blob: 95ea9bc4ecd187a72b5b97c50b0ced1fd4622576 [file] [log] [blame]
Chris Lattner57ad3782011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner57ad3782011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattner57ad3782011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregor577f75a2009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
Chandler Carruth55fc8732012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3e4c6c42011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000027#include "clang/Lex/Preprocessor.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCall781472f2010-08-25 08:40:02 +000040using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000041
Douglas Gregor577f75a2009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump1eb44332009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump1eb44332009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000101
Douglas Gregord3731192011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000106
Douglas Gregord3731192011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier4a9d7952012-08-08 18:46:20 +0000111
Douglas Gregor577f75a2009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000114
Douglas Gregordfca6f52012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000119
Mike Stump1eb44332009-09-09 15:08:12 +0000120public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000123
Douglas Gregor577f75a2009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000130 }
131
John McCall60d7b3a2010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000134
Douglas Gregor577f75a2009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000138
Douglas Gregor577f75a2009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
144 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000145
Douglas Gregor577f75a2009-08-04 16:50:30 +0000146 /// \brief Returns the location of the entity being transformed, if that
147 /// information was not available elsewhere in the AST.
148 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000149 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000150 /// provide an alternative implementation that provides better location
151 /// information.
152 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000153
Douglas Gregor577f75a2009-08-04 16:50:30 +0000154 /// \brief Returns the name of the entity being transformed, if that
155 /// information was not available elsewhere in the AST.
156 ///
157 /// By default, returns an empty name. Subclasses can provide an alternative
158 /// implementation with a more precise name.
159 DeclarationName getBaseEntity() { return DeclarationName(); }
160
Douglas Gregorb98b1992009-08-11 05:31:07 +0000161 /// \brief Sets the "base" location and entity when that
162 /// information is known based on another transformation.
163 ///
164 /// By default, the source location and entity are ignored. Subclasses can
165 /// override this function to provide a customized implementation.
166 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000167
Douglas Gregorb98b1992009-08-11 05:31:07 +0000168 /// \brief RAII object that temporarily sets the base location and entity
169 /// used for reporting diagnostics in types.
170 class TemporaryBase {
171 TreeTransform &Self;
172 SourceLocation OldLocation;
173 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000174
Douglas Gregorb98b1992009-08-11 05:31:07 +0000175 public:
176 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000177 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000178 OldLocation = Self.getDerived().getBaseLocation();
179 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000180
Douglas Gregorae201f72011-01-25 17:51:48 +0000181 if (Location.isValid())
182 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000183 }
Mike Stump1eb44332009-09-09 15:08:12 +0000184
Douglas Gregorb98b1992009-08-11 05:31:07 +0000185 ~TemporaryBase() {
186 Self.getDerived().setBase(OldLocation, OldEntity);
187 }
188 };
Mike Stump1eb44332009-09-09 15:08:12 +0000189
190 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000191 /// transformed.
192 ///
193 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000194 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000195 /// not change. For example, template instantiation need not traverse
196 /// non-dependent types.
197 bool AlreadyTransformed(QualType T) {
198 return T.isNull();
199 }
200
Douglas Gregor6eef5192009-12-14 19:27:10 +0000201 /// \brief Determine whether the given call argument should be dropped, e.g.,
202 /// because it is a default argument.
203 ///
204 /// Subclasses can provide an alternative implementation of this routine to
205 /// determine which kinds of call arguments get dropped. By default,
206 /// CXXDefaultArgument nodes are dropped (prior to transformation).
207 bool DropCallArgument(Expr *E) {
208 return E->isDefaultArgument();
209 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000210
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000211 /// \brief Determine whether we should expand a pack expansion with the
212 /// given set of parameter packs into separate arguments by repeatedly
213 /// transforming the pattern.
214 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000215 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000216 /// Subclasses can override this routine to provide different behavior.
217 ///
218 /// \param EllipsisLoc The location of the ellipsis that identifies the
219 /// pack expansion.
220 ///
221 /// \param PatternRange The source range that covers the entire pattern of
222 /// the pack expansion.
223 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000224 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000225 /// pattern.
226 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000227 /// \param ShouldExpand Will be set to \c true if the transformer should
228 /// expand the corresponding pack expansions into separate arguments. When
229 /// set, \c NumExpansions must also be set.
230 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000231 /// \param RetainExpansion Whether the caller should add an unexpanded
232 /// pack expansion after all of the expanded arguments. This is used
233 /// when extending explicitly-specified template argument packs per
234 /// C++0x [temp.arg.explicit]p9.
235 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000236 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000237 /// the expanded form of the corresponding pack expansion. This is both an
238 /// input and an output parameter, which can be set by the caller if the
239 /// number of expansions is known a priori (e.g., due to a prior substitution)
240 /// and will be set by the callee when the number of expansions is known.
241 /// The callee must set this value when \c ShouldExpand is \c true; it may
242 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000243 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000244 /// \returns true if an error occurred (e.g., because the parameter packs
245 /// are to be instantiated with arguments of different lengths), false
246 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000247 /// must be set.
248 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
249 SourceRange PatternRange,
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +0000250 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000251 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000252 bool &RetainExpansion,
David Blaikiedc84cd52013-02-20 22:23:23 +0000253 Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000254 ShouldExpand = false;
255 return false;
256 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000257
Douglas Gregord3731192011-01-10 07:32:04 +0000258 /// \brief "Forget" about the partially-substituted pack template argument,
259 /// when performing an instantiation that must preserve the parameter pack
260 /// use.
261 ///
262 /// This routine is meant to be overridden by the template instantiator.
263 TemplateArgument ForgetPartiallySubstitutedPack() {
264 return TemplateArgument();
265 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000266
Douglas Gregord3731192011-01-10 07:32:04 +0000267 /// \brief "Remember" the partially-substituted pack template argument
268 /// after performing an instantiation that must preserve the parameter pack
269 /// use.
270 ///
271 /// This routine is meant to be overridden by the template instantiator.
272 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000273
Douglas Gregor12c9c002011-01-07 16:43:16 +0000274 /// \brief Note to the derived class when a function parameter pack is
275 /// being expanded.
276 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000277
Douglas Gregor577f75a2009-08-04 16:50:30 +0000278 /// \brief Transforms the given type into another type.
279 ///
John McCalla2becad2009-10-21 00:40:46 +0000280 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000281 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000282 /// function. This is expensive, but we don't mind, because
283 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000284 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000285 ///
286 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000287 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000288
John McCalla2becad2009-10-21 00:40:46 +0000289 /// \brief Transforms the given type-with-location into a new
290 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000291 ///
John McCalla2becad2009-10-21 00:40:46 +0000292 /// By default, this routine transforms a type by delegating to the
293 /// appropriate TransformXXXType to build a new type. Subclasses
294 /// may override this function (to take over all type
295 /// transformations) or some set of the TransformXXXType functions
296 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000297 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000298
299 /// \brief Transform the given type-with-location into a new
300 /// type, collecting location information in the given builder
301 /// as necessary.
302 ///
John McCall43fed0d2010-11-12 08:19:04 +0000303 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000304
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000305 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000306 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000307 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000308 /// appropriate TransformXXXStmt function to transform a specific kind of
309 /// statement or the TransformExpr() function to transform an expression.
310 /// Subclasses may override this function to transform statements using some
311 /// other mechanism.
312 ///
313 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000314 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000315
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000316 /// \brief Transform the given expression.
317 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000318 /// By default, this routine transforms an expression by delegating to the
319 /// appropriate TransformXXXExpr function to build a new expression.
320 /// Subclasses may override this function to transform expressions using some
321 /// other mechanism.
322 ///
323 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000324 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000325
Richard Smithc83c2302012-12-19 01:39:02 +0000326 /// \brief Transform the given initializer.
327 ///
328 /// By default, this routine transforms an initializer by stripping off the
329 /// semantic nodes added by initialization, then passing the result to
330 /// TransformExpr or TransformExprs.
331 ///
332 /// \returns the transformed initializer.
333 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
334
Douglas Gregoraa165f82011-01-03 19:04:46 +0000335 /// \brief Transform the given list of expressions.
336 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000337 /// This routine transforms a list of expressions by invoking
338 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregoraa165f82011-01-03 19:04:46 +0000339 /// support for variadic templates by expanding any pack expansions (if the
340 /// derived class permits such expansion) along the way. When pack expansions
341 /// are present, the number of outputs may not equal the number of inputs.
342 ///
343 /// \param Inputs The set of expressions to be transformed.
344 ///
345 /// \param NumInputs The number of expressions in \c Inputs.
346 ///
347 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier4a9d7952012-08-08 18:46:20 +0000348 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregoraa165f82011-01-03 19:04:46 +0000349 /// be.
350 ///
351 /// \param Outputs The transformed input expressions will be added to this
352 /// vector.
353 ///
354 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
355 /// due to transformation.
356 ///
357 /// \returns true if an error occurred, false otherwise.
358 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000359 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000360 bool *ArgChanged = 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000361
Douglas Gregor577f75a2009-08-04 16:50:30 +0000362 /// \brief Transform the given declaration, which is referenced from a type
363 /// or expression.
364 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000365 /// By default, acts as the identity function on declarations, unless the
366 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000367 /// may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000368 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregordfca6f52012-02-13 22:00:16 +0000369 llvm::DenseMap<Decl *, Decl *>::iterator Known
370 = TransformedLocalDecls.find(D);
371 if (Known != TransformedLocalDecls.end())
372 return Known->second;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000373
374 return D;
Douglas Gregordfca6f52012-02-13 22:00:16 +0000375 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000376
Chad Rosier4a9d7952012-08-08 18:46:20 +0000377 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregordfca6f52012-02-13 22:00:16 +0000378 /// place them on the new declaration.
379 ///
380 /// By default, this operation does nothing. Subclasses may override this
381 /// behavior to transform attributes.
382 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000383
Douglas Gregordfca6f52012-02-13 22:00:16 +0000384 /// \brief Note that a local declaration has been transformed by this
385 /// transformer.
386 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000387 /// Local declarations are typically transformed via a call to
Douglas Gregordfca6f52012-02-13 22:00:16 +0000388 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
389 /// the transformer itself has to transform the declarations. This routine
390 /// can be overridden by a subclass that keeps track of such mappings.
391 void transformedLocalDecl(Decl *Old, Decl *New) {
392 TransformedLocalDecls[Old] = New;
393 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000394
Douglas Gregor43959a92009-08-20 07:17:43 +0000395 /// \brief Transform the definition of the given declaration.
396 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000397 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000398 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000399 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
400 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000401 }
Mike Stump1eb44332009-09-09 15:08:12 +0000402
Douglas Gregor6cd21982009-10-20 05:58:46 +0000403 /// \brief Transform the given declaration, which was the first part of a
404 /// nested-name-specifier in a member access expression.
405 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000406 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000407 /// identifier in a nested-name-specifier of a member access expression, e.g.,
408 /// the \c T in \c x->T::member
409 ///
410 /// By default, invokes TransformDecl() to transform the declaration.
411 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000412 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
413 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000414 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000415
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000416 /// \brief Transform the given nested-name-specifier with source-location
417 /// information.
418 ///
419 /// By default, transforms all of the types and declarations within the
420 /// nested-name-specifier. Subclasses may override this function to provide
421 /// alternate behavior.
422 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
423 NestedNameSpecifierLoc NNS,
424 QualType ObjectType = QualType(),
425 NamedDecl *FirstQualifierInScope = 0);
426
Douglas Gregor81499bb2009-09-03 22:13:48 +0000427 /// \brief Transform the given declaration name.
428 ///
429 /// By default, transforms the types of conversion function, constructor,
430 /// and destructor names and then (if needed) rebuilds the declaration name.
431 /// Identifiers and selectors are returned unmodified. Sublcasses may
432 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000433 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000434 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000435
Douglas Gregor577f75a2009-08-04 16:50:30 +0000436 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000437 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000438 /// \param SS The nested-name-specifier that qualifies the template
439 /// name. This nested-name-specifier must already have been transformed.
440 ///
441 /// \param Name The template name to transform.
442 ///
443 /// \param NameLoc The source location of the template name.
444 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000445 /// \param ObjectType If we're translating a template name within a member
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000446 /// access expression, this is the type of the object whose member template
447 /// is being referenced.
448 ///
449 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
450 /// also refers to a name within the current (lexical) scope, this is the
451 /// declaration it refers to.
452 ///
453 /// By default, transforms the template name by transforming the declarations
454 /// and nested-name-specifiers that occur within the template name.
455 /// Subclasses may override this function to provide alternate behavior.
456 TemplateName TransformTemplateName(CXXScopeSpec &SS,
457 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000458 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000459 QualType ObjectType = QualType(),
460 NamedDecl *FirstQualifierInScope = 0);
461
Douglas Gregor577f75a2009-08-04 16:50:30 +0000462 /// \brief Transform the given template argument.
463 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000464 /// By default, this operation transforms the type, expression, or
465 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000466 /// new template argument from the transformed result. Subclasses may
467 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000468 ///
469 /// Returns true if there was an error.
470 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
471 TemplateArgumentLoc &Output);
472
Douglas Gregorfcc12532010-12-20 17:31:10 +0000473 /// \brief Transform the given set of template arguments.
474 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000475 /// By default, this operation transforms all of the template arguments
Douglas Gregorfcc12532010-12-20 17:31:10 +0000476 /// in the input set using \c TransformTemplateArgument(), and appends
477 /// the transformed arguments to the output list.
478 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000479 /// Note that this overload of \c TransformTemplateArguments() is merely
480 /// a convenience function. Subclasses that wish to override this behavior
481 /// should override the iterator-based member template version.
482 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000483 /// \param Inputs The set of template arguments to be transformed.
484 ///
485 /// \param NumInputs The number of template arguments in \p Inputs.
486 ///
487 /// \param Outputs The set of transformed template arguments output by this
488 /// routine.
489 ///
490 /// Returns true if an error occurred.
491 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
492 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000493 TemplateArgumentListInfo &Outputs) {
494 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
495 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000496
497 /// \brief Transform the given set of template arguments.
498 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000499 /// By default, this operation transforms all of the template arguments
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000500 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier4a9d7952012-08-08 18:46:20 +0000501 /// the transformed arguments to the output list.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000502 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000503 /// \param First An iterator to the first template argument.
504 ///
505 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000506 ///
507 /// \param Outputs The set of transformed template arguments output by this
508 /// routine.
509 ///
510 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000511 template<typename InputIterator>
512 bool TransformTemplateArguments(InputIterator First,
513 InputIterator Last,
514 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000515
John McCall833ca992009-10-29 08:12:44 +0000516 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
517 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
518 TemplateArgumentLoc &ArgLoc);
519
John McCalla93c9342009-12-07 02:54:59 +0000520 /// \brief Fakes up a TypeSourceInfo for a type.
521 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
522 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000523 getDerived().getBaseLocation());
524 }
Mike Stump1eb44332009-09-09 15:08:12 +0000525
John McCalla2becad2009-10-21 00:40:46 +0000526#define ABSTRACT_TYPELOC(CLASS, PARENT)
527#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000528 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000529#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000530
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000531 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
532 FunctionProtoTypeLoc TL,
533 CXXRecordDecl *ThisContext,
534 unsigned ThisTypeQuals);
535
John Wiegley28bbe4b2011-04-28 01:08:34 +0000536 StmtResult
537 TransformSEHHandler(Stmt *Handler);
538
Chad Rosier4a9d7952012-08-08 18:46:20 +0000539 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000540 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
541 TemplateSpecializationTypeLoc TL,
542 TemplateName Template);
543
Chad Rosier4a9d7952012-08-08 18:46:20 +0000544 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000545 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
546 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000547 TemplateName Template,
548 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000549
Chad Rosier4a9d7952012-08-08 18:46:20 +0000550 QualType
Douglas Gregora88f09f2011-02-28 17:23:35 +0000551 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000552 DependentTemplateSpecializationTypeLoc TL,
553 NestedNameSpecifierLoc QualifierLoc);
554
John McCall21ef0fa2010-03-11 09:03:00 +0000555 /// \brief Transforms the parameters of a function type into the
556 /// given vectors.
557 ///
558 /// The result vectors should be kept in sync; null entries in the
559 /// variables vector are acceptable.
560 ///
561 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000562 bool TransformFunctionTypeParams(SourceLocation Loc,
563 ParmVarDecl **Params, unsigned NumParams,
564 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000565 SmallVectorImpl<QualType> &PTypes,
566 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000567
568 /// \brief Transforms a single function-type parameter. Return null
569 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000570 ///
571 /// \param indexAdjustment - A number to add to the parameter's
572 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000573 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000574 int indexAdjustment,
David Blaikiedc84cd52013-02-20 22:23:23 +0000575 Optional<unsigned> NumExpansions,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000576 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000577
John McCall43fed0d2010-11-12 08:19:04 +0000578 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000579
John McCall60d7b3a2010-08-24 06:29:42 +0000580 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
581 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000582
Richard Smith612409e2012-07-25 03:56:55 +0000583 /// \brief Transform the captures and body of a lambda expression.
584 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
585
Richard Smithefeeccf2012-10-21 03:28:35 +0000586 ExprResult TransformAddressOfOperand(Expr *E);
587 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
588 bool IsAddressOfOperand);
589
Douglas Gregor43959a92009-08-20 07:17:43 +0000590#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000591 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000592#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000593 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000594#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000595#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000596
Douglas Gregor577f75a2009-08-04 16:50:30 +0000597 /// \brief Build a new pointer type given its pointee type.
598 ///
599 /// By default, performs semantic analysis when building the pointer type.
600 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000601 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000602
603 /// \brief Build a new block pointer type given its pointee type.
604 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000605 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000606 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000607 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000608
John McCall85737a72009-10-30 00:06:24 +0000609 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000610 ///
John McCall85737a72009-10-30 00:06:24 +0000611 /// By default, performs semantic analysis when building the
612 /// reference type. Subclasses may override this routine to provide
613 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000614 ///
John McCall85737a72009-10-30 00:06:24 +0000615 /// \param LValue whether the type was written with an lvalue sigil
616 /// or an rvalue sigil.
617 QualType RebuildReferenceType(QualType ReferentType,
618 bool LValue,
619 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000620
Douglas Gregor577f75a2009-08-04 16:50:30 +0000621 /// \brief Build a new member pointer type given the pointee type and the
622 /// class type it refers into.
623 ///
624 /// By default, performs semantic analysis when building the member pointer
625 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000626 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
627 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000628
Douglas Gregor577f75a2009-08-04 16:50:30 +0000629 /// \brief Build a new array type given the element type, size
630 /// modifier, size of the array (if known), size expression, and index type
631 /// qualifiers.
632 ///
633 /// By default, performs semantic analysis when building the array type.
634 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000635 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636 QualType RebuildArrayType(QualType ElementType,
637 ArrayType::ArraySizeModifier SizeMod,
638 const llvm::APInt *Size,
639 Expr *SizeExpr,
640 unsigned IndexTypeQuals,
641 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000642
Douglas Gregor577f75a2009-08-04 16:50:30 +0000643 /// \brief Build a new constant array type given the element type, size
644 /// modifier, (known) size of the array, and index type qualifiers.
645 ///
646 /// By default, performs semantic analysis when building the array type.
647 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000648 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000649 ArrayType::ArraySizeModifier SizeMod,
650 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000651 unsigned IndexTypeQuals,
652 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000653
Douglas Gregor577f75a2009-08-04 16:50:30 +0000654 /// \brief Build a new incomplete array type given the element type, size
655 /// modifier, and index type qualifiers.
656 ///
657 /// By default, performs semantic analysis when building the array type.
658 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000659 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000660 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000661 unsigned IndexTypeQuals,
662 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663
Mike Stump1eb44332009-09-09 15:08:12 +0000664 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000665 /// size modifier, size expression, and index type qualifiers.
666 ///
667 /// By default, performs semantic analysis when building the array type.
668 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000669 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000670 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000671 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000672 unsigned IndexTypeQuals,
673 SourceRange BracketsRange);
674
Mike Stump1eb44332009-09-09 15:08:12 +0000675 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000676 /// size modifier, size expression, and index type qualifiers.
677 ///
678 /// By default, performs semantic analysis when building the array type.
679 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000680 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000681 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000682 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000683 unsigned IndexTypeQuals,
684 SourceRange BracketsRange);
685
686 /// \brief Build a new vector type given the element type and
687 /// number of elements.
688 ///
689 /// By default, performs semantic analysis when building the vector type.
690 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000691 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000692 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000693
Douglas Gregor577f75a2009-08-04 16:50:30 +0000694 /// \brief Build a new extended vector type given the element type and
695 /// number of elements.
696 ///
697 /// By default, performs semantic analysis when building the vector type.
698 /// Subclasses may override this routine to provide different behavior.
699 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
700 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000701
702 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000703 /// given the element type and number of elements.
704 ///
705 /// By default, performs semantic analysis when building the vector type.
706 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000707 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000708 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000709 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000710
Douglas Gregor577f75a2009-08-04 16:50:30 +0000711 /// \brief Build a new function type.
712 ///
713 /// By default, performs semantic analysis when building the function type.
714 /// Subclasses may override this routine to provide different behavior.
715 QualType RebuildFunctionProtoType(QualType T,
Jordan Rosebea522f2013-03-08 21:51:21 +0000716 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +0000717 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump1eb44332009-09-09 15:08:12 +0000718
John McCalla2becad2009-10-21 00:40:46 +0000719 /// \brief Build a new unprototyped function type.
720 QualType RebuildFunctionNoProtoType(QualType ResultType);
721
John McCalled976492009-12-04 22:46:56 +0000722 /// \brief Rebuild an unresolved typename type, given the decl that
723 /// the UnresolvedUsingTypenameDecl was transformed to.
724 QualType RebuildUnresolvedUsingType(Decl *D);
725
Douglas Gregor577f75a2009-08-04 16:50:30 +0000726 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000727 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000728 return SemaRef.Context.getTypeDeclType(Typedef);
729 }
730
731 /// \brief Build a new class/struct/union type.
732 QualType RebuildRecordType(RecordDecl *Record) {
733 return SemaRef.Context.getTypeDeclType(Record);
734 }
735
736 /// \brief Build a new Enum type.
737 QualType RebuildEnumType(EnumDecl *Enum) {
738 return SemaRef.Context.getTypeDeclType(Enum);
739 }
John McCall7da24312009-09-05 00:15:47 +0000740
Mike Stump1eb44332009-09-09 15:08:12 +0000741 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000742 ///
743 /// By default, performs semantic analysis when building the typeof type.
744 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000745 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000746
Mike Stump1eb44332009-09-09 15:08:12 +0000747 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000748 ///
749 /// By default, builds a new TypeOfType with the given underlying type.
750 QualType RebuildTypeOfType(QualType Underlying);
751
Sean Huntca63c202011-05-24 22:41:36 +0000752 /// \brief Build a new unary transform type.
753 QualType RebuildUnaryTransformType(QualType BaseType,
754 UnaryTransformType::UTTKind UKind,
755 SourceLocation Loc);
756
Richard Smitha2c36462013-04-26 16:15:35 +0000757 /// \brief Build a new C++11 decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000758 ///
759 /// By default, performs semantic analysis when building the decltype type.
760 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000761 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000762
Richard Smitha2c36462013-04-26 16:15:35 +0000763 /// \brief Build a new C++11 auto type.
Richard Smith34b41d92011-02-20 03:19:35 +0000764 ///
765 /// By default, builds a new AutoType with the given deduced type.
Richard Smitha2c36462013-04-26 16:15:35 +0000766 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smithdc7a4f52013-04-30 13:56:41 +0000767 // Note, IsDependent is always false here: we implicitly convert an 'auto'
768 // which has been deduced to a dependent type into an undeduced 'auto', so
769 // that we'll retry deduction after the transformation.
Richard Smitha2c36462013-04-26 16:15:35 +0000770 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto);
Richard Smith34b41d92011-02-20 03:19:35 +0000771 }
772
Douglas Gregor577f75a2009-08-04 16:50:30 +0000773 /// \brief Build a new template specialization type.
774 ///
775 /// By default, performs semantic analysis when building the template
776 /// specialization type. Subclasses may override this routine to provide
777 /// different behavior.
778 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000779 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000780 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000781
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000782 /// \brief Build a new parenthesized type.
783 ///
784 /// By default, builds a new ParenType type from the inner type.
785 /// Subclasses may override this routine to provide different behavior.
786 QualType RebuildParenType(QualType InnerType) {
787 return SemaRef.Context.getParenType(InnerType);
788 }
789
Douglas Gregor577f75a2009-08-04 16:50:30 +0000790 /// \brief Build a new qualified name type.
791 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000792 /// By default, builds a new ElaboratedType type from the keyword,
793 /// the nested-name-specifier and the named type.
794 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000795 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
796 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000797 NestedNameSpecifierLoc QualifierLoc,
798 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000799 return SemaRef.Context.getElaboratedType(Keyword,
800 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000801 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000802 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000803
804 /// \brief Build a new typename type that refers to a template-id.
805 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000806 /// By default, builds a new DependentNameType type from the
807 /// nested-name-specifier and the given type. Subclasses may override
808 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000809 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000810 ElaboratedTypeKeyword Keyword,
811 NestedNameSpecifierLoc QualifierLoc,
812 const IdentifierInfo *Name,
813 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000814 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000815 // Rebuild the template name.
816 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000817 CXXScopeSpec SS;
818 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000819 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000820 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000821
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000822 if (InstName.isNull())
823 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000824
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000825 // If it's still dependent, make a dependent specialization.
826 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000827 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
828 QualifierLoc.getNestedNameSpecifier(),
829 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000830 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000831
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000832 // Otherwise, make an elaborated type wrapping a non-dependent
833 // specialization.
834 QualType T =
835 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
836 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000837
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000838 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
839 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000840
841 return SemaRef.Context.getElaboratedType(Keyword,
842 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000843 T);
844 }
845
Douglas Gregor577f75a2009-08-04 16:50:30 +0000846 /// \brief Build a new typename type that refers to an identifier.
847 ///
848 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000849 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000850 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000851 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000852 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000853 NestedNameSpecifierLoc QualifierLoc,
854 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000855 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000856 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000857 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000858
Douglas Gregor2494dd02011-03-01 01:34:45 +0000859 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000860 // If the name is still dependent, just build a new dependent name type.
861 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000862 return SemaRef.Context.getDependentNameType(Keyword,
863 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000864 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000865 }
866
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000867 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000868 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000869 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000870
871 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
872
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000873 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000874 // into a non-dependent elaborated-type-specifier. Find the tag we're
875 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000876 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000877 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
878 if (!DC)
879 return QualType();
880
John McCall56138762010-05-27 06:40:31 +0000881 if (SemaRef.RequireCompleteDeclContext(SS, DC))
882 return QualType();
883
Douglas Gregor40336422010-03-31 22:19:08 +0000884 TagDecl *Tag = 0;
885 SemaRef.LookupQualifiedName(Result, DC);
886 switch (Result.getResultKind()) {
887 case LookupResult::NotFound:
888 case LookupResult::NotFoundInCurrentInstantiation:
889 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000890
Douglas Gregor40336422010-03-31 22:19:08 +0000891 case LookupResult::Found:
892 Tag = Result.getAsSingle<TagDecl>();
893 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000894
Douglas Gregor40336422010-03-31 22:19:08 +0000895 case LookupResult::FoundOverloaded:
896 case LookupResult::FoundUnresolvedValue:
897 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000898
Douglas Gregor40336422010-03-31 22:19:08 +0000899 case LookupResult::Ambiguous:
900 // Let the LookupResult structure handle ambiguities.
901 return QualType();
902 }
903
904 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000905 // Check where the name exists but isn't a tag type and use that to emit
906 // better diagnostics.
907 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
908 SemaRef.LookupQualifiedName(Result, DC);
909 switch (Result.getResultKind()) {
910 case LookupResult::Found:
911 case LookupResult::FoundOverloaded:
912 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000913 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000914 unsigned Kind = 0;
915 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000916 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
917 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000918 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
919 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
920 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000921 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000922 default:
923 // FIXME: Would be nice to highlight just the source range.
924 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
925 << Kind << Id << DC;
926 break;
927 }
Douglas Gregor40336422010-03-31 22:19:08 +0000928 return QualType();
929 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000930
Richard Trieubbf34c02011-06-10 03:11:26 +0000931 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
932 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000933 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000934 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
935 return QualType();
936 }
937
938 // Build the elaborated-type-specifier type.
939 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000940 return SemaRef.Context.getElaboratedType(Keyword,
941 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000942 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000943 }
Mike Stump1eb44332009-09-09 15:08:12 +0000944
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000945 /// \brief Build a new pack expansion type.
946 ///
947 /// By default, builds a new PackExpansionType type from the given pattern.
948 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000949 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000950 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000951 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +0000952 Optional<unsigned> NumExpansions) {
Douglas Gregorcded4f62011-01-14 17:04:44 +0000953 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
954 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000955 }
956
Eli Friedmanb001de72011-10-06 23:00:33 +0000957 /// \brief Build a new atomic type given its value type.
958 ///
959 /// By default, performs semantic analysis when building the atomic type.
960 /// Subclasses may override this routine to provide different behavior.
961 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
962
Douglas Gregord1067e52009-08-06 06:41:21 +0000963 /// \brief Build a new template name given a nested name specifier, a flag
964 /// indicating whether the "template" keyword was provided, and the template
965 /// that the template name refers to.
966 ///
967 /// By default, builds the new template name directly. Subclasses may override
968 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000969 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000970 bool TemplateKW,
971 TemplateDecl *Template);
972
Douglas Gregord1067e52009-08-06 06:41:21 +0000973 /// \brief Build a new template name given a nested name specifier and the
974 /// name that is referred to as a template.
975 ///
976 /// By default, performs semantic analysis to determine whether the name can
977 /// be resolved to a specific template, then builds the appropriate kind of
978 /// template name. Subclasses may override this routine to provide different
979 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000980 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
981 const IdentifierInfo &Name,
982 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000983 QualType ObjectType,
984 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000985
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000986 /// \brief Build a new template name given a nested name specifier and the
987 /// overloaded operator name that is referred to as a template.
988 ///
989 /// By default, performs semantic analysis to determine whether the name can
990 /// be resolved to a specific template, then builds the appropriate kind of
991 /// template name. Subclasses may override this routine to provide different
992 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000993 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000994 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000995 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000996 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000997
998 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +0000999 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001000 ///
1001 /// By default, performs semantic analysis to determine whether the name can
1002 /// be resolved to a specific template, then builds the appropriate kind of
1003 /// template name. Subclasses may override this routine to provide different
1004 /// behavior.
1005 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1006 const TemplateArgument &ArgPack) {
1007 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1008 }
1009
Douglas Gregor43959a92009-08-20 07:17:43 +00001010 /// \brief Build a new compound statement.
1011 ///
1012 /// By default, performs semantic analysis to build the new statement.
1013 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001014 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001015 MultiStmtArg Statements,
1016 SourceLocation RBraceLoc,
1017 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001018 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001019 IsStmtExpr);
1020 }
1021
1022 /// \brief Build a new case statement.
1023 ///
1024 /// By default, performs semantic analysis to build the new statement.
1025 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001026 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001027 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001028 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001029 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001030 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001031 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001032 ColonLoc);
1033 }
Mike Stump1eb44332009-09-09 15:08:12 +00001034
Douglas Gregor43959a92009-08-20 07:17:43 +00001035 /// \brief Attach the body to a new case statement.
1036 ///
1037 /// By default, performs semantic analysis to build the new statement.
1038 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001039 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001040 getSema().ActOnCaseStmtBody(S, Body);
1041 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001042 }
Mike Stump1eb44332009-09-09 15:08:12 +00001043
Douglas Gregor43959a92009-08-20 07:17:43 +00001044 /// \brief Build a new default statement.
1045 ///
1046 /// By default, performs semantic analysis to build the new statement.
1047 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001048 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001049 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001050 Stmt *SubStmt) {
1051 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001052 /*CurScope=*/0);
1053 }
Mike Stump1eb44332009-09-09 15:08:12 +00001054
Douglas Gregor43959a92009-08-20 07:17:43 +00001055 /// \brief Build a new label statement.
1056 ///
1057 /// By default, performs semantic analysis to build the new statement.
1058 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001059 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1060 SourceLocation ColonLoc, Stmt *SubStmt) {
1061 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001062 }
Mike Stump1eb44332009-09-09 15:08:12 +00001063
Richard Smith534986f2012-04-14 00:33:13 +00001064 /// \brief Build a new label statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001068 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1069 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001070 Stmt *SubStmt) {
1071 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1072 }
1073
Douglas Gregor43959a92009-08-20 07:17:43 +00001074 /// \brief Build a new "if" statement.
1075 ///
1076 /// By default, performs semantic analysis to build the new statement.
1077 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001078 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001079 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001080 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001081 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001082 }
Mike Stump1eb44332009-09-09 15:08:12 +00001083
Douglas Gregor43959a92009-08-20 07:17:43 +00001084 /// \brief Start building a new switch statement.
1085 ///
1086 /// By default, performs semantic analysis to build the new statement.
1087 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001088 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001089 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001090 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001091 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001092 }
Mike Stump1eb44332009-09-09 15:08:12 +00001093
Douglas Gregor43959a92009-08-20 07:17:43 +00001094 /// \brief Attach the body to the switch statement.
1095 ///
1096 /// By default, performs semantic analysis to build the new statement.
1097 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001098 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001099 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001100 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001101 }
1102
1103 /// \brief Build a new while statement.
1104 ///
1105 /// By default, performs semantic analysis to build the new statement.
1106 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001107 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1108 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001109 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001110 }
Mike Stump1eb44332009-09-09 15:08:12 +00001111
Douglas Gregor43959a92009-08-20 07:17:43 +00001112 /// \brief Build a new do-while statement.
1113 ///
1114 /// By default, performs semantic analysis to build the new statement.
1115 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001116 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001117 SourceLocation WhileLoc, SourceLocation LParenLoc,
1118 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001119 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1120 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001121 }
1122
1123 /// \brief Build a new for statement.
1124 ///
1125 /// By default, performs semantic analysis to build the new statement.
1126 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001127 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001128 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001129 VarDecl *CondVar, Sema::FullExprArg Inc,
1130 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001131 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001132 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001133 }
Mike Stump1eb44332009-09-09 15:08:12 +00001134
Douglas Gregor43959a92009-08-20 07:17:43 +00001135 /// \brief Build a new goto statement.
1136 ///
1137 /// By default, performs semantic analysis to build the new statement.
1138 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001139 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1140 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001141 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001142 }
1143
1144 /// \brief Build a new indirect goto statement.
1145 ///
1146 /// By default, performs semantic analysis to build the new statement.
1147 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001148 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001149 SourceLocation StarLoc,
1150 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001151 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001152 }
Mike Stump1eb44332009-09-09 15:08:12 +00001153
Douglas Gregor43959a92009-08-20 07:17:43 +00001154 /// \brief Build a new return statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001158 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001159 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001160 }
Mike Stump1eb44332009-09-09 15:08:12 +00001161
Douglas Gregor43959a92009-08-20 07:17:43 +00001162 /// \brief Build a new declaration statement.
1163 ///
1164 /// By default, performs semantic analysis to build the new statement.
1165 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001166 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001167 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001168 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001169 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1170 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001171 }
Mike Stump1eb44332009-09-09 15:08:12 +00001172
Anders Carlsson703e3942010-01-24 05:50:09 +00001173 /// \brief Build a new inline asm statement.
1174 ///
1175 /// By default, performs semantic analysis to build the new statement.
1176 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001177 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1178 bool IsVolatile, unsigned NumOutputs,
1179 unsigned NumInputs, IdentifierInfo **Names,
1180 MultiExprArg Constraints, MultiExprArg Exprs,
1181 Expr *AsmString, MultiExprArg Clobbers,
1182 SourceLocation RParenLoc) {
1183 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1184 NumInputs, Names, Constraints, Exprs,
1185 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001186 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001187
Chad Rosier8cd64b42012-06-11 20:47:18 +00001188 /// \brief Build a new MS style inline asm statement.
1189 ///
1190 /// By default, performs semantic analysis to build the new statement.
1191 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001192 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallaeeacf72013-05-03 00:10:13 +00001193 ArrayRef<Token> AsmToks,
1194 StringRef AsmString,
1195 unsigned NumOutputs, unsigned NumInputs,
1196 ArrayRef<StringRef> Constraints,
1197 ArrayRef<StringRef> Clobbers,
1198 ArrayRef<Expr*> Exprs,
1199 SourceLocation EndLoc) {
1200 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1201 NumOutputs, NumInputs,
1202 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001203 }
1204
James Dennett699c9042012-06-15 07:13:21 +00001205 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001206 ///
1207 /// By default, performs semantic analysis to build the new statement.
1208 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001209 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001210 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001211 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001212 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001213 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001214 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001215 }
1216
Douglas Gregorbe270a02010-04-26 17:57:08 +00001217 /// \brief Rebuild an Objective-C exception declaration.
1218 ///
1219 /// By default, performs semantic analysis to build the new declaration.
1220 /// Subclasses may override this routine to provide different behavior.
1221 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1222 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001223 return getSema().BuildObjCExceptionDecl(TInfo, T,
1224 ExceptionDecl->getInnerLocStart(),
1225 ExceptionDecl->getLocation(),
1226 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001227 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001228
James Dennett699c9042012-06-15 07:13:21 +00001229 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001230 ///
1231 /// By default, performs semantic analysis to build the new statement.
1232 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001233 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001234 SourceLocation RParenLoc,
1235 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001236 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001237 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001238 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001239 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001240
James Dennett699c9042012-06-15 07:13:21 +00001241 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001242 ///
1243 /// By default, performs semantic analysis to build the new statement.
1244 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001245 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001246 Stmt *Body) {
1247 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001248 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001249
James Dennett699c9042012-06-15 07:13:21 +00001250 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001251 ///
1252 /// By default, performs semantic analysis to build the new statement.
1253 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001254 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001255 Expr *Operand) {
1256 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001257 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001258
James Dennett699c9042012-06-15 07:13:21 +00001259 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001260 ///
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
1263 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1264 Expr *object) {
1265 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1266 }
1267
James Dennett699c9042012-06-15 07:13:21 +00001268 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001269 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001270 /// By default, performs semantic analysis to build the new statement.
1271 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001272 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001273 Expr *Object, Stmt *Body) {
1274 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001275 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001276
James Dennett699c9042012-06-15 07:13:21 +00001277 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001278 ///
1279 /// By default, performs semantic analysis to build the new statement.
1280 /// Subclasses may override this routine to provide different behavior.
1281 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1282 Stmt *Body) {
1283 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1284 }
John McCall990567c2011-07-27 01:07:15 +00001285
Douglas Gregorc3203e72010-04-22 23:10:45 +00001286 /// \brief Build a new Objective-C fast enumeration statement.
1287 ///
1288 /// By default, performs semantic analysis to build the new statement.
1289 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001290 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001291 Stmt *Element,
1292 Expr *Collection,
1293 SourceLocation RParenLoc,
1294 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001295 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001296 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001297 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001298 RParenLoc);
1299 if (ForEachStmt.isInvalid())
1300 return StmtError();
1301
1302 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001303 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001304
Douglas Gregor43959a92009-08-20 07:17:43 +00001305 /// \brief Build a new C++ exception declaration.
1306 ///
1307 /// By default, performs semantic analysis to build the new decaration.
1308 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001309 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001310 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001311 SourceLocation StartLoc,
1312 SourceLocation IdLoc,
1313 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001314 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1315 StartLoc, IdLoc, Id);
1316 if (Var)
1317 getSema().CurContext->addDecl(Var);
1318 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001319 }
1320
1321 /// \brief Build a new C++ catch statement.
1322 ///
1323 /// By default, performs semantic analysis to build the new statement.
1324 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001325 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001326 VarDecl *ExceptionDecl,
1327 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001328 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1329 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001330 }
Mike Stump1eb44332009-09-09 15:08:12 +00001331
Douglas Gregor43959a92009-08-20 07:17:43 +00001332 /// \brief Build a new C++ try statement.
1333 ///
1334 /// By default, performs semantic analysis to build the new statement.
1335 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001336 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001337 Stmt *TryBlock,
1338 MultiStmtArg Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001339 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001340 }
Mike Stump1eb44332009-09-09 15:08:12 +00001341
Richard Smithad762fc2011-04-14 22:09:26 +00001342 /// \brief Build a new C++0x range-based for statement.
1343 ///
1344 /// By default, performs semantic analysis to build the new statement.
1345 /// Subclasses may override this routine to provide different behavior.
1346 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1347 SourceLocation ColonLoc,
1348 Stmt *Range, Stmt *BeginEnd,
1349 Expr *Cond, Expr *Inc,
1350 Stmt *LoopVar,
1351 SourceLocation RParenLoc) {
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001352 // If we've just learned that the range is actually an Objective-C
1353 // collection, treat this as an Objective-C fast enumeration loop.
1354 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1355 if (RangeStmt->isSingleDecl()) {
1356 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39b60dc2013-05-02 18:35:56 +00001357 if (RangeVar->isInvalidDecl())
1358 return StmtError();
1359
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001360 Expr *RangeExpr = RangeVar->getInit();
1361 if (!RangeExpr->isTypeDependent() &&
1362 RangeExpr->getType()->isObjCObjectPointerType())
1363 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1364 RParenLoc);
1365 }
1366 }
1367 }
1368
Richard Smithad762fc2011-04-14 22:09:26 +00001369 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001370 Cond, Inc, LoopVar, RParenLoc,
1371 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001372 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001373
1374 /// \brief Build a new C++0x range-based for statement.
1375 ///
1376 /// By default, performs semantic analysis to build the new statement.
1377 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001378 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001379 bool IsIfExists,
1380 NestedNameSpecifierLoc QualifierLoc,
1381 DeclarationNameInfo NameInfo,
1382 Stmt *Nested) {
1383 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1384 QualifierLoc, NameInfo, Nested);
1385 }
1386
Richard Smithad762fc2011-04-14 22:09:26 +00001387 /// \brief Attach body to a C++0x range-based for statement.
1388 ///
1389 /// By default, performs semantic analysis to finish the new statement.
1390 /// Subclasses may override this routine to provide different behavior.
1391 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1392 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1393 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001394
John Wiegley28bbe4b2011-04-28 01:08:34 +00001395 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1396 SourceLocation TryLoc,
1397 Stmt *TryBlock,
1398 Stmt *Handler) {
1399 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1400 }
1401
1402 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1403 Expr *FilterExpr,
1404 Stmt *Block) {
1405 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1406 }
1407
1408 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1409 Stmt *Block) {
1410 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1411 }
1412
Douglas Gregorb98b1992009-08-11 05:31:07 +00001413 /// \brief Build a new expression that references a declaration.
1414 ///
1415 /// By default, performs semantic analysis to build the new expression.
1416 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001417 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001418 LookupResult &R,
1419 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001420 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1421 }
1422
1423
1424 /// \brief Build a new expression that references a declaration.
1425 ///
1426 /// By default, performs semantic analysis to build the new expression.
1427 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001428 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001429 ValueDecl *VD,
1430 const DeclarationNameInfo &NameInfo,
1431 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001432 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001433 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001434
1435 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001436
1437 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001438 }
Mike Stump1eb44332009-09-09 15:08:12 +00001439
Douglas Gregorb98b1992009-08-11 05:31:07 +00001440 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001441 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001442 /// By default, performs semantic analysis to build the new expression.
1443 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001444 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001445 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001446 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001447 }
1448
Douglas Gregora71d8192009-09-04 17:36:40 +00001449 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001450 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001451 /// By default, performs semantic analysis to build the new expression.
1452 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001453 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001454 SourceLocation OperatorLoc,
1455 bool isArrow,
1456 CXXScopeSpec &SS,
1457 TypeSourceInfo *ScopeType,
1458 SourceLocation CCLoc,
1459 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001460 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001461
Douglas Gregorb98b1992009-08-11 05:31:07 +00001462 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001463 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001464 /// By default, performs semantic analysis to build the new expression.
1465 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001466 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001467 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001468 Expr *SubExpr) {
1469 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001470 }
Mike Stump1eb44332009-09-09 15:08:12 +00001471
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001472 /// \brief Build a new builtin offsetof expression.
1473 ///
1474 /// By default, performs semantic analysis to build the new expression.
1475 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001476 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001477 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001478 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001479 unsigned NumComponents,
1480 SourceLocation RParenLoc) {
1481 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1482 NumComponents, RParenLoc);
1483 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001484
1485 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001486 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001487 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001488 /// By default, performs semantic analysis to build the new expression.
1489 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001490 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1491 SourceLocation OpLoc,
1492 UnaryExprOrTypeTrait ExprKind,
1493 SourceRange R) {
1494 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 }
1496
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001497 /// \brief Build a new sizeof, alignof or vec step expression with an
1498 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001499 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001500 /// By default, performs semantic analysis to build the new expression.
1501 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001502 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1503 UnaryExprOrTypeTrait ExprKind,
1504 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001505 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001506 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001508 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001509
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001510 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001511 }
Mike Stump1eb44332009-09-09 15:08:12 +00001512
Douglas Gregorb98b1992009-08-11 05:31:07 +00001513 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001514 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001515 /// By default, performs semantic analysis to build the new expression.
1516 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001517 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001518 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001519 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001520 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001521 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1522 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001523 RBracketLoc);
1524 }
1525
1526 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001527 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001528 /// By default, performs semantic analysis to build the new expression.
1529 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001530 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001531 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001532 SourceLocation RParenLoc,
1533 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001534 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001535 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001536 }
1537
1538 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001539 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001540 /// By default, performs semantic analysis to build the new expression.
1541 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001542 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001543 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001544 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001545 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001546 const DeclarationNameInfo &MemberNameInfo,
1547 ValueDecl *Member,
1548 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001549 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001550 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001551 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1552 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001553 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001554 // We have a reference to an unnamed field. This is always the
1555 // base of an anonymous struct/union member access, i.e. the
1556 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001557 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001558 assert(Member->getType()->isRecordType() &&
1559 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001560
Richard Smith9138b4e2011-10-26 19:06:56 +00001561 BaseResult =
1562 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001563 QualifierLoc.getNestedNameSpecifier(),
1564 FoundDecl, Member);
1565 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001566 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001567 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001568 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001569 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001570 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001571 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001572 cast<FieldDecl>(Member)->getType(),
1573 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001574 return getSema().Owned(ME);
1575 }
Mike Stump1eb44332009-09-09 15:08:12 +00001576
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001577 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001578 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001579
John Wiegley429bb272011-04-08 18:41:53 +00001580 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001581 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001582
John McCall6bb80172010-03-30 21:47:33 +00001583 // FIXME: this involves duplicating earlier analysis in a lot of
1584 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001585 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001586 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001587 R.resolveKind();
1588
John McCall9ae2f072010-08-23 23:25:46 +00001589 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001590 SS, TemplateKWLoc,
1591 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001592 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 }
Mike Stump1eb44332009-09-09 15:08:12 +00001594
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001596 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001597 /// By default, performs semantic analysis to build the new expression.
1598 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001599 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001600 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001601 Expr *LHS, Expr *RHS) {
1602 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 }
1604
1605 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001606 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001607 /// By default, performs semantic analysis to build the new expression.
1608 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001609 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001610 SourceLocation QuestionLoc,
1611 Expr *LHS,
1612 SourceLocation ColonLoc,
1613 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001614 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1615 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001616 }
1617
Douglas Gregorb98b1992009-08-11 05:31:07 +00001618 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001619 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001620 /// By default, performs semantic analysis to build the new expression.
1621 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001622 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001623 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001624 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001625 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001626 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001627 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001628 }
Mike Stump1eb44332009-09-09 15:08:12 +00001629
Douglas Gregorb98b1992009-08-11 05:31:07 +00001630 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001631 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 /// By default, performs semantic analysis to build the new expression.
1633 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001634 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001635 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001636 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001637 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001638 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001639 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001640 }
Mike Stump1eb44332009-09-09 15:08:12 +00001641
Douglas Gregorb98b1992009-08-11 05:31:07 +00001642 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001643 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 /// By default, performs semantic analysis to build the new expression.
1645 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001646 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001647 SourceLocation OpLoc,
1648 SourceLocation AccessorLoc,
1649 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001650
John McCall129e2df2009-11-30 22:42:35 +00001651 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001652 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001653 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001654 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001655 SS, SourceLocation(),
1656 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001657 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001658 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 }
Mike Stump1eb44332009-09-09 15:08:12 +00001660
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001662 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 /// By default, performs semantic analysis to build the new expression.
1664 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001665 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001666 MultiExprArg Inits,
1667 SourceLocation RBraceLoc,
1668 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001669 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001670 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001671 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001672 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001673
Douglas Gregore48319a2009-11-09 17:16:50 +00001674 // Patch in the result type we were given, which may have been computed
1675 // when the initial InitListExpr was built.
1676 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1677 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001678 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 }
Mike Stump1eb44332009-09-09 15:08:12 +00001680
Douglas Gregorb98b1992009-08-11 05:31:07 +00001681 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001682 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001683 /// By default, performs semantic analysis to build the new expression.
1684 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001685 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001686 MultiExprArg ArrayExprs,
1687 SourceLocation EqualOrColonLoc,
1688 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001689 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001690 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001692 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001693 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001694 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001695
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001696 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001697 }
Mike Stump1eb44332009-09-09 15:08:12 +00001698
Douglas Gregorb98b1992009-08-11 05:31:07 +00001699 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001700 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001701 /// By default, builds the implicit value initialization without performing
1702 /// any semantic analysis. Subclasses may override this routine to provide
1703 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001704 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001705 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1706 }
Mike Stump1eb44332009-09-09 15:08:12 +00001707
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001709 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 /// By default, performs semantic analysis to build the new expression.
1711 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001712 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001713 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001714 SourceLocation RParenLoc) {
1715 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001716 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001717 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 }
1719
1720 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001721 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 /// By default, performs semantic analysis to build the new expression.
1723 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001724 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001725 MultiExprArg SubExprs,
1726 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001727 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001728 }
Mike Stump1eb44332009-09-09 15:08:12 +00001729
Douglas Gregorb98b1992009-08-11 05:31:07 +00001730 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001731 ///
1732 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001733 /// rather than attempting to map the label statement itself.
1734 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001735 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001736 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001737 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001738 }
Mike Stump1eb44332009-09-09 15:08:12 +00001739
Douglas Gregorb98b1992009-08-11 05:31:07 +00001740 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001741 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001742 /// By default, performs semantic analysis to build the new expression.
1743 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001744 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001745 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001746 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001747 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 }
Mike Stump1eb44332009-09-09 15:08:12 +00001749
Douglas Gregorb98b1992009-08-11 05:31:07 +00001750 /// \brief Build a new __builtin_choose_expr expression.
1751 ///
1752 /// By default, performs semantic analysis to build the new expression.
1753 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001754 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001755 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 SourceLocation RParenLoc) {
1757 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001758 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 RParenLoc);
1760 }
Mike Stump1eb44332009-09-09 15:08:12 +00001761
Peter Collingbournef111d932011-04-15 00:35:48 +00001762 /// \brief Build a new generic selection expression.
1763 ///
1764 /// By default, performs semantic analysis to build the new expression.
1765 /// Subclasses may override this routine to provide different behavior.
1766 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1767 SourceLocation DefaultLoc,
1768 SourceLocation RParenLoc,
1769 Expr *ControllingExpr,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001770 ArrayRef<TypeSourceInfo *> Types,
1771 ArrayRef<Expr *> Exprs) {
Peter Collingbournef111d932011-04-15 00:35:48 +00001772 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001773 ControllingExpr, Types, Exprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00001774 }
1775
Douglas Gregorb98b1992009-08-11 05:31:07 +00001776 /// \brief Build a new overloaded operator call expression.
1777 ///
1778 /// By default, performs semantic analysis to build the new expression.
1779 /// The semantic analysis provides the behavior of template instantiation,
1780 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001781 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001782 /// argument-dependent lookup, etc. Subclasses may override this routine to
1783 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001784 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001785 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001786 Expr *Callee,
1787 Expr *First,
1788 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001789
1790 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 /// reinterpret_cast.
1792 ///
1793 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001794 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001795 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001796 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 Stmt::StmtClass Class,
1798 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001799 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800 SourceLocation RAngleLoc,
1801 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001802 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 SourceLocation RParenLoc) {
1804 switch (Class) {
1805 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001806 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001807 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001808 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809
1810 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001811 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001812 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001813 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001814
Douglas Gregorb98b1992009-08-11 05:31:07 +00001815 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001816 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001817 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001818 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001819 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001820
Douglas Gregorb98b1992009-08-11 05:31:07 +00001821 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001822 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001823 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001824 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001825
Douglas Gregorb98b1992009-08-11 05:31:07 +00001826 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001827 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001828 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001829 }
Mike Stump1eb44332009-09-09 15:08:12 +00001830
Douglas Gregorb98b1992009-08-11 05:31:07 +00001831 /// \brief Build a new C++ static_cast expression.
1832 ///
1833 /// By default, performs semantic analysis to build the new expression.
1834 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001835 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001836 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001837 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001838 SourceLocation RAngleLoc,
1839 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001840 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001841 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001842 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001843 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001844 SourceRange(LAngleLoc, RAngleLoc),
1845 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001846 }
1847
1848 /// \brief Build a new C++ dynamic_cast expression.
1849 ///
1850 /// By default, performs semantic analysis to build the new expression.
1851 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001852 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001853 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001854 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001855 SourceLocation RAngleLoc,
1856 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001857 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001858 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001859 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001860 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001861 SourceRange(LAngleLoc, RAngleLoc),
1862 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001863 }
1864
1865 /// \brief Build a new C++ reinterpret_cast expression.
1866 ///
1867 /// By default, performs semantic analysis to build the new expression.
1868 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001869 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001870 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001871 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001872 SourceLocation RAngleLoc,
1873 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001874 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001875 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001876 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001877 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001878 SourceRange(LAngleLoc, RAngleLoc),
1879 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001880 }
1881
1882 /// \brief Build a new C++ const_cast expression.
1883 ///
1884 /// By default, performs semantic analysis to build the new expression.
1885 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001886 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001887 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001888 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 SourceLocation RAngleLoc,
1890 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001891 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001892 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001893 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001894 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001895 SourceRange(LAngleLoc, RAngleLoc),
1896 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001897 }
Mike Stump1eb44332009-09-09 15:08:12 +00001898
Douglas Gregorb98b1992009-08-11 05:31:07 +00001899 /// \brief Build a new C++ functional-style cast expression.
1900 ///
1901 /// By default, performs semantic analysis to build the new expression.
1902 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001903 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1904 SourceLocation LParenLoc,
1905 Expr *Sub,
1906 SourceLocation RParenLoc) {
1907 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001908 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001909 RParenLoc);
1910 }
Mike Stump1eb44332009-09-09 15:08:12 +00001911
Douglas Gregorb98b1992009-08-11 05:31:07 +00001912 /// \brief Build a new C++ typeid(type) expression.
1913 ///
1914 /// By default, performs semantic analysis to build the new expression.
1915 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001916 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001917 SourceLocation TypeidLoc,
1918 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001919 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001920 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001921 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001922 }
Mike Stump1eb44332009-09-09 15:08:12 +00001923
Francois Pichet01b7c302010-09-08 12:20:18 +00001924
Douglas Gregorb98b1992009-08-11 05:31:07 +00001925 /// \brief Build a new C++ typeid(expr) expression.
1926 ///
1927 /// By default, performs semantic analysis to build the new expression.
1928 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001929 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001930 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001931 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001932 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001933 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001934 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001935 }
1936
Francois Pichet01b7c302010-09-08 12:20:18 +00001937 /// \brief Build a new C++ __uuidof(type) expression.
1938 ///
1939 /// By default, performs semantic analysis to build the new expression.
1940 /// Subclasses may override this routine to provide different behavior.
1941 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1942 SourceLocation TypeidLoc,
1943 TypeSourceInfo *Operand,
1944 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001945 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001946 RParenLoc);
1947 }
1948
1949 /// \brief Build a new C++ __uuidof(expr) expression.
1950 ///
1951 /// By default, performs semantic analysis to build the new expression.
1952 /// Subclasses may override this routine to provide different behavior.
1953 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1954 SourceLocation TypeidLoc,
1955 Expr *Operand,
1956 SourceLocation RParenLoc) {
1957 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1958 RParenLoc);
1959 }
1960
Douglas Gregorb98b1992009-08-11 05:31:07 +00001961 /// \brief Build a new C++ "this" expression.
1962 ///
1963 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001964 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001965 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001966 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001967 QualType ThisType,
1968 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001969 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001970 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001971 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1972 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001973 }
1974
1975 /// \brief Build a new C++ throw expression.
1976 ///
1977 /// By default, performs semantic analysis to build the new expression.
1978 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001979 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1980 bool IsThrownVariableInScope) {
1981 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001982 }
1983
1984 /// \brief Build a new C++ default-argument expression.
1985 ///
1986 /// By default, builds a new default-argument expression, which does not
1987 /// require any semantic analysis. Subclasses may override this routine to
1988 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001989 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001990 ParmVarDecl *Param) {
1991 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1992 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001993 }
1994
Richard Smithc3bf52c2013-04-20 22:23:05 +00001995 /// \brief Build a new C++11 default-initialization expression.
1996 ///
1997 /// By default, builds a new default field initialization expression, which
1998 /// does not require any semantic analysis. Subclasses may override this
1999 /// routine to provide different behavior.
2000 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2001 FieldDecl *Field) {
2002 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2003 Field));
2004 }
2005
Douglas Gregorb98b1992009-08-11 05:31:07 +00002006 /// \brief Build a new C++ zero-initialization expression.
2007 ///
2008 /// By default, performs semantic analysis to build the new expression.
2009 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002010 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2011 SourceLocation LParenLoc,
2012 SourceLocation RParenLoc) {
2013 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002014 None, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002015 }
Mike Stump1eb44332009-09-09 15:08:12 +00002016
Douglas Gregorb98b1992009-08-11 05:31:07 +00002017 /// \brief Build a new C++ "new" expression.
2018 ///
2019 /// By default, performs semantic analysis to build the new expression.
2020 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002021 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002022 bool UseGlobal,
2023 SourceLocation PlacementLParen,
2024 MultiExprArg PlacementArgs,
2025 SourceLocation PlacementRParen,
2026 SourceRange TypeIdParens,
2027 QualType AllocatedType,
2028 TypeSourceInfo *AllocatedTypeInfo,
2029 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002030 SourceRange DirectInitRange,
2031 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002032 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002033 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002034 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002035 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002036 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002037 AllocatedType,
2038 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002039 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002040 DirectInitRange,
2041 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002042 }
Mike Stump1eb44332009-09-09 15:08:12 +00002043
Douglas Gregorb98b1992009-08-11 05:31:07 +00002044 /// \brief Build a new C++ "delete" expression.
2045 ///
2046 /// By default, performs semantic analysis to build the new expression.
2047 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002048 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002049 bool IsGlobalDelete,
2050 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002051 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002052 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002053 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002054 }
Mike Stump1eb44332009-09-09 15:08:12 +00002055
Douglas Gregorb98b1992009-08-11 05:31:07 +00002056 /// \brief Build a new unary type trait expression.
2057 ///
2058 /// By default, performs semantic analysis to build the new expression.
2059 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002060 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002061 SourceLocation StartLoc,
2062 TypeSourceInfo *T,
2063 SourceLocation RParenLoc) {
2064 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002065 }
2066
Francois Pichet6ad6f282010-12-07 00:08:36 +00002067 /// \brief Build a new binary type trait expression.
2068 ///
2069 /// By default, performs semantic analysis to build the new expression.
2070 /// Subclasses may override this routine to provide different behavior.
2071 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2072 SourceLocation StartLoc,
2073 TypeSourceInfo *LhsT,
2074 TypeSourceInfo *RhsT,
2075 SourceLocation RParenLoc) {
2076 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2077 }
2078
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002079 /// \brief Build a new type trait expression.
2080 ///
2081 /// By default, performs semantic analysis to build the new expression.
2082 /// Subclasses may override this routine to provide different behavior.
2083 ExprResult RebuildTypeTrait(TypeTrait Trait,
2084 SourceLocation StartLoc,
2085 ArrayRef<TypeSourceInfo *> Args,
2086 SourceLocation RParenLoc) {
2087 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2088 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002089
John Wiegley21ff2e52011-04-28 00:16:57 +00002090 /// \brief Build a new array type trait expression.
2091 ///
2092 /// By default, performs semantic analysis to build the new expression.
2093 /// Subclasses may override this routine to provide different behavior.
2094 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2095 SourceLocation StartLoc,
2096 TypeSourceInfo *TSInfo,
2097 Expr *DimExpr,
2098 SourceLocation RParenLoc) {
2099 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2100 }
2101
John Wiegley55262202011-04-25 06:54:41 +00002102 /// \brief Build a new expression trait expression.
2103 ///
2104 /// By default, performs semantic analysis to build the new expression.
2105 /// Subclasses may override this routine to provide different behavior.
2106 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2107 SourceLocation StartLoc,
2108 Expr *Queried,
2109 SourceLocation RParenLoc) {
2110 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2111 }
2112
Mike Stump1eb44332009-09-09 15:08:12 +00002113 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002114 /// expression.
2115 ///
2116 /// By default, performs semantic analysis to build the new expression.
2117 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002118 ExprResult RebuildDependentScopeDeclRefExpr(
2119 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002120 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002121 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002122 const TemplateArgumentListInfo *TemplateArgs,
2123 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002124 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002125 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002126
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002127 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002128 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002129 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002130
Richard Smithefeeccf2012-10-21 03:28:35 +00002131 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2132 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002133 }
2134
2135 /// \brief Build a new template-id expression.
2136 ///
2137 /// By default, performs semantic analysis to build the new expression.
2138 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002139 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002140 SourceLocation TemplateKWLoc,
2141 LookupResult &R,
2142 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002143 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002144 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2145 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002146 }
2147
2148 /// \brief Build a new object-construction expression.
2149 ///
2150 /// By default, performs semantic analysis to build the new expression.
2151 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002152 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002153 SourceLocation Loc,
2154 CXXConstructorDecl *Constructor,
2155 bool IsElidable,
2156 MultiExprArg Args,
2157 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002158 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002159 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002160 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002161 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002162 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002163 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002164 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002165 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002166
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002167 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002168 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002169 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002170 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002171 RequiresZeroInit, ConstructKind,
2172 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002173 }
2174
2175 /// \brief Build a new object-construction expression.
2176 ///
2177 /// By default, performs semantic analysis to build the new expression.
2178 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002179 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2180 SourceLocation LParenLoc,
2181 MultiExprArg Args,
2182 SourceLocation RParenLoc) {
2183 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002184 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002185 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002186 RParenLoc);
2187 }
2188
2189 /// \brief Build a new object-construction expression.
2190 ///
2191 /// By default, performs semantic analysis to build the new expression.
2192 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002193 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2194 SourceLocation LParenLoc,
2195 MultiExprArg Args,
2196 SourceLocation RParenLoc) {
2197 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002198 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002199 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002200 RParenLoc);
2201 }
Mike Stump1eb44332009-09-09 15:08:12 +00002202
Douglas Gregorb98b1992009-08-11 05:31:07 +00002203 /// \brief Build a new member reference expression.
2204 ///
2205 /// By default, performs semantic analysis to build the new expression.
2206 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002207 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002208 QualType BaseType,
2209 bool IsArrow,
2210 SourceLocation OperatorLoc,
2211 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002212 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002213 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002214 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002215 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002216 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002217 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002218
John McCall9ae2f072010-08-23 23:25:46 +00002219 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002220 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002221 SS, TemplateKWLoc,
2222 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002223 MemberNameInfo,
2224 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002225 }
2226
John McCall129e2df2009-11-30 22:42:35 +00002227 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002228 ///
2229 /// By default, performs semantic analysis to build the new expression.
2230 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002231 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2232 SourceLocation OperatorLoc,
2233 bool IsArrow,
2234 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002235 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002236 NamedDecl *FirstQualifierInScope,
2237 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002238 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002239 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002240 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002241
John McCall9ae2f072010-08-23 23:25:46 +00002242 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002243 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002244 SS, TemplateKWLoc,
2245 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002246 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002247 }
Mike Stump1eb44332009-09-09 15:08:12 +00002248
Sebastian Redl2e156222010-09-10 20:55:43 +00002249 /// \brief Build a new noexcept expression.
2250 ///
2251 /// By default, performs semantic analysis to build the new expression.
2252 /// Subclasses may override this routine to provide different behavior.
2253 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2254 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2255 }
2256
Douglas Gregoree8aff02011-01-04 17:33:58 +00002257 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002258 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2259 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002260 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002261 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002262 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002263 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2264 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002265 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002266
2267 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2268 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002269 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002270 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002271
Patrick Beardeb382ec2012-04-19 00:25:12 +00002272 /// \brief Build a new Objective-C boxed expression.
2273 ///
2274 /// By default, performs semantic analysis to build the new expression.
2275 /// Subclasses may override this routine to provide different behavior.
2276 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2277 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2278 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002279
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002280 /// \brief Build a new Objective-C array literal.
2281 ///
2282 /// By default, performs semantic analysis to build the new expression.
2283 /// Subclasses may override this routine to provide different behavior.
2284 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2285 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002286 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002287 MultiExprArg(Elements, NumElements));
2288 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002289
2290 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002291 Expr *Base, Expr *Key,
2292 ObjCMethodDecl *getterMethod,
2293 ObjCMethodDecl *setterMethod) {
2294 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2295 getterMethod, setterMethod);
2296 }
2297
2298 /// \brief Build a new Objective-C dictionary literal.
2299 ///
2300 /// By default, performs semantic analysis to build the new expression.
2301 /// Subclasses may override this routine to provide different behavior.
2302 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2303 ObjCDictionaryElement *Elements,
2304 unsigned NumElements) {
2305 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2306 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002307
James Dennett699c9042012-06-15 07:13:21 +00002308 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002309 ///
2310 /// By default, performs semantic analysis to build the new expression.
2311 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002312 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002313 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002314 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002315 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002316 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002317 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002318
Douglas Gregor92e986e2010-04-22 16:44:27 +00002319 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002320 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002321 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002322 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002323 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002324 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002325 MultiExprArg Args,
2326 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002327 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2328 ReceiverTypeInfo->getType(),
2329 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002330 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002331 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002332 }
2333
2334 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002335 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002336 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002337 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002338 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002339 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002340 MultiExprArg Args,
2341 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002342 return SemaRef.BuildInstanceMessage(Receiver,
2343 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002344 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002345 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002346 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002347 }
2348
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002349 /// \brief Build a new Objective-C ivar reference expression.
2350 ///
2351 /// By default, performs semantic analysis to build the new expression.
2352 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002353 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002354 SourceLocation IvarLoc,
2355 bool IsArrow, bool IsFreeIvar) {
2356 // FIXME: We lose track of the IsFreeIvar bit.
2357 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002358 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002359 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2360 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002361 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002362 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002363 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002364 false);
John Wiegley429bb272011-04-08 18:41:53 +00002365 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002366 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002367
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002368 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002369 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002370
John Wiegley429bb272011-04-08 18:41:53 +00002371 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002372 /*FIXME:*/IvarLoc, IsArrow,
2373 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002374 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002375 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002376 /*TemplateArgs=*/0);
2377 }
Douglas Gregore3303542010-04-26 20:47:02 +00002378
2379 /// \brief Build a new Objective-C property reference expression.
2380 ///
2381 /// By default, performs semantic analysis to build the new expression.
2382 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002383 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002384 ObjCPropertyDecl *Property,
2385 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002386 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002387 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002388 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2389 Sema::LookupMemberName);
2390 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002391 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002392 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002393 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002394 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002395 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002396
Douglas Gregore3303542010-04-26 20:47:02 +00002397 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002398 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002399
John Wiegley429bb272011-04-08 18:41:53 +00002400 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002401 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002402 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002403 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002404 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002405 /*TemplateArgs=*/0);
2406 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002407
John McCall12f78a62010-12-02 01:19:52 +00002408 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002409 ///
2410 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002411 /// Subclasses may override this routine to provide different behavior.
2412 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2413 ObjCMethodDecl *Getter,
2414 ObjCMethodDecl *Setter,
2415 SourceLocation PropertyLoc) {
2416 // Since these expressions can only be value-dependent, we do not
2417 // need to perform semantic analysis again.
2418 return Owned(
2419 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2420 VK_LValue, OK_ObjCProperty,
2421 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002422 }
2423
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002424 /// \brief Build a new Objective-C "isa" expression.
2425 ///
2426 /// By default, performs semantic analysis to build the new expression.
2427 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002428 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002429 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002430 bool IsArrow) {
2431 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002432 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002433 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2434 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002435 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002436 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002437 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002438 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002439 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002440
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002441 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002442 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002443
John Wiegley429bb272011-04-08 18:41:53 +00002444 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002445 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002446 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002447 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002448 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002449 /*TemplateArgs=*/0);
2450 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002451
Douglas Gregorb98b1992009-08-11 05:31:07 +00002452 /// \brief Build a new shuffle vector expression.
2453 ///
2454 /// By default, performs semantic analysis to build the new expression.
2455 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002456 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002457 MultiExprArg SubExprs,
2458 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002459 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002460 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002461 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2462 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2463 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002464 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002465
Douglas Gregorb98b1992009-08-11 05:31:07 +00002466 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002467 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002468 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2469 SemaRef.Context.BuiltinFnTy,
2470 VK_RValue, BuiltinLoc);
2471 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2472 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2473 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002474
2475 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002476 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002477 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002478 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002479 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002480 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002481
Douglas Gregorb98b1992009-08-11 05:31:07 +00002482 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002483 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002484 }
John McCall43fed0d2010-11-12 08:19:04 +00002485
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002486 /// \brief Build a new template argument pack expansion.
2487 ///
2488 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002489 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002490 /// different behavior.
2491 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002492 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002493 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002494 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002495 case TemplateArgument::Expression: {
2496 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002497 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2498 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002499 if (Result.isInvalid())
2500 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002501
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002502 return TemplateArgumentLoc(Result.get(), Result.get());
2503 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002504
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002505 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002506 return TemplateArgumentLoc(TemplateArgument(
2507 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002508 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002509 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002510 Pattern.getTemplateNameLoc(),
2511 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002512
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002513 case TemplateArgument::Null:
2514 case TemplateArgument::Integral:
2515 case TemplateArgument::Declaration:
2516 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002517 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002518 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002519 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002520
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002521 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002522 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002523 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002524 EllipsisLoc,
2525 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002526 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2527 Expansion);
2528 break;
2529 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002530
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002531 return TemplateArgumentLoc();
2532 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002533
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002534 /// \brief Build a new expression pack expansion.
2535 ///
2536 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002537 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002538 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002539 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002540 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002541 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002542 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002543
2544 /// \brief Build a new atomic operation expression.
2545 ///
2546 /// By default, performs semantic analysis to build the new expression.
2547 /// Subclasses may override this routine to provide different behavior.
2548 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2549 MultiExprArg SubExprs,
2550 QualType RetTy,
2551 AtomicExpr::AtomicOp Op,
2552 SourceLocation RParenLoc) {
2553 // Just create the expression; there is not any interesting semantic
2554 // analysis here because we can't actually build an AtomicExpr until
2555 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002556 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002557 RParenLoc);
2558 }
2559
John McCall43fed0d2010-11-12 08:19:04 +00002560private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002561 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2562 QualType ObjectType,
2563 NamedDecl *FirstQualifierInScope,
2564 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002565
2566 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2567 QualType ObjectType,
2568 NamedDecl *FirstQualifierInScope,
2569 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002570};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002571
Douglas Gregor43959a92009-08-20 07:17:43 +00002572template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002573StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002574 if (!S)
2575 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002576
Douglas Gregor43959a92009-08-20 07:17:43 +00002577 switch (S->getStmtClass()) {
2578 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002579
Douglas Gregor43959a92009-08-20 07:17:43 +00002580 // Transform individual statement nodes
2581#define STMT(Node, Parent) \
2582 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002583#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002584#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002585#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002586
Douglas Gregor43959a92009-08-20 07:17:43 +00002587 // Transform expressions by calling TransformExpr.
2588#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002589#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002590#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002591#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002592 {
John McCall60d7b3a2010-08-24 06:29:42 +00002593 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002594 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002595 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002596
Richard Smith41956372013-01-14 22:39:08 +00002597 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002598 }
Mike Stump1eb44332009-09-09 15:08:12 +00002599 }
2600
John McCall3fa5cae2010-10-26 07:05:15 +00002601 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002602}
Mike Stump1eb44332009-09-09 15:08:12 +00002603
2604
Douglas Gregor670444e2009-08-04 22:27:00 +00002605template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002606ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002607 if (!E)
2608 return SemaRef.Owned(E);
2609
2610 switch (E->getStmtClass()) {
2611 case Stmt::NoStmtClass: break;
2612#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002613#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002614#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002615 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002616#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002617 }
2618
John McCall3fa5cae2010-10-26 07:05:15 +00002619 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002620}
2621
2622template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002623ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2624 bool CXXDirectInit) {
2625 // Initializers are instantiated like expressions, except that various outer
2626 // layers are stripped.
2627 if (!Init)
2628 return SemaRef.Owned(Init);
2629
2630 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2631 Init = ExprTemp->getSubExpr();
2632
2633 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2634 Init = Binder->getSubExpr();
2635
2636 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2637 Init = ICE->getSubExprAsWritten();
2638
Richard Smith5cf15892012-12-21 08:13:35 +00002639 // If this is not a direct-initializer, we only need to reconstruct
2640 // InitListExprs. Other forms of copy-initialization will be a no-op if
2641 // the initializer is already the right type.
2642 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2643 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2644 return getDerived().TransformExpr(Init);
2645
2646 // Revert value-initialization back to empty parens.
2647 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2648 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002649 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002650 Parens.getEnd());
2651 }
2652
2653 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2654 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002655 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002656 SourceLocation());
2657
2658 // Revert initialization by constructor back to a parenthesized or braced list
2659 // of expressions. Any other form of initializer can just be reused directly.
2660 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002661 return getDerived().TransformExpr(Init);
2662
2663 SmallVector<Expr*, 8> NewArgs;
2664 bool ArgChanged = false;
2665 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2666 /*IsCall*/true, NewArgs, &ArgChanged))
2667 return ExprError();
2668
2669 // If this was list initialization, revert to list form.
2670 if (Construct->isListInitialization())
2671 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2672 Construct->getLocEnd(),
2673 Construct->getType());
2674
Richard Smithc83c2302012-12-19 01:39:02 +00002675 // Build a ParenListExpr to represent anything else.
2676 SourceRange Parens = Construct->getParenRange();
2677 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2678 Parens.getEnd());
2679}
2680
2681template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002682bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2683 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002684 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002685 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002686 bool *ArgChanged) {
2687 for (unsigned I = 0; I != NumInputs; ++I) {
2688 // If requested, drop call arguments that need to be dropped.
2689 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2690 if (ArgChanged)
2691 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002692
Douglas Gregoraa165f82011-01-03 19:04:46 +00002693 break;
2694 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002695
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002696 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2697 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002698
Chris Lattner686775d2011-07-20 06:58:45 +00002699 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002700 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2701 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002702
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002703 // Determine whether the set of unexpanded parameter packs can and should
2704 // be expanded.
2705 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002706 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002707 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2708 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002709 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2710 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002711 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002712 Expand, RetainExpansion,
2713 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002714 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002715
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002716 if (!Expand) {
2717 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002718 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002719 // expansion.
2720 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2721 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2722 if (OutPattern.isInvalid())
2723 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002724
2725 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002726 Expansion->getEllipsisLoc(),
2727 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002728 if (Out.isInvalid())
2729 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002730
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002731 if (ArgChanged)
2732 *ArgChanged = true;
2733 Outputs.push_back(Out.get());
2734 continue;
2735 }
John McCallc8fc90a2011-07-06 07:30:07 +00002736
2737 // Record right away that the argument was changed. This needs
2738 // to happen even if the array expands to nothing.
2739 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002740
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002741 // The transform has determined that we should perform an elementwise
2742 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002743 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002744 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2745 ExprResult Out = getDerived().TransformExpr(Pattern);
2746 if (Out.isInvalid())
2747 return true;
2748
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002749 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002750 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2751 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002752 if (Out.isInvalid())
2753 return true;
2754 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002755
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002756 Outputs.push_back(Out.get());
2757 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002758
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002759 continue;
2760 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002761
Richard Smithc83c2302012-12-19 01:39:02 +00002762 ExprResult Result =
2763 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2764 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002765 if (Result.isInvalid())
2766 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002767
Douglas Gregoraa165f82011-01-03 19:04:46 +00002768 if (Result.get() != Inputs[I] && ArgChanged)
2769 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002770
2771 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002772 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002773
Douglas Gregoraa165f82011-01-03 19:04:46 +00002774 return false;
2775}
2776
2777template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002778NestedNameSpecifierLoc
2779TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2780 NestedNameSpecifierLoc NNS,
2781 QualType ObjectType,
2782 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002783 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002784 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002785 Qualifier = Qualifier.getPrefix())
2786 Qualifiers.push_back(Qualifier);
2787
2788 CXXScopeSpec SS;
2789 while (!Qualifiers.empty()) {
2790 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2791 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002792
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002793 switch (QNNS->getKind()) {
2794 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002795 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002796 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002797 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002798 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002799 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002800 FirstQualifierInScope, false))
2801 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002802
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002803 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002804
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002805 case NestedNameSpecifier::Namespace: {
2806 NamespaceDecl *NS
2807 = cast_or_null<NamespaceDecl>(
2808 getDerived().TransformDecl(
2809 Q.getLocalBeginLoc(),
2810 QNNS->getAsNamespace()));
2811 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2812 break;
2813 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002814
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002815 case NestedNameSpecifier::NamespaceAlias: {
2816 NamespaceAliasDecl *Alias
2817 = cast_or_null<NamespaceAliasDecl>(
2818 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2819 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002820 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002821 Q.getLocalEndLoc());
2822 break;
2823 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002824
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002825 case NestedNameSpecifier::Global:
2826 // There is no meaningful transformation that one could perform on the
2827 // global scope.
2828 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2829 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002830
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002831 case NestedNameSpecifier::TypeSpecWithTemplate:
2832 case NestedNameSpecifier::TypeSpec: {
2833 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2834 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002835
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002836 if (!TL)
2837 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002838
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002839 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002840 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002841 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002842 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002843 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002844 if (TL.getType()->isEnumeralType())
2845 SemaRef.Diag(TL.getBeginLoc(),
2846 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002847 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2848 Q.getLocalEndLoc());
2849 break;
2850 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002851 // If the nested-name-specifier is an invalid type def, don't emit an
2852 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002853 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2854 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002855 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002856 << TL.getType() << SS.getRange();
2857 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002858 return NestedNameSpecifierLoc();
2859 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002860 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002861
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002862 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002863 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002864 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002865 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002866
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002867 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002868 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002869 !getDerived().AlwaysRebuild())
2870 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002871
2872 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002873 // nested-name-specifier, do so.
2874 if (SS.location_size() == NNS.getDataLength() &&
2875 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2876 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2877
2878 // Allocate new nested-name-specifier location information.
2879 return SS.getWithLocInContext(SemaRef.Context);
2880}
2881
2882template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002883DeclarationNameInfo
2884TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002885::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002886 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002887 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002888 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002889
2890 switch (Name.getNameKind()) {
2891 case DeclarationName::Identifier:
2892 case DeclarationName::ObjCZeroArgSelector:
2893 case DeclarationName::ObjCOneArgSelector:
2894 case DeclarationName::ObjCMultiArgSelector:
2895 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002896 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002897 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002898 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002899
Douglas Gregor81499bb2009-09-03 22:13:48 +00002900 case DeclarationName::CXXConstructorName:
2901 case DeclarationName::CXXDestructorName:
2902 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002903 TypeSourceInfo *NewTInfo;
2904 CanQualType NewCanTy;
2905 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002906 NewTInfo = getDerived().TransformType(OldTInfo);
2907 if (!NewTInfo)
2908 return DeclarationNameInfo();
2909 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002910 }
2911 else {
2912 NewTInfo = 0;
2913 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002914 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002915 if (NewT.isNull())
2916 return DeclarationNameInfo();
2917 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2918 }
Mike Stump1eb44332009-09-09 15:08:12 +00002919
Abramo Bagnara25777432010-08-11 22:01:17 +00002920 DeclarationName NewName
2921 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2922 NewCanTy);
2923 DeclarationNameInfo NewNameInfo(NameInfo);
2924 NewNameInfo.setName(NewName);
2925 NewNameInfo.setNamedTypeInfo(NewTInfo);
2926 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002927 }
Mike Stump1eb44332009-09-09 15:08:12 +00002928 }
2929
David Blaikieb219cfc2011-09-23 05:06:16 +00002930 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002931}
2932
2933template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002934TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002935TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2936 TemplateName Name,
2937 SourceLocation NameLoc,
2938 QualType ObjectType,
2939 NamedDecl *FirstQualifierInScope) {
2940 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2941 TemplateDecl *Template = QTN->getTemplateDecl();
2942 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002943
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002944 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002945 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002946 Template));
2947 if (!TransTemplate)
2948 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002949
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002950 if (!getDerived().AlwaysRebuild() &&
2951 SS.getScopeRep() == QTN->getQualifier() &&
2952 TransTemplate == Template)
2953 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002954
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002955 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2956 TransTemplate);
2957 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002958
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002959 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2960 if (SS.getScopeRep()) {
2961 // These apply to the scope specifier, not the template.
2962 ObjectType = QualType();
2963 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002964 }
2965
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002966 if (!getDerived().AlwaysRebuild() &&
2967 SS.getScopeRep() == DTN->getQualifier() &&
2968 ObjectType.isNull())
2969 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002970
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002971 if (DTN->isIdentifier()) {
2972 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002973 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002974 NameLoc,
2975 ObjectType,
2976 FirstQualifierInScope);
2977 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002978
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002979 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2980 ObjectType);
2981 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002982
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002983 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2984 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002985 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002986 Template));
2987 if (!TransTemplate)
2988 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002989
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002990 if (!getDerived().AlwaysRebuild() &&
2991 TransTemplate == Template)
2992 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002993
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002994 return TemplateName(TransTemplate);
2995 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002996
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002997 if (SubstTemplateTemplateParmPackStorage *SubstPack
2998 = Name.getAsSubstTemplateTemplateParmPack()) {
2999 TemplateTemplateParmDecl *TransParam
3000 = cast_or_null<TemplateTemplateParmDecl>(
3001 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3002 if (!TransParam)
3003 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003004
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003005 if (!getDerived().AlwaysRebuild() &&
3006 TransParam == SubstPack->getParameterPack())
3007 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003008
3009 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003010 SubstPack->getArgumentPack());
3011 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003012
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003013 // These should be getting filtered out before they reach the AST.
3014 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003015}
3016
3017template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003018void TreeTransform<Derived>::InventTemplateArgumentLoc(
3019 const TemplateArgument &Arg,
3020 TemplateArgumentLoc &Output) {
3021 SourceLocation Loc = getDerived().getBaseLocation();
3022 switch (Arg.getKind()) {
3023 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003024 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003025 break;
3026
3027 case TemplateArgument::Type:
3028 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003029 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003030
John McCall833ca992009-10-29 08:12:44 +00003031 break;
3032
Douglas Gregor788cd062009-11-11 01:00:40 +00003033 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003034 case TemplateArgument::TemplateExpansion: {
3035 NestedNameSpecifierLocBuilder Builder;
3036 TemplateName Template = Arg.getAsTemplate();
3037 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3038 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3039 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3040 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003041
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003042 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003043 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003044 Builder.getWithLocInContext(SemaRef.Context),
3045 Loc);
3046 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003047 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003048 Builder.getWithLocInContext(SemaRef.Context),
3049 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003050
Douglas Gregor788cd062009-11-11 01:00:40 +00003051 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003052 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003053
John McCall833ca992009-10-29 08:12:44 +00003054 case TemplateArgument::Expression:
3055 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3056 break;
3057
3058 case TemplateArgument::Declaration:
3059 case TemplateArgument::Integral:
3060 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003061 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003062 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003063 break;
3064 }
3065}
3066
3067template<typename Derived>
3068bool TreeTransform<Derived>::TransformTemplateArgument(
3069 const TemplateArgumentLoc &Input,
3070 TemplateArgumentLoc &Output) {
3071 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003072 switch (Arg.getKind()) {
3073 case TemplateArgument::Null:
3074 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003075 case TemplateArgument::Pack:
3076 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003077 case TemplateArgument::NullPtr:
3078 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003079
Douglas Gregor670444e2009-08-04 22:27:00 +00003080 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003081 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003082 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003083 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003084
3085 DI = getDerived().TransformType(DI);
3086 if (!DI) return true;
3087
3088 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3089 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003090 }
Mike Stump1eb44332009-09-09 15:08:12 +00003091
Douglas Gregor788cd062009-11-11 01:00:40 +00003092 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003093 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3094 if (QualifierLoc) {
3095 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3096 if (!QualifierLoc)
3097 return true;
3098 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003099
Douglas Gregor1d752d72011-03-02 18:46:51 +00003100 CXXScopeSpec SS;
3101 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003102 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003103 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3104 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003105 if (Template.isNull())
3106 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003107
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003108 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003109 Input.getTemplateNameLoc());
3110 return false;
3111 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003112
3113 case TemplateArgument::TemplateExpansion:
3114 llvm_unreachable("Caller should expand pack expansions");
3115
Douglas Gregor670444e2009-08-04 22:27:00 +00003116 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003117 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003118 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003119 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003120
John McCall833ca992009-10-29 08:12:44 +00003121 Expr *InputExpr = Input.getSourceExpression();
3122 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3123
Chris Lattner223de242011-04-25 20:37:58 +00003124 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003125 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003126 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003127 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003128 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003129 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003130 }
Mike Stump1eb44332009-09-09 15:08:12 +00003131
Douglas Gregor670444e2009-08-04 22:27:00 +00003132 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003133 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003134}
3135
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003136/// \brief Iterator adaptor that invents template argument location information
3137/// for each of the template arguments in its underlying iterator.
3138template<typename Derived, typename InputIterator>
3139class TemplateArgumentLocInventIterator {
3140 TreeTransform<Derived> &Self;
3141 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003142
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003143public:
3144 typedef TemplateArgumentLoc value_type;
3145 typedef TemplateArgumentLoc reference;
3146 typedef typename std::iterator_traits<InputIterator>::difference_type
3147 difference_type;
3148 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003149
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003150 class pointer {
3151 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003152
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003153 public:
3154 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003155
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003156 const TemplateArgumentLoc *operator->() const { return &Arg; }
3157 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003158
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003159 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003160
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003161 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3162 InputIterator Iter)
3163 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003164
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003165 TemplateArgumentLocInventIterator &operator++() {
3166 ++Iter;
3167 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003168 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003169
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003170 TemplateArgumentLocInventIterator operator++(int) {
3171 TemplateArgumentLocInventIterator Old(*this);
3172 ++(*this);
3173 return Old;
3174 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003175
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003176 reference operator*() const {
3177 TemplateArgumentLoc Result;
3178 Self.InventTemplateArgumentLoc(*Iter, Result);
3179 return Result;
3180 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003181
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003182 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003183
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003184 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3185 const TemplateArgumentLocInventIterator &Y) {
3186 return X.Iter == Y.Iter;
3187 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003188
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003189 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3190 const TemplateArgumentLocInventIterator &Y) {
3191 return X.Iter != Y.Iter;
3192 }
3193};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003194
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003195template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003196template<typename InputIterator>
3197bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3198 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003199 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003200 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003201 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003202 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003203
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003204 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3205 // Unpack argument packs, which we translate them into separate
3206 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003207 // FIXME: We could do much better if we could guarantee that the
3208 // TemplateArgumentLocInfo for the pack expansion would be usable for
3209 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003210 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003211 TemplateArgument::pack_iterator>
3212 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003213 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003214 In.getArgument().pack_begin()),
3215 PackLocIterator(*this,
3216 In.getArgument().pack_end()),
3217 Outputs))
3218 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003219
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003220 continue;
3221 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003222
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003223 if (In.getArgument().isPackExpansion()) {
3224 // We have a pack expansion, for which we will be substituting into
3225 // the pattern.
3226 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003227 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003228 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003229 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003230 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003231
Chris Lattner686775d2011-07-20 06:58:45 +00003232 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003233 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3234 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003235
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003236 // Determine whether the set of unexpanded parameter packs can and should
3237 // be expanded.
3238 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003239 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003240 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003241 if (getDerived().TryExpandParameterPacks(Ellipsis,
3242 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003243 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003244 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003245 RetainExpansion,
3246 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003247 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003248
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003249 if (!Expand) {
3250 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003251 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003252 // expansion.
3253 TemplateArgumentLoc OutPattern;
3254 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3255 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3256 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003257
Douglas Gregorcded4f62011-01-14 17:04:44 +00003258 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3259 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003260 if (Out.getArgument().isNull())
3261 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003262
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003263 Outputs.addArgument(Out);
3264 continue;
3265 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003266
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003267 // The transform has determined that we should perform an elementwise
3268 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003269 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003270 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3271
3272 if (getDerived().TransformTemplateArgument(Pattern, Out))
3273 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003274
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003275 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003276 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3277 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003278 if (Out.getArgument().isNull())
3279 return true;
3280 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003281
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003282 Outputs.addArgument(Out);
3283 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003284
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003285 // If we're supposed to retain a pack expansion, do so by temporarily
3286 // forgetting the partially-substituted parameter pack.
3287 if (RetainExpansion) {
3288 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003289
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003290 if (getDerived().TransformTemplateArgument(Pattern, Out))
3291 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003292
Douglas Gregorcded4f62011-01-14 17:04:44 +00003293 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3294 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003295 if (Out.getArgument().isNull())
3296 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003297
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003298 Outputs.addArgument(Out);
3299 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003300
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003301 continue;
3302 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003303
3304 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003305 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003306 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003307
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003308 Outputs.addArgument(Out);
3309 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003310
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003311 return false;
3312
3313}
3314
Douglas Gregor577f75a2009-08-04 16:50:30 +00003315//===----------------------------------------------------------------------===//
3316// Type transformation
3317//===----------------------------------------------------------------------===//
3318
3319template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003320QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003321 if (getDerived().AlreadyTransformed(T))
3322 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003323
John McCalla2becad2009-10-21 00:40:46 +00003324 // Temporary workaround. All of these transformations should
3325 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003326 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3327 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003328
John McCall43fed0d2010-11-12 08:19:04 +00003329 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003330
John McCalla2becad2009-10-21 00:40:46 +00003331 if (!NewDI)
3332 return QualType();
3333
3334 return NewDI->getType();
3335}
3336
3337template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003338TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003339 // Refine the base location to the type's location.
3340 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3341 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003342 if (getDerived().AlreadyTransformed(DI->getType()))
3343 return DI;
3344
3345 TypeLocBuilder TLB;
3346
3347 TypeLoc TL = DI->getTypeLoc();
3348 TLB.reserve(TL.getFullDataSize());
3349
John McCall43fed0d2010-11-12 08:19:04 +00003350 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003351 if (Result.isNull())
3352 return 0;
3353
John McCalla93c9342009-12-07 02:54:59 +00003354 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003355}
3356
3357template<typename Derived>
3358QualType
John McCall43fed0d2010-11-12 08:19:04 +00003359TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003360 switch (T.getTypeLocClass()) {
3361#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003362#define TYPELOC(CLASS, PARENT) \
3363 case TypeLoc::CLASS: \
3364 return getDerived().Transform##CLASS##Type(TLB, \
3365 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003366#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003367 }
Mike Stump1eb44332009-09-09 15:08:12 +00003368
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003369 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003370}
3371
3372/// FIXME: By default, this routine adds type qualifiers only to types
3373/// that can have qualifiers, and silently suppresses those qualifiers
3374/// that are not permitted (e.g., qualifiers on reference or function
3375/// types). This is the right thing for template instantiation, but
3376/// probably not for other clients.
3377template<typename Derived>
3378QualType
3379TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003380 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003381 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003382
John McCall43fed0d2010-11-12 08:19:04 +00003383 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003384 if (Result.isNull())
3385 return QualType();
3386
3387 // Silently suppress qualifiers if the result type can't be qualified.
3388 // FIXME: this is the right thing for template instantiation, but
3389 // probably not for other clients.
3390 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003391 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003392
John McCallf85e1932011-06-15 23:02:42 +00003393 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003394 // resulting type.
3395 if (Quals.hasObjCLifetime()) {
3396 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3397 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003398 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003399 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003400 // A lifetime qualifier applied to a substituted template parameter
3401 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003402 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003403 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003404 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3405 QualType Replacement = SubstTypeParam->getReplacementType();
3406 Qualifiers Qs = Replacement.getQualifiers();
3407 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003408 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003409 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3410 Qs);
3411 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003412 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003413 Replacement);
3414 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003415 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3416 // 'auto' types behave the same way as template parameters.
3417 QualType Deduced = AutoTy->getDeducedType();
3418 Qualifiers Qs = Deduced.getQualifiers();
3419 Qs.removeObjCLifetime();
3420 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3421 Qs);
Richard Smitha2c36462013-04-26 16:15:35 +00003422 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto());
Douglas Gregor92d13872013-01-17 23:59:28 +00003423 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003424 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003425 // Otherwise, complain about the addition of a qualifier to an
3426 // already-qualified type.
3427 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003428 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003429 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003430
Douglas Gregore559ca12011-06-17 22:11:49 +00003431 Quals.removeObjCLifetime();
3432 }
3433 }
3434 }
John McCall28654742010-06-05 06:41:15 +00003435 if (!Quals.empty()) {
3436 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003437 // BuildQualifiedType might not add qualifiers if they are invalid.
3438 if (Result.hasLocalQualifiers())
3439 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003440 // No location information to preserve.
3441 }
John McCalla2becad2009-10-21 00:40:46 +00003442
3443 return Result;
3444}
3445
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003446template<typename Derived>
3447TypeLoc
3448TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3449 QualType ObjectType,
3450 NamedDecl *UnqualLookup,
3451 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003452 QualType T = TL.getType();
3453 if (getDerived().AlreadyTransformed(T))
3454 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003455
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003456 TypeLocBuilder TLB;
3457 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003458
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003459 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003460 TemplateSpecializationTypeLoc SpecTL =
3461 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003462
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003463 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003464 getDerived().TransformTemplateName(SS,
3465 SpecTL.getTypePtr()->getTemplateName(),
3466 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003467 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003468 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003469 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003470
3471 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003472 Template);
3473 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003474 DependentTemplateSpecializationTypeLoc SpecTL =
3475 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003476
Douglas Gregora88f09f2011-02-28 17:23:35 +00003477 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003478 = getDerived().RebuildTemplateName(SS,
3479 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003480 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003481 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003482 if (Template.isNull())
3483 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003484
3485 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003486 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003487 Template,
3488 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003489 } else {
3490 // Nothing special needs to be done for these.
3491 Result = getDerived().TransformType(TLB, TL);
3492 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003493
3494 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003495 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003496
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003497 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3498}
3499
Douglas Gregorb71d8212011-03-02 18:32:08 +00003500template<typename Derived>
3501TypeSourceInfo *
3502TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3503 QualType ObjectType,
3504 NamedDecl *UnqualLookup,
3505 CXXScopeSpec &SS) {
3506 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003507
Douglas Gregorb71d8212011-03-02 18:32:08 +00003508 QualType T = TSInfo->getType();
3509 if (getDerived().AlreadyTransformed(T))
3510 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003511
Douglas Gregorb71d8212011-03-02 18:32:08 +00003512 TypeLocBuilder TLB;
3513 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003514
Douglas Gregorb71d8212011-03-02 18:32:08 +00003515 TypeLoc TL = TSInfo->getTypeLoc();
3516 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003517 TemplateSpecializationTypeLoc SpecTL =
3518 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003519
Douglas Gregorb71d8212011-03-02 18:32:08 +00003520 TemplateName Template
3521 = getDerived().TransformTemplateName(SS,
3522 SpecTL.getTypePtr()->getTemplateName(),
3523 SpecTL.getTemplateNameLoc(),
3524 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003525 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003526 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003527
3528 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003529 Template);
3530 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003531 DependentTemplateSpecializationTypeLoc SpecTL =
3532 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003533
Douglas Gregorb71d8212011-03-02 18:32:08 +00003534 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003535 = getDerived().RebuildTemplateName(SS,
3536 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003537 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003538 ObjectType, UnqualLookup);
3539 if (Template.isNull())
3540 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003541
3542 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003543 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003544 Template,
3545 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003546 } else {
3547 // Nothing special needs to be done for these.
3548 Result = getDerived().TransformType(TLB, TL);
3549 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003550
3551 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003552 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003553
Douglas Gregorb71d8212011-03-02 18:32:08 +00003554 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3555}
3556
John McCalla2becad2009-10-21 00:40:46 +00003557template <class TyLoc> static inline
3558QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3559 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3560 NewT.setNameLoc(T.getNameLoc());
3561 return T.getType();
3562}
3563
John McCalla2becad2009-10-21 00:40:46 +00003564template<typename Derived>
3565QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003566 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003567 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3568 NewT.setBuiltinLoc(T.getBuiltinLoc());
3569 if (T.needsExtraLocalData())
3570 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3571 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003572}
Mike Stump1eb44332009-09-09 15:08:12 +00003573
Douglas Gregor577f75a2009-08-04 16:50:30 +00003574template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003575QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003576 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003577 // FIXME: recurse?
3578 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003579}
Mike Stump1eb44332009-09-09 15:08:12 +00003580
Douglas Gregor577f75a2009-08-04 16:50:30 +00003581template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003582QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003583 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003584 QualType PointeeType
3585 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003586 if (PointeeType.isNull())
3587 return QualType();
3588
3589 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003590 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003591 // A dependent pointer type 'T *' has is being transformed such
3592 // that an Objective-C class type is being replaced for 'T'. The
3593 // resulting pointer type is an ObjCObjectPointerType, not a
3594 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003595 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003596
John McCallc12c5bb2010-05-15 11:32:37 +00003597 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3598 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003599 return Result;
3600 }
John McCall43fed0d2010-11-12 08:19:04 +00003601
Douglas Gregor92e986e2010-04-22 16:44:27 +00003602 if (getDerived().AlwaysRebuild() ||
3603 PointeeType != TL.getPointeeLoc().getType()) {
3604 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3605 if (Result.isNull())
3606 return QualType();
3607 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003608
John McCallf85e1932011-06-15 23:02:42 +00003609 // Objective-C ARC can add lifetime qualifiers to the type that we're
3610 // pointing to.
3611 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003612
Douglas Gregor92e986e2010-04-22 16:44:27 +00003613 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3614 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003615 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003616}
Mike Stump1eb44332009-09-09 15:08:12 +00003617
3618template<typename Derived>
3619QualType
John McCalla2becad2009-10-21 00:40:46 +00003620TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003621 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003622 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003623 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3624 if (PointeeType.isNull())
3625 return QualType();
3626
3627 QualType Result = TL.getType();
3628 if (getDerived().AlwaysRebuild() ||
3629 PointeeType != TL.getPointeeLoc().getType()) {
3630 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003631 TL.getSigilLoc());
3632 if (Result.isNull())
3633 return QualType();
3634 }
3635
Douglas Gregor39968ad2010-04-22 16:50:51 +00003636 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003637 NewT.setSigilLoc(TL.getSigilLoc());
3638 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003639}
3640
John McCall85737a72009-10-30 00:06:24 +00003641/// Transforms a reference type. Note that somewhat paradoxically we
3642/// don't care whether the type itself is an l-value type or an r-value
3643/// type; we only care if the type was *written* as an l-value type
3644/// or an r-value type.
3645template<typename Derived>
3646QualType
3647TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003648 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003649 const ReferenceType *T = TL.getTypePtr();
3650
3651 // Note that this works with the pointee-as-written.
3652 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3653 if (PointeeType.isNull())
3654 return QualType();
3655
3656 QualType Result = TL.getType();
3657 if (getDerived().AlwaysRebuild() ||
3658 PointeeType != T->getPointeeTypeAsWritten()) {
3659 Result = getDerived().RebuildReferenceType(PointeeType,
3660 T->isSpelledAsLValue(),
3661 TL.getSigilLoc());
3662 if (Result.isNull())
3663 return QualType();
3664 }
3665
John McCallf85e1932011-06-15 23:02:42 +00003666 // Objective-C ARC can add lifetime qualifiers to the type that we're
3667 // referring to.
3668 TLB.TypeWasModifiedSafely(
3669 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3670
John McCall85737a72009-10-30 00:06:24 +00003671 // r-value references can be rebuilt as l-value references.
3672 ReferenceTypeLoc NewTL;
3673 if (isa<LValueReferenceType>(Result))
3674 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3675 else
3676 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3677 NewTL.setSigilLoc(TL.getSigilLoc());
3678
3679 return Result;
3680}
3681
Mike Stump1eb44332009-09-09 15:08:12 +00003682template<typename Derived>
3683QualType
John McCalla2becad2009-10-21 00:40:46 +00003684TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003685 LValueReferenceTypeLoc TL) {
3686 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003687}
3688
Mike Stump1eb44332009-09-09 15:08:12 +00003689template<typename Derived>
3690QualType
John McCalla2becad2009-10-21 00:40:46 +00003691TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003692 RValueReferenceTypeLoc TL) {
3693 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003694}
Mike Stump1eb44332009-09-09 15:08:12 +00003695
Douglas Gregor577f75a2009-08-04 16:50:30 +00003696template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003697QualType
John McCalla2becad2009-10-21 00:40:46 +00003698TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003699 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003700 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003701 if (PointeeType.isNull())
3702 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003703
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003704 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3705 TypeSourceInfo* NewClsTInfo = 0;
3706 if (OldClsTInfo) {
3707 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3708 if (!NewClsTInfo)
3709 return QualType();
3710 }
3711
3712 const MemberPointerType *T = TL.getTypePtr();
3713 QualType OldClsType = QualType(T->getClass(), 0);
3714 QualType NewClsType;
3715 if (NewClsTInfo)
3716 NewClsType = NewClsTInfo->getType();
3717 else {
3718 NewClsType = getDerived().TransformType(OldClsType);
3719 if (NewClsType.isNull())
3720 return QualType();
3721 }
Mike Stump1eb44332009-09-09 15:08:12 +00003722
John McCalla2becad2009-10-21 00:40:46 +00003723 QualType Result = TL.getType();
3724 if (getDerived().AlwaysRebuild() ||
3725 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003726 NewClsType != OldClsType) {
3727 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003728 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003729 if (Result.isNull())
3730 return QualType();
3731 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003732
John McCalla2becad2009-10-21 00:40:46 +00003733 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3734 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003735 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003736
3737 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003738}
3739
Mike Stump1eb44332009-09-09 15:08:12 +00003740template<typename Derived>
3741QualType
John McCalla2becad2009-10-21 00:40:46 +00003742TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003743 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003744 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003745 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003746 if (ElementType.isNull())
3747 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003748
John McCalla2becad2009-10-21 00:40:46 +00003749 QualType Result = TL.getType();
3750 if (getDerived().AlwaysRebuild() ||
3751 ElementType != T->getElementType()) {
3752 Result = getDerived().RebuildConstantArrayType(ElementType,
3753 T->getSizeModifier(),
3754 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003755 T->getIndexTypeCVRQualifiers(),
3756 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003757 if (Result.isNull())
3758 return QualType();
3759 }
Eli Friedman457a3772012-01-25 22:19:07 +00003760
3761 // We might have either a ConstantArrayType or a VariableArrayType now:
3762 // a ConstantArrayType is allowed to have an element type which is a
3763 // VariableArrayType if the type is dependent. Fortunately, all array
3764 // types have the same location layout.
3765 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003766 NewTL.setLBracketLoc(TL.getLBracketLoc());
3767 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003768
John McCalla2becad2009-10-21 00:40:46 +00003769 Expr *Size = TL.getSizeExpr();
3770 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003771 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3772 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003773 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003774 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003775 }
3776 NewTL.setSizeExpr(Size);
3777
3778 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003779}
Mike Stump1eb44332009-09-09 15:08:12 +00003780
Douglas Gregor577f75a2009-08-04 16:50:30 +00003781template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003782QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003783 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003784 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003785 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003786 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003787 if (ElementType.isNull())
3788 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003789
John McCalla2becad2009-10-21 00:40:46 +00003790 QualType Result = TL.getType();
3791 if (getDerived().AlwaysRebuild() ||
3792 ElementType != T->getElementType()) {
3793 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003794 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003795 T->getIndexTypeCVRQualifiers(),
3796 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003797 if (Result.isNull())
3798 return QualType();
3799 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003800
John McCalla2becad2009-10-21 00:40:46 +00003801 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3802 NewTL.setLBracketLoc(TL.getLBracketLoc());
3803 NewTL.setRBracketLoc(TL.getRBracketLoc());
3804 NewTL.setSizeExpr(0);
3805
3806 return Result;
3807}
3808
3809template<typename Derived>
3810QualType
3811TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003812 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003813 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003814 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3815 if (ElementType.isNull())
3816 return QualType();
3817
John McCall60d7b3a2010-08-24 06:29:42 +00003818 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003819 = getDerived().TransformExpr(T->getSizeExpr());
3820 if (SizeResult.isInvalid())
3821 return QualType();
3822
John McCall9ae2f072010-08-23 23:25:46 +00003823 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003824
3825 QualType Result = TL.getType();
3826 if (getDerived().AlwaysRebuild() ||
3827 ElementType != T->getElementType() ||
3828 Size != T->getSizeExpr()) {
3829 Result = getDerived().RebuildVariableArrayType(ElementType,
3830 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003831 Size,
John McCalla2becad2009-10-21 00:40:46 +00003832 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003833 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003834 if (Result.isNull())
3835 return QualType();
3836 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003837
John McCalla2becad2009-10-21 00:40:46 +00003838 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3839 NewTL.setLBracketLoc(TL.getLBracketLoc());
3840 NewTL.setRBracketLoc(TL.getRBracketLoc());
3841 NewTL.setSizeExpr(Size);
3842
3843 return Result;
3844}
3845
3846template<typename Derived>
3847QualType
3848TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003849 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003850 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003851 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3852 if (ElementType.isNull())
3853 return QualType();
3854
Richard Smithf6702a32011-12-20 02:08:33 +00003855 // Array bounds are constant expressions.
3856 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3857 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003858
John McCall3b657512011-01-19 10:06:00 +00003859 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3860 Expr *origSize = TL.getSizeExpr();
3861 if (!origSize) origSize = T->getSizeExpr();
3862
3863 ExprResult sizeResult
3864 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003865 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003866 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003867 return QualType();
3868
John McCall3b657512011-01-19 10:06:00 +00003869 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003870
3871 QualType Result = TL.getType();
3872 if (getDerived().AlwaysRebuild() ||
3873 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003874 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003875 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3876 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003877 size,
John McCalla2becad2009-10-21 00:40:46 +00003878 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003879 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003880 if (Result.isNull())
3881 return QualType();
3882 }
John McCalla2becad2009-10-21 00:40:46 +00003883
3884 // We might have any sort of array type now, but fortunately they
3885 // all have the same location layout.
3886 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3887 NewTL.setLBracketLoc(TL.getLBracketLoc());
3888 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003889 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003890
3891 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003892}
Mike Stump1eb44332009-09-09 15:08:12 +00003893
3894template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003895QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003896 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003897 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003898 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003899
3900 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003901 QualType ElementType = getDerived().TransformType(T->getElementType());
3902 if (ElementType.isNull())
3903 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003904
Richard Smithf6702a32011-12-20 02:08:33 +00003905 // Vector sizes are constant expressions.
3906 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3907 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003908
John McCall60d7b3a2010-08-24 06:29:42 +00003909 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003910 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003911 if (Size.isInvalid())
3912 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003913
John McCalla2becad2009-10-21 00:40:46 +00003914 QualType Result = TL.getType();
3915 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003916 ElementType != T->getElementType() ||
3917 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003918 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003919 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003920 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003921 if (Result.isNull())
3922 return QualType();
3923 }
John McCalla2becad2009-10-21 00:40:46 +00003924
3925 // Result might be dependent or not.
3926 if (isa<DependentSizedExtVectorType>(Result)) {
3927 DependentSizedExtVectorTypeLoc NewTL
3928 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3929 NewTL.setNameLoc(TL.getNameLoc());
3930 } else {
3931 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3932 NewTL.setNameLoc(TL.getNameLoc());
3933 }
3934
3935 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003936}
Mike Stump1eb44332009-09-09 15:08:12 +00003937
3938template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003939QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003940 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003941 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003942 QualType ElementType = getDerived().TransformType(T->getElementType());
3943 if (ElementType.isNull())
3944 return QualType();
3945
John McCalla2becad2009-10-21 00:40:46 +00003946 QualType Result = TL.getType();
3947 if (getDerived().AlwaysRebuild() ||
3948 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003949 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003950 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003951 if (Result.isNull())
3952 return QualType();
3953 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003954
John McCalla2becad2009-10-21 00:40:46 +00003955 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3956 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003957
John McCalla2becad2009-10-21 00:40:46 +00003958 return Result;
3959}
3960
3961template<typename Derived>
3962QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003963 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003964 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003965 QualType ElementType = getDerived().TransformType(T->getElementType());
3966 if (ElementType.isNull())
3967 return QualType();
3968
3969 QualType Result = TL.getType();
3970 if (getDerived().AlwaysRebuild() ||
3971 ElementType != T->getElementType()) {
3972 Result = getDerived().RebuildExtVectorType(ElementType,
3973 T->getNumElements(),
3974 /*FIXME*/ SourceLocation());
3975 if (Result.isNull())
3976 return QualType();
3977 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003978
John McCalla2becad2009-10-21 00:40:46 +00003979 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3980 NewTL.setNameLoc(TL.getNameLoc());
3981
3982 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003983}
Mike Stump1eb44332009-09-09 15:08:12 +00003984
David Blaikiedc84cd52013-02-20 22:23:23 +00003985template <typename Derived>
3986ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
3987 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
3988 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003989 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003990 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003991
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003992 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003993 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003994 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003995 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00003996 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003997
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003998 TypeLocBuilder TLB;
3999 TypeLoc NewTL = OldDI->getTypeLoc();
4000 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004001
4002 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004003 OldExpansionTL.getPatternLoc());
4004 if (Result.isNull())
4005 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004006
4007 Result = RebuildPackExpansionType(Result,
4008 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004009 OldExpansionTL.getEllipsisLoc(),
4010 NumExpansions);
4011 if (Result.isNull())
4012 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004013
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004014 PackExpansionTypeLoc NewExpansionTL
4015 = TLB.push<PackExpansionTypeLoc>(Result);
4016 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4017 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4018 } else
4019 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004020 if (!NewDI)
4021 return 0;
4022
John McCallfb44de92011-05-01 22:35:37 +00004023 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004024 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004025
4026 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4027 OldParm->getDeclContext(),
4028 OldParm->getInnerLocStart(),
4029 OldParm->getLocation(),
4030 OldParm->getIdentifier(),
4031 NewDI->getType(),
4032 NewDI,
4033 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004034 /* DefArg */ NULL);
4035 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4036 OldParm->getFunctionScopeIndex() + indexAdjustment);
4037 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004038}
4039
4040template<typename Derived>
4041bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004042 TransformFunctionTypeParams(SourceLocation Loc,
4043 ParmVarDecl **Params, unsigned NumParams,
4044 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004045 SmallVectorImpl<QualType> &OutParamTypes,
4046 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004047 int indexAdjustment = 0;
4048
Douglas Gregora009b592011-01-07 00:20:55 +00004049 for (unsigned i = 0; i != NumParams; ++i) {
4050 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004051 assert(OldParm->getFunctionScopeIndex() == i);
4052
David Blaikiedc84cd52013-02-20 22:23:23 +00004053 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004054 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004055 if (OldParm->isParameterPack()) {
4056 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004057 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004058
Douglas Gregor603cfb42011-01-05 23:12:31 +00004059 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004060 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004061 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004062 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4063 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004064 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4065
Douglas Gregor603cfb42011-01-05 23:12:31 +00004066 // Determine whether we should expand the parameter packs.
4067 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004068 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004069 Optional<unsigned> OrigNumExpansions =
4070 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004071 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004072 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4073 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004074 Unexpanded,
4075 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004076 RetainExpansion,
4077 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004078 return true;
4079 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004080
Douglas Gregor603cfb42011-01-05 23:12:31 +00004081 if (ShouldExpand) {
4082 // Expand the function parameter pack into multiple, separate
4083 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004084 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004085 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004086 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004087 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004088 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004089 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004090 OrigNumExpansions,
4091 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004092 if (!NewParm)
4093 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004094
Douglas Gregora009b592011-01-07 00:20:55 +00004095 OutParamTypes.push_back(NewParm->getType());
4096 if (PVars)
4097 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004098 }
Douglas Gregord3731192011-01-10 07:32:04 +00004099
4100 // If we're supposed to retain a pack expansion, do so by temporarily
4101 // forgetting the partially-substituted parameter pack.
4102 if (RetainExpansion) {
4103 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004104 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004105 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004106 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004107 OrigNumExpansions,
4108 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004109 if (!NewParm)
4110 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004111
Douglas Gregord3731192011-01-10 07:32:04 +00004112 OutParamTypes.push_back(NewParm->getType());
4113 if (PVars)
4114 PVars->push_back(NewParm);
4115 }
4116
John McCallfb44de92011-05-01 22:35:37 +00004117 // The next parameter should have the same adjustment as the
4118 // last thing we pushed, but we post-incremented indexAdjustment
4119 // on every push. Also, if we push nothing, the adjustment should
4120 // go down by one.
4121 indexAdjustment--;
4122
Douglas Gregor603cfb42011-01-05 23:12:31 +00004123 // We're done with the pack expansion.
4124 continue;
4125 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004126
4127 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004128 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004129 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4130 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004131 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004132 NumExpansions,
4133 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004134 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004135 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004136 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004137 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004138
John McCall21ef0fa2010-03-11 09:03:00 +00004139 if (!NewParm)
4140 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004141
Douglas Gregora009b592011-01-07 00:20:55 +00004142 OutParamTypes.push_back(NewParm->getType());
4143 if (PVars)
4144 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004145 continue;
4146 }
John McCall21ef0fa2010-03-11 09:03:00 +00004147
4148 // Deal with the possibility that we don't have a parameter
4149 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004150 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004151 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004152 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004153 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004154 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004155 = dyn_cast<PackExpansionType>(OldType)) {
4156 // We have a function parameter pack that may need to be expanded.
4157 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004158 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004159 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004160
Douglas Gregor603cfb42011-01-05 23:12:31 +00004161 // Determine whether we should expand the parameter packs.
4162 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004163 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004164 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004165 Unexpanded,
4166 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004167 RetainExpansion,
4168 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004169 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004170 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004171
Douglas Gregor603cfb42011-01-05 23:12:31 +00004172 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004173 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004174 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004175 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004176 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4177 QualType NewType = getDerived().TransformType(Pattern);
4178 if (NewType.isNull())
4179 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004180
Douglas Gregora009b592011-01-07 00:20:55 +00004181 OutParamTypes.push_back(NewType);
4182 if (PVars)
4183 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004184 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004185
Douglas Gregor603cfb42011-01-05 23:12:31 +00004186 // We're done with the pack expansion.
4187 continue;
4188 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004189
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004190 // If we're supposed to retain a pack expansion, do so by temporarily
4191 // forgetting the partially-substituted parameter pack.
4192 if (RetainExpansion) {
4193 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4194 QualType NewType = getDerived().TransformType(Pattern);
4195 if (NewType.isNull())
4196 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004197
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004198 OutParamTypes.push_back(NewType);
4199 if (PVars)
4200 PVars->push_back(0);
4201 }
Douglas Gregord3731192011-01-10 07:32:04 +00004202
Chad Rosier4a9d7952012-08-08 18:46:20 +00004203 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004204 // expansion.
4205 OldType = Expansion->getPattern();
4206 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004207 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4208 NewType = getDerived().TransformType(OldType);
4209 } else {
4210 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004211 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004212
Douglas Gregor603cfb42011-01-05 23:12:31 +00004213 if (NewType.isNull())
4214 return true;
4215
4216 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004217 NewType = getSema().Context.getPackExpansionType(NewType,
4218 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004219
Douglas Gregora009b592011-01-07 00:20:55 +00004220 OutParamTypes.push_back(NewType);
4221 if (PVars)
4222 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004223 }
4224
John McCallfb44de92011-05-01 22:35:37 +00004225#ifndef NDEBUG
4226 if (PVars) {
4227 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4228 if (ParmVarDecl *parm = (*PVars)[i])
4229 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004230 }
John McCallfb44de92011-05-01 22:35:37 +00004231#endif
4232
4233 return false;
4234}
John McCall21ef0fa2010-03-11 09:03:00 +00004235
4236template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004237QualType
John McCalla2becad2009-10-21 00:40:46 +00004238TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004239 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004240 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4241}
4242
4243template<typename Derived>
4244QualType
4245TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4246 FunctionProtoTypeLoc TL,
4247 CXXRecordDecl *ThisContext,
4248 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004249 // Transform the parameters and return type.
4250 //
Richard Smithe6975e92012-04-17 00:58:00 +00004251 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004252 // When the function has a trailing return type, we instantiate the
4253 // parameters before the return type, since the return type can then refer
4254 // to the parameters themselves (via decltype, sizeof, etc.).
4255 //
Chris Lattner686775d2011-07-20 06:58:45 +00004256 SmallVector<QualType, 4> ParamTypes;
4257 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004258 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004259
Douglas Gregordab60ad2010-10-01 18:44:50 +00004260 QualType ResultType;
4261
Richard Smith9fbf3272012-08-14 22:51:13 +00004262 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004263 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004264 TL.getParmArray(),
4265 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004266 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004267 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004268 return QualType();
4269
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004270 {
4271 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004272 // If a declaration declares a member function or member function
4273 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004274 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004275 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004276 // declarator.
4277 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004278
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004279 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4280 if (ResultType.isNull())
4281 return QualType();
4282 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004283 }
4284 else {
4285 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4286 if (ResultType.isNull())
4287 return QualType();
4288
Chad Rosier4a9d7952012-08-08 18:46:20 +00004289 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004290 TL.getParmArray(),
4291 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004292 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004293 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004294 return QualType();
4295 }
4296
Richard Smithe6975e92012-04-17 00:58:00 +00004297 // FIXME: Need to transform the exception-specification too.
4298
John McCalla2becad2009-10-21 00:40:46 +00004299 QualType Result = TL.getType();
4300 if (getDerived().AlwaysRebuild() ||
4301 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004302 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004303 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004304 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004305 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004306 if (Result.isNull())
4307 return QualType();
4308 }
Mike Stump1eb44332009-09-09 15:08:12 +00004309
John McCalla2becad2009-10-21 00:40:46 +00004310 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004311 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004312 NewTL.setLParenLoc(TL.getLParenLoc());
4313 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004314 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004315 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4316 NewTL.setArg(i, ParamDecls[i]);
4317
4318 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004319}
Mike Stump1eb44332009-09-09 15:08:12 +00004320
Douglas Gregor577f75a2009-08-04 16:50:30 +00004321template<typename Derived>
4322QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004323 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004324 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004325 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004326 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4327 if (ResultType.isNull())
4328 return QualType();
4329
4330 QualType Result = TL.getType();
4331 if (getDerived().AlwaysRebuild() ||
4332 ResultType != T->getResultType())
4333 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4334
4335 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004336 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004337 NewTL.setLParenLoc(TL.getLParenLoc());
4338 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004339 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004340
4341 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004342}
Mike Stump1eb44332009-09-09 15:08:12 +00004343
John McCalled976492009-12-04 22:46:56 +00004344template<typename Derived> QualType
4345TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004346 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004347 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004348 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004349 if (!D)
4350 return QualType();
4351
4352 QualType Result = TL.getType();
4353 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4354 Result = getDerived().RebuildUnresolvedUsingType(D);
4355 if (Result.isNull())
4356 return QualType();
4357 }
4358
4359 // We might get an arbitrary type spec type back. We should at
4360 // least always get a type spec type, though.
4361 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4362 NewTL.setNameLoc(TL.getNameLoc());
4363
4364 return Result;
4365}
4366
Douglas Gregor577f75a2009-08-04 16:50:30 +00004367template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004368QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004369 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004370 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004371 TypedefNameDecl *Typedef
4372 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4373 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004374 if (!Typedef)
4375 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004376
John McCalla2becad2009-10-21 00:40:46 +00004377 QualType Result = TL.getType();
4378 if (getDerived().AlwaysRebuild() ||
4379 Typedef != T->getDecl()) {
4380 Result = getDerived().RebuildTypedefType(Typedef);
4381 if (Result.isNull())
4382 return QualType();
4383 }
Mike Stump1eb44332009-09-09 15:08:12 +00004384
John McCalla2becad2009-10-21 00:40:46 +00004385 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4386 NewTL.setNameLoc(TL.getNameLoc());
4387
4388 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004389}
Mike Stump1eb44332009-09-09 15:08:12 +00004390
Douglas Gregor577f75a2009-08-04 16:50:30 +00004391template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004392QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004393 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004394 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004395 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4396 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004397
John McCall60d7b3a2010-08-24 06:29:42 +00004398 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004399 if (E.isInvalid())
4400 return QualType();
4401
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004402 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4403 if (E.isInvalid())
4404 return QualType();
4405
John McCalla2becad2009-10-21 00:40:46 +00004406 QualType Result = TL.getType();
4407 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004408 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004409 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004410 if (Result.isNull())
4411 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004412 }
John McCalla2becad2009-10-21 00:40:46 +00004413 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004414
John McCalla2becad2009-10-21 00:40:46 +00004415 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004416 NewTL.setTypeofLoc(TL.getTypeofLoc());
4417 NewTL.setLParenLoc(TL.getLParenLoc());
4418 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004419
4420 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004421}
Mike Stump1eb44332009-09-09 15:08:12 +00004422
4423template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004424QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004425 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004426 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4427 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4428 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004429 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004430
John McCalla2becad2009-10-21 00:40:46 +00004431 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004432 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4433 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004434 if (Result.isNull())
4435 return QualType();
4436 }
Mike Stump1eb44332009-09-09 15:08:12 +00004437
John McCalla2becad2009-10-21 00:40:46 +00004438 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004439 NewTL.setTypeofLoc(TL.getTypeofLoc());
4440 NewTL.setLParenLoc(TL.getLParenLoc());
4441 NewTL.setRParenLoc(TL.getRParenLoc());
4442 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004443
4444 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004445}
Mike Stump1eb44332009-09-09 15:08:12 +00004446
4447template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004448QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004449 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004450 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004451
Douglas Gregor670444e2009-08-04 22:27:00 +00004452 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004453 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4454 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004455
John McCall60d7b3a2010-08-24 06:29:42 +00004456 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004457 if (E.isInvalid())
4458 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004459
Richard Smith76f3f692012-02-22 02:04:18 +00004460 E = getSema().ActOnDecltypeExpression(E.take());
4461 if (E.isInvalid())
4462 return QualType();
4463
John McCalla2becad2009-10-21 00:40:46 +00004464 QualType Result = TL.getType();
4465 if (getDerived().AlwaysRebuild() ||
4466 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004467 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004468 if (Result.isNull())
4469 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004470 }
John McCalla2becad2009-10-21 00:40:46 +00004471 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004472
John McCalla2becad2009-10-21 00:40:46 +00004473 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4474 NewTL.setNameLoc(TL.getNameLoc());
4475
4476 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004477}
4478
4479template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004480QualType TreeTransform<Derived>::TransformUnaryTransformType(
4481 TypeLocBuilder &TLB,
4482 UnaryTransformTypeLoc TL) {
4483 QualType Result = TL.getType();
4484 if (Result->isDependentType()) {
4485 const UnaryTransformType *T = TL.getTypePtr();
4486 QualType NewBase =
4487 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4488 Result = getDerived().RebuildUnaryTransformType(NewBase,
4489 T->getUTTKind(),
4490 TL.getKWLoc());
4491 if (Result.isNull())
4492 return QualType();
4493 }
4494
4495 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4496 NewTL.setKWLoc(TL.getKWLoc());
4497 NewTL.setParensRange(TL.getParensRange());
4498 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4499 return Result;
4500}
4501
4502template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004503QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4504 AutoTypeLoc TL) {
4505 const AutoType *T = TL.getTypePtr();
4506 QualType OldDeduced = T->getDeducedType();
4507 QualType NewDeduced;
4508 if (!OldDeduced.isNull()) {
4509 NewDeduced = getDerived().TransformType(OldDeduced);
4510 if (NewDeduced.isNull())
4511 return QualType();
4512 }
4513
4514 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004515 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4516 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004517 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004518 if (Result.isNull())
4519 return QualType();
4520 }
4521
4522 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4523 NewTL.setNameLoc(TL.getNameLoc());
4524
4525 return Result;
4526}
4527
4528template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004529QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004530 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004531 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004532 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004533 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4534 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004535 if (!Record)
4536 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004537
John McCalla2becad2009-10-21 00:40:46 +00004538 QualType Result = TL.getType();
4539 if (getDerived().AlwaysRebuild() ||
4540 Record != T->getDecl()) {
4541 Result = getDerived().RebuildRecordType(Record);
4542 if (Result.isNull())
4543 return QualType();
4544 }
Mike Stump1eb44332009-09-09 15:08:12 +00004545
John McCalla2becad2009-10-21 00:40:46 +00004546 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4547 NewTL.setNameLoc(TL.getNameLoc());
4548
4549 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004550}
Mike Stump1eb44332009-09-09 15:08:12 +00004551
4552template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004553QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004554 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004555 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004556 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004557 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4558 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004559 if (!Enum)
4560 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004561
John McCalla2becad2009-10-21 00:40:46 +00004562 QualType Result = TL.getType();
4563 if (getDerived().AlwaysRebuild() ||
4564 Enum != T->getDecl()) {
4565 Result = getDerived().RebuildEnumType(Enum);
4566 if (Result.isNull())
4567 return QualType();
4568 }
Mike Stump1eb44332009-09-09 15:08:12 +00004569
John McCalla2becad2009-10-21 00:40:46 +00004570 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4571 NewTL.setNameLoc(TL.getNameLoc());
4572
4573 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004574}
John McCall7da24312009-09-05 00:15:47 +00004575
John McCall3cb0ebd2010-03-10 03:28:59 +00004576template<typename Derived>
4577QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4578 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004579 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004580 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4581 TL.getTypePtr()->getDecl());
4582 if (!D) return QualType();
4583
4584 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4585 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4586 return T;
4587}
4588
Douglas Gregor577f75a2009-08-04 16:50:30 +00004589template<typename Derived>
4590QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004591 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004592 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004593 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004594}
4595
Mike Stump1eb44332009-09-09 15:08:12 +00004596template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004597QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004598 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004599 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004600 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004601
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004602 // Substitute into the replacement type, which itself might involve something
4603 // that needs to be transformed. This only tends to occur with default
4604 // template arguments of template template parameters.
4605 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4606 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4607 if (Replacement.isNull())
4608 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004609
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004610 // Always canonicalize the replacement type.
4611 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4612 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004613 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004614 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004615
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004616 // Propagate type-source information.
4617 SubstTemplateTypeParmTypeLoc NewTL
4618 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4619 NewTL.setNameLoc(TL.getNameLoc());
4620 return Result;
4621
John McCall49a832b2009-10-18 09:09:24 +00004622}
4623
4624template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004625QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4626 TypeLocBuilder &TLB,
4627 SubstTemplateTypeParmPackTypeLoc TL) {
4628 return TransformTypeSpecType(TLB, TL);
4629}
4630
4631template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004632QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004633 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004634 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004635 const TemplateSpecializationType *T = TL.getTypePtr();
4636
Douglas Gregor1d752d72011-03-02 18:46:51 +00004637 // The nested-name-specifier never matters in a TemplateSpecializationType,
4638 // because we can't have a dependent nested-name-specifier anyway.
4639 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004640 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004641 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4642 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004643 if (Template.isNull())
4644 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004645
John McCall43fed0d2010-11-12 08:19:04 +00004646 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4647}
4648
Eli Friedmanb001de72011-10-06 23:00:33 +00004649template<typename Derived>
4650QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4651 AtomicTypeLoc TL) {
4652 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4653 if (ValueType.isNull())
4654 return QualType();
4655
4656 QualType Result = TL.getType();
4657 if (getDerived().AlwaysRebuild() ||
4658 ValueType != TL.getValueLoc().getType()) {
4659 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4660 if (Result.isNull())
4661 return QualType();
4662 }
4663
4664 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4665 NewTL.setKWLoc(TL.getKWLoc());
4666 NewTL.setLParenLoc(TL.getLParenLoc());
4667 NewTL.setRParenLoc(TL.getRParenLoc());
4668
4669 return Result;
4670}
4671
Chad Rosier4a9d7952012-08-08 18:46:20 +00004672 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004673 /// container that provides a \c getArgLoc() member function.
4674 ///
4675 /// This iterator is intended to be used with the iterator form of
4676 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4677 template<typename ArgLocContainer>
4678 class TemplateArgumentLocContainerIterator {
4679 ArgLocContainer *Container;
4680 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004681
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004682 public:
4683 typedef TemplateArgumentLoc value_type;
4684 typedef TemplateArgumentLoc reference;
4685 typedef int difference_type;
4686 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004687
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004688 class pointer {
4689 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004690
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004691 public:
4692 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004693
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004694 const TemplateArgumentLoc *operator->() const {
4695 return &Arg;
4696 }
4697 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004698
4699
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004700 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004701
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004702 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4703 unsigned Index)
4704 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004705
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004706 TemplateArgumentLocContainerIterator &operator++() {
4707 ++Index;
4708 return *this;
4709 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004710
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004711 TemplateArgumentLocContainerIterator operator++(int) {
4712 TemplateArgumentLocContainerIterator Old(*this);
4713 ++(*this);
4714 return Old;
4715 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004716
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004717 TemplateArgumentLoc operator*() const {
4718 return Container->getArgLoc(Index);
4719 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004720
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004721 pointer operator->() const {
4722 return pointer(Container->getArgLoc(Index));
4723 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004724
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004725 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004726 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004727 return X.Container == Y.Container && X.Index == Y.Index;
4728 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004729
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004730 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004731 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004732 return !(X == Y);
4733 }
4734 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004735
4736
John McCall43fed0d2010-11-12 08:19:04 +00004737template <typename Derived>
4738QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4739 TypeLocBuilder &TLB,
4740 TemplateSpecializationTypeLoc TL,
4741 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004742 TemplateArgumentListInfo NewTemplateArgs;
4743 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4744 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004745 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4746 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004747 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004748 ArgIterator(TL, TL.getNumArgs()),
4749 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004750 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004751
John McCall833ca992009-10-29 08:12:44 +00004752 // FIXME: maybe don't rebuild if all the template arguments are the same.
4753
4754 QualType Result =
4755 getDerived().RebuildTemplateSpecializationType(Template,
4756 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004757 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004758
4759 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004760 // Specializations of template template parameters are represented as
4761 // TemplateSpecializationTypes, and substitution of type alias templates
4762 // within a dependent context can transform them into
4763 // DependentTemplateSpecializationTypes.
4764 if (isa<DependentTemplateSpecializationType>(Result)) {
4765 DependentTemplateSpecializationTypeLoc NewTL
4766 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004767 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004768 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004769 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004770 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004771 NewTL.setLAngleLoc(TL.getLAngleLoc());
4772 NewTL.setRAngleLoc(TL.getRAngleLoc());
4773 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4774 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4775 return Result;
4776 }
4777
John McCall833ca992009-10-29 08:12:44 +00004778 TemplateSpecializationTypeLoc NewTL
4779 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004780 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004781 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4782 NewTL.setLAngleLoc(TL.getLAngleLoc());
4783 NewTL.setRAngleLoc(TL.getRAngleLoc());
4784 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4785 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004786 }
Mike Stump1eb44332009-09-09 15:08:12 +00004787
John McCall833ca992009-10-29 08:12:44 +00004788 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004789}
Mike Stump1eb44332009-09-09 15:08:12 +00004790
Douglas Gregora88f09f2011-02-28 17:23:35 +00004791template <typename Derived>
4792QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4793 TypeLocBuilder &TLB,
4794 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004795 TemplateName Template,
4796 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004797 TemplateArgumentListInfo NewTemplateArgs;
4798 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4799 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4800 typedef TemplateArgumentLocContainerIterator<
4801 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004802 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004803 ArgIterator(TL, TL.getNumArgs()),
4804 NewTemplateArgs))
4805 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004806
Douglas Gregora88f09f2011-02-28 17:23:35 +00004807 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004808
Douglas Gregora88f09f2011-02-28 17:23:35 +00004809 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4810 QualType Result
4811 = getSema().Context.getDependentTemplateSpecializationType(
4812 TL.getTypePtr()->getKeyword(),
4813 DTN->getQualifier(),
4814 DTN->getIdentifier(),
4815 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004816
Douglas Gregora88f09f2011-02-28 17:23:35 +00004817 DependentTemplateSpecializationTypeLoc NewTL
4818 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004819 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004820 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004821 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004822 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004823 NewTL.setLAngleLoc(TL.getLAngleLoc());
4824 NewTL.setRAngleLoc(TL.getRAngleLoc());
4825 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4826 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4827 return Result;
4828 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004829
4830 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004831 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004832 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004833 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004834
Douglas Gregora88f09f2011-02-28 17:23:35 +00004835 if (!Result.isNull()) {
4836 /// FIXME: Wrap this in an elaborated-type-specifier?
4837 TemplateSpecializationTypeLoc NewTL
4838 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004839 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004840 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004841 NewTL.setLAngleLoc(TL.getLAngleLoc());
4842 NewTL.setRAngleLoc(TL.getRAngleLoc());
4843 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4844 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4845 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004846
Douglas Gregora88f09f2011-02-28 17:23:35 +00004847 return Result;
4848}
4849
Mike Stump1eb44332009-09-09 15:08:12 +00004850template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004851QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004852TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004853 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004854 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004855
Douglas Gregor9e876872011-03-01 18:12:44 +00004856 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004857 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004858 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004859 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004860 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4861 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004862 return QualType();
4863 }
Mike Stump1eb44332009-09-09 15:08:12 +00004864
John McCall43fed0d2010-11-12 08:19:04 +00004865 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4866 if (NamedT.isNull())
4867 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004868
Richard Smith3e4c6c42011-05-05 21:57:07 +00004869 // C++0x [dcl.type.elab]p2:
4870 // If the identifier resolves to a typedef-name or the simple-template-id
4871 // resolves to an alias template specialization, the
4872 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004873 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4874 if (const TemplateSpecializationType *TST =
4875 NamedT->getAs<TemplateSpecializationType>()) {
4876 TemplateName Template = TST->getTemplateName();
4877 if (TypeAliasTemplateDecl *TAT =
4878 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4879 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4880 diag::err_tag_reference_non_tag) << 4;
4881 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4882 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004883 }
4884 }
4885
John McCalla2becad2009-10-21 00:40:46 +00004886 QualType Result = TL.getType();
4887 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004888 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004889 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004890 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004891 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004892 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004893 if (Result.isNull())
4894 return QualType();
4895 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004896
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004897 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004898 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004899 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004900 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004901}
Mike Stump1eb44332009-09-09 15:08:12 +00004902
4903template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004904QualType TreeTransform<Derived>::TransformAttributedType(
4905 TypeLocBuilder &TLB,
4906 AttributedTypeLoc TL) {
4907 const AttributedType *oldType = TL.getTypePtr();
4908 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4909 if (modifiedType.isNull())
4910 return QualType();
4911
4912 QualType result = TL.getType();
4913
4914 // FIXME: dependent operand expressions?
4915 if (getDerived().AlwaysRebuild() ||
4916 modifiedType != oldType->getModifiedType()) {
4917 // TODO: this is really lame; we should really be rebuilding the
4918 // equivalent type from first principles.
4919 QualType equivalentType
4920 = getDerived().TransformType(oldType->getEquivalentType());
4921 if (equivalentType.isNull())
4922 return QualType();
4923 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4924 modifiedType,
4925 equivalentType);
4926 }
4927
4928 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4929 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4930 if (TL.hasAttrOperand())
4931 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4932 if (TL.hasAttrExprOperand())
4933 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4934 else if (TL.hasAttrEnumOperand())
4935 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4936
4937 return result;
4938}
4939
4940template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004941QualType
4942TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4943 ParenTypeLoc TL) {
4944 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4945 if (Inner.isNull())
4946 return QualType();
4947
4948 QualType Result = TL.getType();
4949 if (getDerived().AlwaysRebuild() ||
4950 Inner != TL.getInnerLoc().getType()) {
4951 Result = getDerived().RebuildParenType(Inner);
4952 if (Result.isNull())
4953 return QualType();
4954 }
4955
4956 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4957 NewTL.setLParenLoc(TL.getLParenLoc());
4958 NewTL.setRParenLoc(TL.getRParenLoc());
4959 return Result;
4960}
4961
4962template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004963QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004964 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004965 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004966
Douglas Gregor2494dd02011-03-01 01:34:45 +00004967 NestedNameSpecifierLoc QualifierLoc
4968 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4969 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004970 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004971
John McCall33500952010-06-11 00:33:02 +00004972 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004973 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004974 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004975 QualifierLoc,
4976 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004977 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004978 if (Result.isNull())
4979 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004980
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004981 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4982 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004983 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4984
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004985 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004986 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004987 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004988 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004989 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004990 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004991 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004992 NewTL.setNameLoc(TL.getNameLoc());
4993 }
John McCalla2becad2009-10-21 00:40:46 +00004994 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004995}
Mike Stump1eb44332009-09-09 15:08:12 +00004996
Douglas Gregor577f75a2009-08-04 16:50:30 +00004997template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004998QualType TreeTransform<Derived>::
4999 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005000 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005001 NestedNameSpecifierLoc QualifierLoc;
5002 if (TL.getQualifierLoc()) {
5003 QualifierLoc
5004 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5005 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00005006 return QualType();
5007 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005008
John McCall43fed0d2010-11-12 08:19:04 +00005009 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005010 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005011}
5012
5013template<typename Derived>
5014QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005015TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5016 DependentTemplateSpecializationTypeLoc TL,
5017 NestedNameSpecifierLoc QualifierLoc) {
5018 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005019
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005020 TemplateArgumentListInfo NewTemplateArgs;
5021 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5022 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005023
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005024 typedef TemplateArgumentLocContainerIterator<
5025 DependentTemplateSpecializationTypeLoc> ArgIterator;
5026 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5027 ArgIterator(TL, TL.getNumArgs()),
5028 NewTemplateArgs))
5029 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005030
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005031 QualType Result
5032 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5033 QualifierLoc,
5034 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005035 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005036 NewTemplateArgs);
5037 if (Result.isNull())
5038 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005039
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005040 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5041 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005042
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005043 // Copy information relevant to the template specialization.
5044 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005045 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005046 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005047 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005048 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5049 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005050 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005051 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005052
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005053 // Copy information relevant to the elaborated type.
5054 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005055 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005056 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005057 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5058 DependentTemplateSpecializationTypeLoc SpecTL
5059 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005060 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005061 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005062 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005063 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005064 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5065 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005066 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005067 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005068 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005069 TemplateSpecializationTypeLoc SpecTL
5070 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005071 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005072 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005073 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5074 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005075 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005076 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005077 }
5078 return Result;
5079}
5080
5081template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005082QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5083 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005084 QualType Pattern
5085 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005086 if (Pattern.isNull())
5087 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005088
5089 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005090 if (getDerived().AlwaysRebuild() ||
5091 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005092 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005093 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005094 TL.getEllipsisLoc(),
5095 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005096 if (Result.isNull())
5097 return QualType();
5098 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005099
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005100 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5101 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5102 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005103}
5104
5105template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005106QualType
5107TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005108 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005109 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005110 TLB.pushFullCopy(TL);
5111 return TL.getType();
5112}
5113
5114template<typename Derived>
5115QualType
5116TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005117 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005118 // ObjCObjectType is never dependent.
5119 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005120 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005121}
Mike Stump1eb44332009-09-09 15:08:12 +00005122
5123template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005124QualType
5125TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005126 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005127 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005128 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005129 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005130}
5131
Douglas Gregor577f75a2009-08-04 16:50:30 +00005132//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005133// Statement transformation
5134//===----------------------------------------------------------------------===//
5135template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005136StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005137TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005138 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005139}
5140
5141template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005142StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005143TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5144 return getDerived().TransformCompoundStmt(S, false);
5145}
5146
5147template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005148StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005149TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005150 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005151 Sema::CompoundScopeRAII CompoundScope(getSema());
5152
John McCall7114cba2010-08-27 19:56:05 +00005153 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005154 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005155 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005156 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5157 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005158 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005159 if (Result.isInvalid()) {
5160 // Immediately fail if this was a DeclStmt, since it's very
5161 // likely that this will cause problems for future statements.
5162 if (isa<DeclStmt>(*B))
5163 return StmtError();
5164
5165 // Otherwise, just keep processing substatements and fail later.
5166 SubStmtInvalid = true;
5167 continue;
5168 }
Mike Stump1eb44332009-09-09 15:08:12 +00005169
Douglas Gregor43959a92009-08-20 07:17:43 +00005170 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5171 Statements.push_back(Result.takeAs<Stmt>());
5172 }
Mike Stump1eb44332009-09-09 15:08:12 +00005173
John McCall7114cba2010-08-27 19:56:05 +00005174 if (SubStmtInvalid)
5175 return StmtError();
5176
Douglas Gregor43959a92009-08-20 07:17:43 +00005177 if (!getDerived().AlwaysRebuild() &&
5178 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005179 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005180
5181 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005182 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005183 S->getRBracLoc(),
5184 IsStmtExpr);
5185}
Mike Stump1eb44332009-09-09 15:08:12 +00005186
Douglas Gregor43959a92009-08-20 07:17:43 +00005187template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005188StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005189TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005190 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005191 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005192 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5193 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005194
Eli Friedman264c1f82009-11-19 03:14:00 +00005195 // Transform the left-hand case value.
5196 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005197 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005198 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005199 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005200
Eli Friedman264c1f82009-11-19 03:14:00 +00005201 // Transform the right-hand case value (for the GNU case-range extension).
5202 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005203 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005204 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005205 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005206 }
Mike Stump1eb44332009-09-09 15:08:12 +00005207
Douglas Gregor43959a92009-08-20 07:17:43 +00005208 // Build the case statement.
5209 // Case statements are always rebuilt so that they will attached to their
5210 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005211 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005212 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005213 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005214 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005215 S->getColonLoc());
5216 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005217 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005218
Douglas Gregor43959a92009-08-20 07:17:43 +00005219 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005220 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005221 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005222 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005223
Douglas Gregor43959a92009-08-20 07:17:43 +00005224 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005225 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005226}
5227
5228template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005229StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005230TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005231 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005232 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005233 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005234 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005235
Douglas Gregor43959a92009-08-20 07:17:43 +00005236 // Default statements are always rebuilt
5237 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005238 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005239}
Mike Stump1eb44332009-09-09 15:08:12 +00005240
Douglas Gregor43959a92009-08-20 07:17:43 +00005241template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005242StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005243TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005244 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005245 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005246 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005247
Chris Lattner57ad3782011-02-17 20:34:02 +00005248 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5249 S->getDecl());
5250 if (!LD)
5251 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005252
5253
Douglas Gregor43959a92009-08-20 07:17:43 +00005254 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005255 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005256 cast<LabelDecl>(LD), SourceLocation(),
5257 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005258}
Mike Stump1eb44332009-09-09 15:08:12 +00005259
Douglas Gregor43959a92009-08-20 07:17:43 +00005260template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005261StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005262TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5263 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5264 if (SubStmt.isInvalid())
5265 return StmtError();
5266
5267 // TODO: transform attributes
5268 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5269 return S;
5270
5271 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5272 S->getAttrs(),
5273 SubStmt.get());
5274}
5275
5276template<typename Derived>
5277StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005278TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005279 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005280 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005281 VarDecl *ConditionVar = 0;
5282 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005283 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005284 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005285 getDerived().TransformDefinition(
5286 S->getConditionVariable()->getLocation(),
5287 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005288 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005289 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005290 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005291 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005292
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005293 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005294 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005295
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005296 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005297 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005298 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005299 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005300 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005301 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005302
John McCall9ae2f072010-08-23 23:25:46 +00005303 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005304 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005305 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005306
John McCall9ae2f072010-08-23 23:25:46 +00005307 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5308 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005309 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005310
Douglas Gregor43959a92009-08-20 07:17:43 +00005311 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005312 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005313 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005314 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005315
Douglas Gregor43959a92009-08-20 07:17:43 +00005316 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005317 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005318 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005319 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005320
Douglas Gregor43959a92009-08-20 07:17:43 +00005321 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005322 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005323 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005324 Then.get() == S->getThen() &&
5325 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005326 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005327
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005328 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005329 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005330 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005331}
5332
5333template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005334StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005335TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005336 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005337 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005338 VarDecl *ConditionVar = 0;
5339 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005340 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005341 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005342 getDerived().TransformDefinition(
5343 S->getConditionVariable()->getLocation(),
5344 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005345 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005346 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005347 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005348 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005349
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005350 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005351 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005352 }
Mike Stump1eb44332009-09-09 15:08:12 +00005353
Douglas Gregor43959a92009-08-20 07:17:43 +00005354 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005355 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005356 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005357 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005358 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005359 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005360
Douglas Gregor43959a92009-08-20 07:17:43 +00005361 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005362 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005363 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005364 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005365
Douglas Gregor43959a92009-08-20 07:17:43 +00005366 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005367 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5368 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005369}
Mike Stump1eb44332009-09-09 15:08:12 +00005370
Douglas Gregor43959a92009-08-20 07:17:43 +00005371template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005372StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005373TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005374 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005375 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005376 VarDecl *ConditionVar = 0;
5377 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005378 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005379 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005380 getDerived().TransformDefinition(
5381 S->getConditionVariable()->getLocation(),
5382 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005383 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005384 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005385 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005386 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005387
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005388 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005389 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005390
5391 if (S->getCond()) {
5392 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005393 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005394 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005395 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005396 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005397 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005398 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005399 }
Mike Stump1eb44332009-09-09 15:08:12 +00005400
John McCall9ae2f072010-08-23 23:25:46 +00005401 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5402 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005403 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005404
Douglas Gregor43959a92009-08-20 07:17:43 +00005405 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005406 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005407 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005408 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005409
Douglas Gregor43959a92009-08-20 07:17:43 +00005410 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005411 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005412 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005413 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005414 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005415
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005416 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005417 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005418}
Mike Stump1eb44332009-09-09 15:08:12 +00005419
Douglas Gregor43959a92009-08-20 07:17:43 +00005420template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005421StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005422TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005423 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005424 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005425 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005426 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005427
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005428 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005429 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005430 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005431 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005432
Douglas Gregor43959a92009-08-20 07:17:43 +00005433 if (!getDerived().AlwaysRebuild() &&
5434 Cond.get() == S->getCond() &&
5435 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005436 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005437
John McCall9ae2f072010-08-23 23:25:46 +00005438 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5439 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005440 S->getRParenLoc());
5441}
Mike Stump1eb44332009-09-09 15:08:12 +00005442
Douglas Gregor43959a92009-08-20 07:17:43 +00005443template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005444StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005445TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005446 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005447 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005448 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005449 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005450
Douglas Gregor43959a92009-08-20 07:17:43 +00005451 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005452 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005453 VarDecl *ConditionVar = 0;
5454 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005455 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005456 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005457 getDerived().TransformDefinition(
5458 S->getConditionVariable()->getLocation(),
5459 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005460 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005461 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005462 } else {
5463 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005464
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005465 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005466 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005467
5468 if (S->getCond()) {
5469 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005470 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005471 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005472 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005473 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005474
John McCall9ae2f072010-08-23 23:25:46 +00005475 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005476 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005477 }
Mike Stump1eb44332009-09-09 15:08:12 +00005478
Chad Rosier4a9d7952012-08-08 18:46:20 +00005479 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005480 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005481 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005482
Douglas Gregor43959a92009-08-20 07:17:43 +00005483 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005484 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005485 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005486 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005487
Richard Smith41956372013-01-14 22:39:08 +00005488 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005489 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005490 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005491
Douglas Gregor43959a92009-08-20 07:17:43 +00005492 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005493 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005494 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005495 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005496
Douglas Gregor43959a92009-08-20 07:17:43 +00005497 if (!getDerived().AlwaysRebuild() &&
5498 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005499 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005500 Inc.get() == S->getInc() &&
5501 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005502 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005503
Douglas Gregor43959a92009-08-20 07:17:43 +00005504 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005505 Init.get(), FullCond, ConditionVar,
5506 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005507}
5508
5509template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005510StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005511TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005512 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5513 S->getLabel());
5514 if (!LD)
5515 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005516
Douglas Gregor43959a92009-08-20 07:17:43 +00005517 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005518 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005519 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005520}
5521
5522template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005523StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005524TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005525 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005526 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005527 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005528 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005529
Douglas Gregor43959a92009-08-20 07:17:43 +00005530 if (!getDerived().AlwaysRebuild() &&
5531 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005532 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005533
5534 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005535 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005536}
5537
5538template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005539StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005540TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *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>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005547 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005548}
Mike Stump1eb44332009-09-09 15:08:12 +00005549
Douglas Gregor43959a92009-08-20 07:17:43 +00005550template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005551StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005552TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005553 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005554 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005555 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005556
Mike Stump1eb44332009-09-09 15:08:12 +00005557 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005558 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005559 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005560}
Mike Stump1eb44332009-09-09 15:08:12 +00005561
Douglas Gregor43959a92009-08-20 07:17:43 +00005562template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005563StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005564TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005565 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005566 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005567 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5568 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005569 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5570 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005571 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005572 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005573
Douglas Gregor43959a92009-08-20 07:17:43 +00005574 if (Transformed != *D)
5575 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005576
Douglas Gregor43959a92009-08-20 07:17:43 +00005577 Decls.push_back(Transformed);
5578 }
Mike Stump1eb44332009-09-09 15:08:12 +00005579
Douglas Gregor43959a92009-08-20 07:17:43 +00005580 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005581 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005582
5583 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005584 S->getStartLoc(), S->getEndLoc());
5585}
Mike Stump1eb44332009-09-09 15:08:12 +00005586
Douglas Gregor43959a92009-08-20 07:17:43 +00005587template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005588StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005589TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005590
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005591 SmallVector<Expr*, 8> Constraints;
5592 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005593 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005594
John McCall60d7b3a2010-08-24 06:29:42 +00005595 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005596 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005597
5598 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005599
Anders Carlsson703e3942010-01-24 05:50:09 +00005600 // Go through the outputs.
5601 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005602 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005603
Anders Carlsson703e3942010-01-24 05:50:09 +00005604 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005605 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005606
Anders Carlsson703e3942010-01-24 05:50:09 +00005607 // Transform the output expr.
5608 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005609 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005610 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005611 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005612
Anders Carlsson703e3942010-01-24 05:50:09 +00005613 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005614
John McCall9ae2f072010-08-23 23:25:46 +00005615 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005616 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005617
Anders Carlsson703e3942010-01-24 05:50:09 +00005618 // Go through the inputs.
5619 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005620 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005621
Anders Carlsson703e3942010-01-24 05:50:09 +00005622 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005623 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005624
Anders Carlsson703e3942010-01-24 05:50:09 +00005625 // Transform the input expr.
5626 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005627 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005628 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005629 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005630
Anders Carlsson703e3942010-01-24 05:50:09 +00005631 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005632
John McCall9ae2f072010-08-23 23:25:46 +00005633 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005634 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005635
Anders Carlsson703e3942010-01-24 05:50:09 +00005636 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005637 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005638
5639 // Go through the clobbers.
5640 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005641 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005642
5643 // No need to transform the asm string literal.
5644 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005645 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5646 S->isVolatile(), S->getNumOutputs(),
5647 S->getNumInputs(), Names.data(),
5648 Constraints, Exprs, AsmString.get(),
5649 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005650}
5651
Chad Rosier8cd64b42012-06-11 20:47:18 +00005652template<typename Derived>
5653StmtResult
5654TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005655 ArrayRef<Token> AsmToks =
5656 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005657
John McCallaeeacf72013-05-03 00:10:13 +00005658 bool HadError = false, HadChange = false;
5659
5660 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5661 SmallVector<Expr*, 8> TransformedExprs;
5662 TransformedExprs.reserve(SrcExprs.size());
5663 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5664 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5665 if (!Result.isUsable()) {
5666 HadError = true;
5667 } else {
5668 HadChange |= (Result.get() != SrcExprs[i]);
5669 TransformedExprs.push_back(Result.take());
5670 }
5671 }
5672
5673 if (HadError) return StmtError();
5674 if (!HadChange && !getDerived().AlwaysRebuild())
5675 return Owned(S);
5676
Chad Rosier7bd092b2012-08-15 16:53:30 +00005677 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallaeeacf72013-05-03 00:10:13 +00005678 AsmToks, S->getAsmString(),
5679 S->getNumOutputs(), S->getNumInputs(),
5680 S->getAllConstraints(), S->getClobbers(),
5681 TransformedExprs, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005682}
Douglas Gregor43959a92009-08-20 07:17:43 +00005683
5684template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005685StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005686TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005687 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005688 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005689 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005690 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005691
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005692 // Transform the @catch statements (if present).
5693 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005694 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005695 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005696 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005697 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005698 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005699 if (Catch.get() != S->getCatchStmt(I))
5700 AnyCatchChanged = true;
5701 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005702 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005703
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005704 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005705 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005706 if (S->getFinallyStmt()) {
5707 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5708 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005709 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005710 }
5711
5712 // If nothing changed, just retain this statement.
5713 if (!getDerived().AlwaysRebuild() &&
5714 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005715 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005716 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005717 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005718
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005719 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005720 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005721 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005722}
Mike Stump1eb44332009-09-09 15:08:12 +00005723
Douglas Gregor43959a92009-08-20 07:17:43 +00005724template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005725StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005726TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005727 // Transform the @catch parameter, if there is one.
5728 VarDecl *Var = 0;
5729 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5730 TypeSourceInfo *TSInfo = 0;
5731 if (FromVar->getTypeSourceInfo()) {
5732 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5733 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005734 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005735 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005736
Douglas Gregorbe270a02010-04-26 17:57:08 +00005737 QualType T;
5738 if (TSInfo)
5739 T = TSInfo->getType();
5740 else {
5741 T = getDerived().TransformType(FromVar->getType());
5742 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005743 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005744 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005745
Douglas Gregorbe270a02010-04-26 17:57:08 +00005746 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5747 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005748 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005749 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005750
John McCall60d7b3a2010-08-24 06:29:42 +00005751 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005752 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005753 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005754
5755 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005756 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005757 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005758}
Mike Stump1eb44332009-09-09 15:08:12 +00005759
Douglas Gregor43959a92009-08-20 07:17:43 +00005760template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005761StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005762TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005763 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005764 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005765 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005766 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005767
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005768 // If nothing changed, just retain this statement.
5769 if (!getDerived().AlwaysRebuild() &&
5770 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005771 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005772
5773 // Build a new statement.
5774 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005775 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005776}
Mike Stump1eb44332009-09-09 15:08:12 +00005777
Douglas Gregor43959a92009-08-20 07:17:43 +00005778template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005779StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005780TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005781 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005782 if (S->getThrowExpr()) {
5783 Operand = getDerived().TransformExpr(S->getThrowExpr());
5784 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005785 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005786 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005787
Douglas Gregord1377b22010-04-22 21:44:01 +00005788 if (!getDerived().AlwaysRebuild() &&
5789 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005790 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005791
John McCall9ae2f072010-08-23 23:25:46 +00005792 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005793}
Mike Stump1eb44332009-09-09 15:08:12 +00005794
Douglas Gregor43959a92009-08-20 07:17:43 +00005795template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005796StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005797TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005798 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005799 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005800 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005801 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005802 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005803 Object =
5804 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5805 Object.get());
5806 if (Object.isInvalid())
5807 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005808
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005809 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005810 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005811 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005812 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005813
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005814 // If nothing change, just retain the current statement.
5815 if (!getDerived().AlwaysRebuild() &&
5816 Object.get() == S->getSynchExpr() &&
5817 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005818 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005819
5820 // Build a new statement.
5821 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005822 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005823}
5824
5825template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005826StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005827TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5828 ObjCAutoreleasePoolStmt *S) {
5829 // Transform the body.
5830 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5831 if (Body.isInvalid())
5832 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005833
John McCallf85e1932011-06-15 23:02:42 +00005834 // If nothing changed, just retain this statement.
5835 if (!getDerived().AlwaysRebuild() &&
5836 Body.get() == S->getSubStmt())
5837 return SemaRef.Owned(S);
5838
5839 // Build a new statement.
5840 return getDerived().RebuildObjCAutoreleasePoolStmt(
5841 S->getAtLoc(), Body.get());
5842}
5843
5844template<typename Derived>
5845StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005846TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005847 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005848 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005849 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005850 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005851 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005852
Douglas Gregorc3203e72010-04-22 23:10:45 +00005853 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005854 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005855 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005856 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005857
Douglas Gregorc3203e72010-04-22 23:10:45 +00005858 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005859 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005860 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005861 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005862
Douglas Gregorc3203e72010-04-22 23:10:45 +00005863 // If nothing changed, just retain this statement.
5864 if (!getDerived().AlwaysRebuild() &&
5865 Element.get() == S->getElement() &&
5866 Collection.get() == S->getCollection() &&
5867 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005868 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005869
Douglas Gregorc3203e72010-04-22 23:10:45 +00005870 // Build a new statement.
5871 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005872 Element.get(),
5873 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005874 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005875 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005876}
5877
5878
5879template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005880StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005881TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5882 // Transform the exception declaration, if any.
5883 VarDecl *Var = 0;
5884 if (S->getExceptionDecl()) {
5885 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005886 TypeSourceInfo *T = getDerived().TransformType(
5887 ExceptionDecl->getTypeSourceInfo());
5888 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005889 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005890
Douglas Gregor83cb9422010-09-09 17:09:21 +00005891 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005892 ExceptionDecl->getInnerLocStart(),
5893 ExceptionDecl->getLocation(),
5894 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005895 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005896 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005897 }
Mike Stump1eb44332009-09-09 15:08:12 +00005898
Douglas Gregor43959a92009-08-20 07:17:43 +00005899 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005900 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005901 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 if (!getDerived().AlwaysRebuild() &&
5905 !Var &&
5906 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005907 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005908
5909 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5910 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005911 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005912}
Mike Stump1eb44332009-09-09 15:08:12 +00005913
Douglas Gregor43959a92009-08-20 07:17:43 +00005914template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005915StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005916TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5917 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005918 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005919 = getDerived().TransformCompoundStmt(S->getTryBlock());
5920 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005921 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005922
Douglas Gregor43959a92009-08-20 07:17:43 +00005923 // Transform the handlers.
5924 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005925 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005926 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005927 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005928 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5929 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005930 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005931
Douglas Gregor43959a92009-08-20 07:17:43 +00005932 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5933 Handlers.push_back(Handler.takeAs<Stmt>());
5934 }
Mike Stump1eb44332009-09-09 15:08:12 +00005935
Douglas Gregor43959a92009-08-20 07:17:43 +00005936 if (!getDerived().AlwaysRebuild() &&
5937 TryBlock.get() == S->getTryBlock() &&
5938 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005939 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005940
John McCall9ae2f072010-08-23 23:25:46 +00005941 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005942 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005943}
Mike Stump1eb44332009-09-09 15:08:12 +00005944
Richard Smithad762fc2011-04-14 22:09:26 +00005945template<typename Derived>
5946StmtResult
5947TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5948 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5949 if (Range.isInvalid())
5950 return StmtError();
5951
5952 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5953 if (BeginEnd.isInvalid())
5954 return StmtError();
5955
5956 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5957 if (Cond.isInvalid())
5958 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005959 if (Cond.get())
5960 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5961 if (Cond.isInvalid())
5962 return StmtError();
5963 if (Cond.get())
5964 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005965
5966 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5967 if (Inc.isInvalid())
5968 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005969 if (Inc.get())
5970 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005971
5972 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5973 if (LoopVar.isInvalid())
5974 return StmtError();
5975
5976 StmtResult NewStmt = S;
5977 if (getDerived().AlwaysRebuild() ||
5978 Range.get() != S->getRangeStmt() ||
5979 BeginEnd.get() != S->getBeginEndStmt() ||
5980 Cond.get() != S->getCond() ||
5981 Inc.get() != S->getInc() ||
Douglas Gregor39b60dc2013-05-02 18:35:56 +00005982 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smithad762fc2011-04-14 22:09:26 +00005983 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5984 S->getColonLoc(), Range.get(),
5985 BeginEnd.get(), Cond.get(),
5986 Inc.get(), LoopVar.get(),
5987 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00005988 if (NewStmt.isInvalid())
5989 return StmtError();
5990 }
Richard Smithad762fc2011-04-14 22:09:26 +00005991
5992 StmtResult Body = getDerived().TransformStmt(S->getBody());
5993 if (Body.isInvalid())
5994 return StmtError();
5995
5996 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5997 // it now so we have a new statement to attach the body to.
Douglas Gregor39b60dc2013-05-02 18:35:56 +00005998 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smithad762fc2011-04-14 22:09:26 +00005999 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6000 S->getColonLoc(), Range.get(),
6001 BeginEnd.get(), Cond.get(),
6002 Inc.get(), LoopVar.get(),
6003 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006004 if (NewStmt.isInvalid())
6005 return StmtError();
6006 }
Richard Smithad762fc2011-04-14 22:09:26 +00006007
6008 if (NewStmt.get() == S)
6009 return SemaRef.Owned(S);
6010
6011 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6012}
6013
John Wiegley28bbe4b2011-04-28 01:08:34 +00006014template<typename Derived>
6015StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00006016TreeTransform<Derived>::TransformMSDependentExistsStmt(
6017 MSDependentExistsStmt *S) {
6018 // Transform the nested-name-specifier, if any.
6019 NestedNameSpecifierLoc QualifierLoc;
6020 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006021 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00006022 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6023 if (!QualifierLoc)
6024 return StmtError();
6025 }
6026
6027 // Transform the declaration name.
6028 DeclarationNameInfo NameInfo = S->getNameInfo();
6029 if (NameInfo.getName()) {
6030 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6031 if (!NameInfo.getName())
6032 return StmtError();
6033 }
6034
6035 // Check whether anything changed.
6036 if (!getDerived().AlwaysRebuild() &&
6037 QualifierLoc == S->getQualifierLoc() &&
6038 NameInfo.getName() == S->getNameInfo().getName())
6039 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006040
Douglas Gregorba0513d2011-10-25 01:33:02 +00006041 // Determine whether this name exists, if we can.
6042 CXXScopeSpec SS;
6043 SS.Adopt(QualifierLoc);
6044 bool Dependent = false;
6045 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6046 case Sema::IER_Exists:
6047 if (S->isIfExists())
6048 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006049
Douglas Gregorba0513d2011-10-25 01:33:02 +00006050 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6051
6052 case Sema::IER_DoesNotExist:
6053 if (S->isIfNotExists())
6054 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006055
Douglas Gregorba0513d2011-10-25 01:33:02 +00006056 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006057
Douglas Gregorba0513d2011-10-25 01:33:02 +00006058 case Sema::IER_Dependent:
6059 Dependent = true;
6060 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006061
Douglas Gregor65019ac2011-10-25 03:44:56 +00006062 case Sema::IER_Error:
6063 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006064 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006065
Douglas Gregorba0513d2011-10-25 01:33:02 +00006066 // We need to continue with the instantiation, so do so now.
6067 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6068 if (SubStmt.isInvalid())
6069 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006070
Douglas Gregorba0513d2011-10-25 01:33:02 +00006071 // If we have resolved the name, just transform to the substatement.
6072 if (!Dependent)
6073 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006074
Douglas Gregorba0513d2011-10-25 01:33:02 +00006075 // The name is still dependent, so build a dependent expression again.
6076 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6077 S->isIfExists(),
6078 QualifierLoc,
6079 NameInfo,
6080 SubStmt.get());
6081}
6082
6083template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006084ExprResult
6085TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6086 NestedNameSpecifierLoc QualifierLoc;
6087 if (E->getQualifierLoc()) {
6088 QualifierLoc
6089 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6090 if (!QualifierLoc)
6091 return ExprError();
6092 }
6093
6094 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6095 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6096 if (!PD)
6097 return ExprError();
6098
6099 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6100 if (Base.isInvalid())
6101 return ExprError();
6102
6103 return new (SemaRef.getASTContext())
6104 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6105 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6106 QualifierLoc, E->getMemberLoc());
6107}
6108
6109template<typename Derived>
Douglas Gregorba0513d2011-10-25 01:33:02 +00006110StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006111TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6112 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6113 if(TryBlock.isInvalid()) return StmtError();
6114
6115 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6116 if(!getDerived().AlwaysRebuild() &&
6117 TryBlock.get() == S->getTryBlock() &&
6118 Handler.get() == S->getHandler())
6119 return SemaRef.Owned(S);
6120
6121 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6122 S->getTryLoc(),
6123 TryBlock.take(),
6124 Handler.take());
6125}
6126
6127template<typename Derived>
6128StmtResult
6129TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6130 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6131 if(Block.isInvalid()) return StmtError();
6132
6133 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6134 Block.take());
6135}
6136
6137template<typename Derived>
6138StmtResult
6139TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6140 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6141 if(FilterExpr.isInvalid()) return StmtError();
6142
6143 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6144 if(Block.isInvalid()) return StmtError();
6145
6146 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6147 FilterExpr.take(),
6148 Block.take());
6149}
6150
6151template<typename Derived>
6152StmtResult
6153TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6154 if(isa<SEHFinallyStmt>(Handler))
6155 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6156 else
6157 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6158}
6159
Douglas Gregor43959a92009-08-20 07:17:43 +00006160//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006161// Expression transformation
6162//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006163template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006164ExprResult
John McCall454feb92009-12-08 09:21:05 +00006165TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006166 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006167}
Mike Stump1eb44332009-09-09 15:08:12 +00006168
6169template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006170ExprResult
John McCall454feb92009-12-08 09:21:05 +00006171TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006172 NestedNameSpecifierLoc QualifierLoc;
6173 if (E->getQualifierLoc()) {
6174 QualifierLoc
6175 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6176 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006177 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006178 }
John McCalldbd872f2009-12-08 09:08:17 +00006179
6180 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006181 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6182 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006183 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006184 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006185
John McCallec8045d2010-08-17 21:27:17 +00006186 DeclarationNameInfo NameInfo = E->getNameInfo();
6187 if (NameInfo.getName()) {
6188 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6189 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006190 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006191 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006192
6193 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006194 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006195 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006196 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006197 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006198
6199 // Mark it referenced in the new context regardless.
6200 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006201 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006202
John McCall3fa5cae2010-10-26 07:05:15 +00006203 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006204 }
John McCalldbd872f2009-12-08 09:08:17 +00006205
6206 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006207 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006208 TemplateArgs = &TransArgs;
6209 TransArgs.setLAngleLoc(E->getLAngleLoc());
6210 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006211 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6212 E->getNumTemplateArgs(),
6213 TransArgs))
6214 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006215 }
6216
Chad Rosier4a9d7952012-08-08 18:46:20 +00006217 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006218 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006219}
Mike Stump1eb44332009-09-09 15:08:12 +00006220
Douglas Gregorb98b1992009-08-11 05:31:07 +00006221template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006222ExprResult
John McCall454feb92009-12-08 09:21:05 +00006223TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006224 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006225}
Mike Stump1eb44332009-09-09 15:08:12 +00006226
Douglas Gregorb98b1992009-08-11 05:31:07 +00006227template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006228ExprResult
John McCall454feb92009-12-08 09:21:05 +00006229TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006230 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006231}
Mike Stump1eb44332009-09-09 15:08:12 +00006232
Douglas Gregorb98b1992009-08-11 05:31:07 +00006233template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006234ExprResult
John McCall454feb92009-12-08 09:21:05 +00006235TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006236 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006237}
Mike Stump1eb44332009-09-09 15:08:12 +00006238
Douglas Gregorb98b1992009-08-11 05:31:07 +00006239template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006240ExprResult
John McCall454feb92009-12-08 09:21:05 +00006241TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006242 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006243}
Mike Stump1eb44332009-09-09 15:08:12 +00006244
Douglas Gregorb98b1992009-08-11 05:31:07 +00006245template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006246ExprResult
John McCall454feb92009-12-08 09:21:05 +00006247TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006248 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006249}
6250
6251template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006252ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006253TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006254 if (FunctionDecl *FD = E->getDirectCallee())
6255 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006256 return SemaRef.MaybeBindToTemporary(E);
6257}
6258
6259template<typename Derived>
6260ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006261TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6262 ExprResult ControllingExpr =
6263 getDerived().TransformExpr(E->getControllingExpr());
6264 if (ControllingExpr.isInvalid())
6265 return ExprError();
6266
Chris Lattner686775d2011-07-20 06:58:45 +00006267 SmallVector<Expr *, 4> AssocExprs;
6268 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006269 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6270 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6271 if (TS) {
6272 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6273 if (!AssocType)
6274 return ExprError();
6275 AssocTypes.push_back(AssocType);
6276 } else {
6277 AssocTypes.push_back(0);
6278 }
6279
6280 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6281 if (AssocExpr.isInvalid())
6282 return ExprError();
6283 AssocExprs.push_back(AssocExpr.release());
6284 }
6285
6286 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6287 E->getDefaultLoc(),
6288 E->getRParenLoc(),
6289 ControllingExpr.release(),
Dmitri Gribenko80613222013-05-10 13:06:58 +00006290 AssocTypes,
6291 AssocExprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00006292}
6293
6294template<typename Derived>
6295ExprResult
John McCall454feb92009-12-08 09:21:05 +00006296TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006297 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006298 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006299 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006300
Douglas Gregorb98b1992009-08-11 05:31:07 +00006301 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006302 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006303
John McCall9ae2f072010-08-23 23:25:46 +00006304 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006305 E->getRParen());
6306}
6307
Richard Smithefeeccf2012-10-21 03:28:35 +00006308/// \brief The operand of a unary address-of operator has special rules: it's
6309/// allowed to refer to a non-static member of a class even if there's no 'this'
6310/// object available.
6311template<typename Derived>
6312ExprResult
6313TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6314 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6315 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6316 else
6317 return getDerived().TransformExpr(E);
6318}
6319
Mike Stump1eb44332009-09-09 15:08:12 +00006320template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006321ExprResult
John McCall454feb92009-12-08 09:21:05 +00006322TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00006323 ExprResult SubExpr = TransformAddressOfOperand(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006324 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006325 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006326
Douglas Gregorb98b1992009-08-11 05:31:07 +00006327 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006328 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006329
Douglas Gregorb98b1992009-08-11 05:31:07 +00006330 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6331 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006332 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006333}
Mike Stump1eb44332009-09-09 15:08:12 +00006334
Douglas Gregorb98b1992009-08-11 05:31:07 +00006335template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006336ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006337TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6338 // Transform the type.
6339 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6340 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006341 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006342
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006343 // Transform all of the components into components similar to what the
6344 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006345 // FIXME: It would be slightly more efficient in the non-dependent case to
6346 // just map FieldDecls, rather than requiring the rebuilder to look for
6347 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006348 // template code that we don't care.
6349 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006350 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006351 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006352 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006353 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6354 const Node &ON = E->getComponent(I);
6355 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006356 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006357 Comp.LocStart = ON.getSourceRange().getBegin();
6358 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006359 switch (ON.getKind()) {
6360 case Node::Array: {
6361 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006362 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006363 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006364 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006365
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006366 ExprChanged = ExprChanged || Index.get() != FromIndex;
6367 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006368 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006369 break;
6370 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006371
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006372 case Node::Field:
6373 case Node::Identifier:
6374 Comp.isBrackets = false;
6375 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006376 if (!Comp.U.IdentInfo)
6377 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006378
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006379 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006380
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006381 case Node::Base:
6382 // Will be recomputed during the rebuild.
6383 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006384 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006385
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006386 Components.push_back(Comp);
6387 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006388
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006389 // If nothing changed, retain the existing expression.
6390 if (!getDerived().AlwaysRebuild() &&
6391 Type == E->getTypeSourceInfo() &&
6392 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006393 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006394
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006395 // Build a new offsetof expression.
6396 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6397 Components.data(), Components.size(),
6398 E->getRParenLoc());
6399}
6400
6401template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006402ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006403TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6404 assert(getDerived().AlreadyTransformed(E->getType()) &&
6405 "opaque value expression requires transformation");
6406 return SemaRef.Owned(E);
6407}
6408
6409template<typename Derived>
6410ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006411TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006412 // Rebuild the syntactic form. The original syntactic form has
6413 // opaque-value expressions in it, so strip those away and rebuild
6414 // the result. This is a really awful way of doing this, but the
6415 // better solution (rebuilding the semantic expressions and
6416 // rebinding OVEs as necessary) doesn't work; we'd need
6417 // TreeTransform to not strip away implicit conversions.
6418 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6419 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006420 if (result.isInvalid()) return ExprError();
6421
6422 // If that gives us a pseudo-object result back, the pseudo-object
6423 // expression must have been an lvalue-to-rvalue conversion which we
6424 // should reapply.
6425 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6426 result = SemaRef.checkPseudoObjectRValue(result.take());
6427
6428 return result;
6429}
6430
6431template<typename Derived>
6432ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006433TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6434 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006435 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006436 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006437
John McCalla93c9342009-12-07 02:54:59 +00006438 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006439 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006440 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006441
John McCall5ab75172009-11-04 07:28:41 +00006442 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006443 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006444
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006445 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6446 E->getKind(),
6447 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006448 }
Mike Stump1eb44332009-09-09 15:08:12 +00006449
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006450 // C++0x [expr.sizeof]p1:
6451 // The operand is either an expression, which is an unevaluated operand
6452 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006453 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6454 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006455
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006456 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6457 if (SubExpr.isInvalid())
6458 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006459
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006460 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6461 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006462
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006463 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6464 E->getOperatorLoc(),
6465 E->getKind(),
6466 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006467}
Mike Stump1eb44332009-09-09 15:08:12 +00006468
Douglas Gregorb98b1992009-08-11 05:31:07 +00006469template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006470ExprResult
John McCall454feb92009-12-08 09:21:05 +00006471TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006472 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006473 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006474 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006475
John McCall60d7b3a2010-08-24 06:29:42 +00006476 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006477 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006478 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006479
6480
Douglas Gregorb98b1992009-08-11 05:31:07 +00006481 if (!getDerived().AlwaysRebuild() &&
6482 LHS.get() == E->getLHS() &&
6483 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006484 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006485
John McCall9ae2f072010-08-23 23:25:46 +00006486 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006487 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006488 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006489 E->getRBracketLoc());
6490}
Mike Stump1eb44332009-09-09 15:08:12 +00006491
6492template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006493ExprResult
John McCall454feb92009-12-08 09:21:05 +00006494TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006495 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006496 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006497 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006498 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006499
6500 // Transform arguments.
6501 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006502 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006503 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006504 &ArgChanged))
6505 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006506
Douglas Gregorb98b1992009-08-11 05:31:07 +00006507 if (!getDerived().AlwaysRebuild() &&
6508 Callee.get() == E->getCallee() &&
6509 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006510 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006511
Douglas Gregorb98b1992009-08-11 05:31:07 +00006512 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006513 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006514 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006515 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006516 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006517 E->getRParenLoc());
6518}
Mike Stump1eb44332009-09-09 15:08:12 +00006519
6520template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006521ExprResult
John McCall454feb92009-12-08 09:21:05 +00006522TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006523 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006524 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006525 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006526
Douglas Gregor40d96a62011-02-28 21:54:11 +00006527 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006528 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006529 QualifierLoc
6530 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006531
Douglas Gregor40d96a62011-02-28 21:54:11 +00006532 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006533 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006534 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006535 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006536
Eli Friedmanf595cc42009-12-04 06:40:45 +00006537 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006538 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6539 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006540 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006541 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006542
John McCall6bb80172010-03-30 21:47:33 +00006543 NamedDecl *FoundDecl = E->getFoundDecl();
6544 if (FoundDecl == E->getMemberDecl()) {
6545 FoundDecl = Member;
6546 } else {
6547 FoundDecl = cast_or_null<NamedDecl>(
6548 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6549 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006550 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006551 }
6552
Douglas Gregorb98b1992009-08-11 05:31:07 +00006553 if (!getDerived().AlwaysRebuild() &&
6554 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006555 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006556 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006557 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006558 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006559
Anders Carlsson1f240322009-12-22 05:24:09 +00006560 // Mark it referenced in the new context regardless.
6561 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006562 SemaRef.MarkMemberReferenced(E);
6563
John McCall3fa5cae2010-10-26 07:05:15 +00006564 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006565 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006566
John McCalld5532b62009-11-23 01:53:49 +00006567 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006568 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006569 TransArgs.setLAngleLoc(E->getLAngleLoc());
6570 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006571 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6572 E->getNumTemplateArgs(),
6573 TransArgs))
6574 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006575 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006576
Douglas Gregorb98b1992009-08-11 05:31:07 +00006577 // FIXME: Bogus source location for the operator
6578 SourceLocation FakeOperatorLoc
6579 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6580
John McCallc2233c52010-01-15 08:34:02 +00006581 // FIXME: to do this check properly, we will need to preserve the
6582 // first-qualifier-in-scope here, just in case we had a dependent
6583 // base (and therefore couldn't do the check) and a
6584 // nested-name-qualifier (and therefore could do the lookup).
6585 NamedDecl *FirstQualifierInScope = 0;
6586
John McCall9ae2f072010-08-23 23:25:46 +00006587 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006588 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006589 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006590 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006591 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006592 Member,
John McCall6bb80172010-03-30 21:47:33 +00006593 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006594 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006595 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006596 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006597}
Mike Stump1eb44332009-09-09 15:08:12 +00006598
Douglas Gregorb98b1992009-08-11 05:31:07 +00006599template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006600ExprResult
John McCall454feb92009-12-08 09:21:05 +00006601TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006602 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006603 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006604 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006605
John McCall60d7b3a2010-08-24 06:29:42 +00006606 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006607 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006608 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006609
Douglas Gregorb98b1992009-08-11 05:31:07 +00006610 if (!getDerived().AlwaysRebuild() &&
6611 LHS.get() == E->getLHS() &&
6612 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006613 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006614
Lang Hamesbe9af122012-10-02 04:45:10 +00006615 Sema::FPContractStateRAII FPContractState(getSema());
6616 getSema().FPFeatures.fp_contract = E->isFPContractable();
6617
Douglas Gregorb98b1992009-08-11 05:31:07 +00006618 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006619 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006620}
6621
Mike Stump1eb44332009-09-09 15:08:12 +00006622template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006623ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006624TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006625 CompoundAssignOperator *E) {
6626 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006627}
Mike Stump1eb44332009-09-09 15:08:12 +00006628
Douglas Gregorb98b1992009-08-11 05:31:07 +00006629template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006630ExprResult TreeTransform<Derived>::
6631TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6632 // Just rebuild the common and RHS expressions and see whether we
6633 // get any changes.
6634
6635 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6636 if (commonExpr.isInvalid())
6637 return ExprError();
6638
6639 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6640 if (rhs.isInvalid())
6641 return ExprError();
6642
6643 if (!getDerived().AlwaysRebuild() &&
6644 commonExpr.get() == e->getCommon() &&
6645 rhs.get() == e->getFalseExpr())
6646 return SemaRef.Owned(e);
6647
6648 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6649 e->getQuestionLoc(),
6650 0,
6651 e->getColonLoc(),
6652 rhs.get());
6653}
6654
6655template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006656ExprResult
John McCall454feb92009-12-08 09:21:05 +00006657TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006658 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006659 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006660 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006661
John McCall60d7b3a2010-08-24 06:29:42 +00006662 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006663 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006664 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006665
John McCall60d7b3a2010-08-24 06:29:42 +00006666 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006668 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006669
Douglas Gregorb98b1992009-08-11 05:31:07 +00006670 if (!getDerived().AlwaysRebuild() &&
6671 Cond.get() == E->getCond() &&
6672 LHS.get() == E->getLHS() &&
6673 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006674 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006675
John McCall9ae2f072010-08-23 23:25:46 +00006676 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006677 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006678 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006679 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006680 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006681}
Mike Stump1eb44332009-09-09 15:08:12 +00006682
6683template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006684ExprResult
John McCall454feb92009-12-08 09:21:05 +00006685TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006686 // Implicit casts are eliminated during transformation, since they
6687 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006688 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006689}
Mike Stump1eb44332009-09-09 15:08:12 +00006690
Douglas Gregorb98b1992009-08-11 05:31:07 +00006691template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006692ExprResult
John McCall454feb92009-12-08 09:21:05 +00006693TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006694 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6695 if (!Type)
6696 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006697
John McCall60d7b3a2010-08-24 06:29:42 +00006698 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006699 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006700 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006701 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006702
Douglas Gregorb98b1992009-08-11 05:31:07 +00006703 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006704 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006705 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006706 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006707
John McCall9d125032010-01-15 18:39:57 +00006708 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006709 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006710 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006711 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712}
Mike Stump1eb44332009-09-09 15:08:12 +00006713
Douglas Gregorb98b1992009-08-11 05:31:07 +00006714template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006715ExprResult
John McCall454feb92009-12-08 09:21:05 +00006716TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006717 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6718 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6719 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006720 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006721
John McCall60d7b3a2010-08-24 06:29:42 +00006722 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006723 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006724 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006725
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006727 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006728 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006729 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006730
John McCall1d7d8d62010-01-19 22:33:45 +00006731 // Note: the expression type doesn't necessarily match the
6732 // type-as-written, but that's okay, because it should always be
6733 // derivable from the initializer.
6734
John McCall42f56b52010-01-18 19:35:47 +00006735 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006736 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006737 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006738}
Mike Stump1eb44332009-09-09 15:08:12 +00006739
Douglas Gregorb98b1992009-08-11 05:31:07 +00006740template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006741ExprResult
John McCall454feb92009-12-08 09:21:05 +00006742TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006743 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006744 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006745 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006746
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747 if (!getDerived().AlwaysRebuild() &&
6748 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006749 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006750
Douglas Gregorb98b1992009-08-11 05:31:07 +00006751 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006752 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006753 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006754 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006755 E->getAccessorLoc(),
6756 E->getAccessor());
6757}
Mike Stump1eb44332009-09-09 15:08:12 +00006758
Douglas Gregorb98b1992009-08-11 05:31:07 +00006759template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006760ExprResult
John McCall454feb92009-12-08 09:21:05 +00006761TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006762 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006763
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006764 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006765 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006766 Inits, &InitChanged))
6767 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006768
Douglas Gregorb98b1992009-08-11 05:31:07 +00006769 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006770 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006771
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006772 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006773 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006774}
Mike Stump1eb44332009-09-09 15:08:12 +00006775
Douglas Gregorb98b1992009-08-11 05:31:07 +00006776template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006777ExprResult
John McCall454feb92009-12-08 09:21:05 +00006778TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006779 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006780
Douglas Gregor43959a92009-08-20 07:17:43 +00006781 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006782 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006783 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006784 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006785
Douglas Gregor43959a92009-08-20 07:17:43 +00006786 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006787 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006788 bool ExprChanged = false;
6789 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6790 DEnd = E->designators_end();
6791 D != DEnd; ++D) {
6792 if (D->isFieldDesignator()) {
6793 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6794 D->getDotLoc(),
6795 D->getFieldLoc()));
6796 continue;
6797 }
Mike Stump1eb44332009-09-09 15:08:12 +00006798
Douglas Gregorb98b1992009-08-11 05:31:07 +00006799 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006800 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006801 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006802 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006803
6804 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006805 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006806
Douglas Gregorb98b1992009-08-11 05:31:07 +00006807 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6808 ArrayExprs.push_back(Index.release());
6809 continue;
6810 }
Mike Stump1eb44332009-09-09 15:08:12 +00006811
Douglas Gregorb98b1992009-08-11 05:31:07 +00006812 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006813 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006814 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6815 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006816 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006817
John McCall60d7b3a2010-08-24 06:29:42 +00006818 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006819 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006820 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006821
6822 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006823 End.get(),
6824 D->getLBracketLoc(),
6825 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006826
Douglas Gregorb98b1992009-08-11 05:31:07 +00006827 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6828 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006829
Douglas Gregorb98b1992009-08-11 05:31:07 +00006830 ArrayExprs.push_back(Start.release());
6831 ArrayExprs.push_back(End.release());
6832 }
Mike Stump1eb44332009-09-09 15:08:12 +00006833
Douglas Gregorb98b1992009-08-11 05:31:07 +00006834 if (!getDerived().AlwaysRebuild() &&
6835 Init.get() == E->getInit() &&
6836 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006837 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006838
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006839 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006840 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006841 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006842}
Mike Stump1eb44332009-09-09 15:08:12 +00006843
Douglas Gregorb98b1992009-08-11 05:31:07 +00006844template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006845ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006846TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006847 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006848 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006849
Douglas Gregor5557b252009-10-28 00:29:27 +00006850 // FIXME: Will we ever have proper type location here? Will we actually
6851 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006852 QualType T = getDerived().TransformType(E->getType());
6853 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006854 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006855
Douglas Gregorb98b1992009-08-11 05:31:07 +00006856 if (!getDerived().AlwaysRebuild() &&
6857 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006858 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006859
Douglas Gregorb98b1992009-08-11 05:31:07 +00006860 return getDerived().RebuildImplicitValueInitExpr(T);
6861}
Mike Stump1eb44332009-09-09 15:08:12 +00006862
Douglas Gregorb98b1992009-08-11 05:31:07 +00006863template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006864ExprResult
John McCall454feb92009-12-08 09:21:05 +00006865TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006866 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6867 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006868 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006869
John McCall60d7b3a2010-08-24 06:29:42 +00006870 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006871 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006872 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006873
Douglas Gregorb98b1992009-08-11 05:31:07 +00006874 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006875 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006876 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006877 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006878
John McCall9ae2f072010-08-23 23:25:46 +00006879 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006880 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006881}
6882
6883template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006884ExprResult
John McCall454feb92009-12-08 09:21:05 +00006885TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006886 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006887 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006888 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6889 &ArgumentChanged))
6890 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006891
Douglas Gregorb98b1992009-08-11 05:31:07 +00006892 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006893 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006894 E->getRParenLoc());
6895}
Mike Stump1eb44332009-09-09 15:08:12 +00006896
Douglas Gregorb98b1992009-08-11 05:31:07 +00006897/// \brief Transform an address-of-label expression.
6898///
6899/// By default, the transformation of an address-of-label expression always
6900/// rebuilds the expression, so that the label identifier can be resolved to
6901/// the corresponding label statement by semantic analysis.
6902template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006903ExprResult
John McCall454feb92009-12-08 09:21:05 +00006904TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006905 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6906 E->getLabel());
6907 if (!LD)
6908 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006909
Douglas Gregorb98b1992009-08-11 05:31:07 +00006910 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006911 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006912}
Mike Stump1eb44332009-09-09 15:08:12 +00006913
6914template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006915ExprResult
John McCall454feb92009-12-08 09:21:05 +00006916TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006917 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006918 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006919 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006920 if (SubStmt.isInvalid()) {
6921 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006922 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006923 }
Mike Stump1eb44332009-09-09 15:08:12 +00006924
Douglas Gregorb98b1992009-08-11 05:31:07 +00006925 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006926 SubStmt.get() == E->getSubStmt()) {
6927 // Calling this an 'error' is unintuitive, but it does the right thing.
6928 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006929 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006930 }
Mike Stump1eb44332009-09-09 15:08:12 +00006931
6932 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006933 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006934 E->getRParenLoc());
6935}
Mike Stump1eb44332009-09-09 15:08:12 +00006936
Douglas Gregorb98b1992009-08-11 05:31:07 +00006937template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006938ExprResult
John McCall454feb92009-12-08 09:21:05 +00006939TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006940 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006941 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006942 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006943
John McCall60d7b3a2010-08-24 06:29:42 +00006944 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006945 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006946 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006947
John McCall60d7b3a2010-08-24 06:29:42 +00006948 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006949 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006950 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006951
Douglas Gregorb98b1992009-08-11 05:31:07 +00006952 if (!getDerived().AlwaysRebuild() &&
6953 Cond.get() == E->getCond() &&
6954 LHS.get() == E->getLHS() &&
6955 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006956 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006957
Douglas Gregorb98b1992009-08-11 05:31:07 +00006958 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006959 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006960 E->getRParenLoc());
6961}
Mike Stump1eb44332009-09-09 15:08:12 +00006962
Douglas Gregorb98b1992009-08-11 05:31:07 +00006963template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006964ExprResult
John McCall454feb92009-12-08 09:21:05 +00006965TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006966 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006967}
6968
6969template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006970ExprResult
John McCall454feb92009-12-08 09:21:05 +00006971TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006972 switch (E->getOperator()) {
6973 case OO_New:
6974 case OO_Delete:
6975 case OO_Array_New:
6976 case OO_Array_Delete:
6977 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006978
Douglas Gregor668d6d92009-12-13 20:44:55 +00006979 case OO_Call: {
6980 // This is a call to an object's operator().
6981 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6982
6983 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006984 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006985 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006986 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006987
6988 // FIXME: Poor location information
6989 SourceLocation FakeLParenLoc
6990 = SemaRef.PP.getLocForEndOfToken(
6991 static_cast<Expr *>(Object.get())->getLocEnd());
6992
6993 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006994 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006995 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006996 Args))
6997 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006998
John McCall9ae2f072010-08-23 23:25:46 +00006999 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007000 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00007001 E->getLocEnd());
7002 }
7003
7004#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7005 case OO_##Name:
7006#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7007#include "clang/Basic/OperatorKinds.def"
7008 case OO_Subscript:
7009 // Handled below.
7010 break;
7011
7012 case OO_Conditional:
7013 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007014
7015 case OO_None:
7016 case NUM_OVERLOADED_OPERATORS:
7017 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007018 }
7019
John McCall60d7b3a2010-08-24 06:29:42 +00007020 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007021 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007022 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007023
Richard Smithefeeccf2012-10-21 03:28:35 +00007024 ExprResult First;
7025 if (E->getOperator() == OO_Amp)
7026 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7027 else
7028 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007029 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007030 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031
John McCall60d7b3a2010-08-24 06:29:42 +00007032 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007033 if (E->getNumArgs() == 2) {
7034 Second = getDerived().TransformExpr(E->getArg(1));
7035 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007036 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007037 }
Mike Stump1eb44332009-09-09 15:08:12 +00007038
Douglas Gregorb98b1992009-08-11 05:31:07 +00007039 if (!getDerived().AlwaysRebuild() &&
7040 Callee.get() == E->getCallee() &&
7041 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007042 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007043 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007044
Lang Hamesbe9af122012-10-02 04:45:10 +00007045 Sema::FPContractStateRAII FPContractState(getSema());
7046 getSema().FPFeatures.fp_contract = E->isFPContractable();
7047
Douglas Gregorb98b1992009-08-11 05:31:07 +00007048 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7049 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007050 Callee.get(),
7051 First.get(),
7052 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007053}
Mike Stump1eb44332009-09-09 15:08:12 +00007054
Douglas Gregorb98b1992009-08-11 05:31:07 +00007055template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007056ExprResult
John McCall454feb92009-12-08 09:21:05 +00007057TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7058 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007059}
Mike Stump1eb44332009-09-09 15:08:12 +00007060
Douglas Gregorb98b1992009-08-11 05:31:07 +00007061template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007062ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007063TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7064 // Transform the callee.
7065 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7066 if (Callee.isInvalid())
7067 return ExprError();
7068
7069 // Transform exec config.
7070 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7071 if (EC.isInvalid())
7072 return ExprError();
7073
7074 // Transform arguments.
7075 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007076 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007077 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007078 &ArgChanged))
7079 return ExprError();
7080
7081 if (!getDerived().AlwaysRebuild() &&
7082 Callee.get() == E->getCallee() &&
7083 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007084 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007085
7086 // FIXME: Wrong source location information for the '('.
7087 SourceLocation FakeLParenLoc
7088 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7089 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007090 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007091 E->getRParenLoc(), EC.get());
7092}
7093
7094template<typename Derived>
7095ExprResult
John McCall454feb92009-12-08 09:21:05 +00007096TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007097 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7098 if (!Type)
7099 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007100
John McCall60d7b3a2010-08-24 06:29:42 +00007101 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007102 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007103 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007104 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007105
Douglas Gregorb98b1992009-08-11 05:31:07 +00007106 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007107 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007108 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007109 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007110 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007111 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007112 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007113 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007114 E->getAngleBrackets().getEnd(),
7115 // FIXME. this should be '(' location
7116 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007117 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007118 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007119}
Mike Stump1eb44332009-09-09 15:08:12 +00007120
Douglas Gregorb98b1992009-08-11 05:31:07 +00007121template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007122ExprResult
John McCall454feb92009-12-08 09:21:05 +00007123TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7124 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007125}
Mike Stump1eb44332009-09-09 15:08:12 +00007126
7127template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007128ExprResult
John McCall454feb92009-12-08 09:21:05 +00007129TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7130 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007131}
7132
Douglas Gregorb98b1992009-08-11 05:31:07 +00007133template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007134ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007135TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007136 CXXReinterpretCastExpr *E) {
7137 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007138}
Mike Stump1eb44332009-09-09 15:08:12 +00007139
Douglas Gregorb98b1992009-08-11 05:31:07 +00007140template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007141ExprResult
John McCall454feb92009-12-08 09:21:05 +00007142TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7143 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007144}
Mike Stump1eb44332009-09-09 15:08:12 +00007145
Douglas Gregorb98b1992009-08-11 05:31:07 +00007146template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007147ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007148TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007149 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007150 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7151 if (!Type)
7152 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007153
John McCall60d7b3a2010-08-24 06:29:42 +00007154 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007155 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007156 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007157 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007158
Douglas Gregorb98b1992009-08-11 05:31:07 +00007159 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007160 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007161 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007162 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007163
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007164 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007165 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007166 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007167 E->getRParenLoc());
7168}
Mike Stump1eb44332009-09-09 15:08:12 +00007169
Douglas Gregorb98b1992009-08-11 05:31:07 +00007170template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007171ExprResult
John McCall454feb92009-12-08 09:21:05 +00007172TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007173 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007174 TypeSourceInfo *TInfo
7175 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7176 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007177 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007178
Douglas Gregorb98b1992009-08-11 05:31:07 +00007179 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007180 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007181 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007182
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007183 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7184 E->getLocStart(),
7185 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007186 E->getLocEnd());
7187 }
Mike Stump1eb44332009-09-09 15:08:12 +00007188
Eli Friedmanef331b72012-01-20 01:26:23 +00007189 // We don't know whether the subexpression is potentially evaluated until
7190 // after we perform semantic analysis. We speculatively assume it is
7191 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007192 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007193 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7194 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007195
John McCall60d7b3a2010-08-24 06:29:42 +00007196 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007197 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007198 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007199
Douglas Gregorb98b1992009-08-11 05:31:07 +00007200 if (!getDerived().AlwaysRebuild() &&
7201 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007202 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007203
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007204 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7205 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007206 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007207 E->getLocEnd());
7208}
7209
7210template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007211ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007212TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7213 if (E->isTypeOperand()) {
7214 TypeSourceInfo *TInfo
7215 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7216 if (!TInfo)
7217 return ExprError();
7218
7219 if (!getDerived().AlwaysRebuild() &&
7220 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007221 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007222
Douglas Gregor3c52a212011-03-06 17:40:41 +00007223 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007224 E->getLocStart(),
7225 TInfo,
7226 E->getLocEnd());
7227 }
7228
Francois Pichet01b7c302010-09-08 12:20:18 +00007229 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7230
7231 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7232 if (SubExpr.isInvalid())
7233 return ExprError();
7234
7235 if (!getDerived().AlwaysRebuild() &&
7236 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007237 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007238
7239 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7240 E->getLocStart(),
7241 SubExpr.get(),
7242 E->getLocEnd());
7243}
7244
7245template<typename Derived>
7246ExprResult
John McCall454feb92009-12-08 09:21:05 +00007247TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007248 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007249}
Mike Stump1eb44332009-09-09 15:08:12 +00007250
Douglas Gregorb98b1992009-08-11 05:31:07 +00007251template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007252ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007253TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007254 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007255 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007256}
Mike Stump1eb44332009-09-09 15:08:12 +00007257
Douglas Gregorb98b1992009-08-11 05:31:07 +00007258template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007259ExprResult
John McCall454feb92009-12-08 09:21:05 +00007260TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007261 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007262 QualType T;
7263 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7264 T = MD->getThisType(getSema().Context);
Douglas Gregore4743be2013-03-08 22:43:48 +00007265 else if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(DC)) {
Richard Smith7a614d82011-06-11 17:19:42 +00007266 T = getSema().Context.getPointerType(
Douglas Gregore4743be2013-03-08 22:43:48 +00007267 getSema().Context.getRecordType(Record));
7268 } else {
7269 assert(SemaRef.Context.getDiagnostics().hasErrorOccurred() &&
7270 "this in the wrong scope?");
7271 return ExprError();
7272 }
Mike Stump1eb44332009-09-09 15:08:12 +00007273
Douglas Gregorec79d872012-02-24 17:41:38 +00007274 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7275 // Make sure that we capture 'this'.
7276 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007277 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007278 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007279
Douglas Gregor828a1972010-01-07 23:12:05 +00007280 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007281}
Mike Stump1eb44332009-09-09 15:08:12 +00007282
Douglas Gregorb98b1992009-08-11 05:31:07 +00007283template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007284ExprResult
John McCall454feb92009-12-08 09:21:05 +00007285TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007286 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007287 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007288 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007289
Douglas Gregorb98b1992009-08-11 05:31:07 +00007290 if (!getDerived().AlwaysRebuild() &&
7291 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007292 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007293
Douglas Gregorbca01b42011-07-06 22:04:06 +00007294 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7295 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007296}
Mike Stump1eb44332009-09-09 15:08:12 +00007297
Douglas Gregorb98b1992009-08-11 05:31:07 +00007298template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007299ExprResult
John McCall454feb92009-12-08 09:21:05 +00007300TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007301 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007302 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7303 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007304 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007305 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007306
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007307 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007308 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007309 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007310
Douglas Gregor036aed12009-12-23 23:03:06 +00007311 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007312}
Mike Stump1eb44332009-09-09 15:08:12 +00007313
Douglas Gregorb98b1992009-08-11 05:31:07 +00007314template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007315ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007316TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7317 FieldDecl *Field
7318 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7319 E->getField()));
7320 if (!Field)
7321 return ExprError();
7322
7323 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7324 return SemaRef.Owned(E);
7325
7326 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7327}
7328
7329template<typename Derived>
7330ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007331TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7332 CXXScalarValueInitExpr *E) {
7333 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7334 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007335 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007336
Douglas Gregorb98b1992009-08-11 05:31:07 +00007337 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007338 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007339 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007340
Chad Rosier4a9d7952012-08-08 18:46:20 +00007341 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007342 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007343 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007344}
Mike Stump1eb44332009-09-09 15:08:12 +00007345
Douglas Gregorb98b1992009-08-11 05:31:07 +00007346template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007347ExprResult
John McCall454feb92009-12-08 09:21:05 +00007348TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007349 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007350 TypeSourceInfo *AllocTypeInfo
7351 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7352 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007353 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007354
Douglas Gregorb98b1992009-08-11 05:31:07 +00007355 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007356 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007357 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007358 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007359
Douglas Gregorb98b1992009-08-11 05:31:07 +00007360 // Transform the placement arguments (if any).
7361 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007362 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007363 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007364 E->getNumPlacementArgs(), true,
7365 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007366 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007367
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007368 // Transform the initializer (if any).
7369 Expr *OldInit = E->getInitializer();
7370 ExprResult NewInit;
7371 if (OldInit)
7372 NewInit = getDerived().TransformExpr(OldInit);
7373 if (NewInit.isInvalid())
7374 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007375
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007376 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007377 FunctionDecl *OperatorNew = 0;
7378 if (E->getOperatorNew()) {
7379 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007380 getDerived().TransformDecl(E->getLocStart(),
7381 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007382 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007383 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007384 }
7385
7386 FunctionDecl *OperatorDelete = 0;
7387 if (E->getOperatorDelete()) {
7388 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007389 getDerived().TransformDecl(E->getLocStart(),
7390 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007391 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007392 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007393 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007394
Douglas Gregorb98b1992009-08-11 05:31:07 +00007395 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007396 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007397 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007398 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007399 OperatorNew == E->getOperatorNew() &&
7400 OperatorDelete == E->getOperatorDelete() &&
7401 !ArgumentChanged) {
7402 // Mark any declarations we need as referenced.
7403 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007404 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007405 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007406 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007407 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007408
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007409 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007410 QualType ElementType
7411 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7412 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7413 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7414 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007415 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007416 }
7417 }
7418 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007419
John McCall3fa5cae2010-10-26 07:05:15 +00007420 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007421 }
Mike Stump1eb44332009-09-09 15:08:12 +00007422
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007423 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007424 if (!ArraySize.get()) {
7425 // If no array size was specified, but the new expression was
7426 // instantiated with an array type (e.g., "new T" where T is
7427 // instantiated with "int[4]"), extract the outer bound from the
7428 // array type as our array size. We do this with constant and
7429 // dependently-sized array types.
7430 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7431 if (!ArrayT) {
7432 // Do nothing
7433 } else if (const ConstantArrayType *ConsArrayT
7434 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007435 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007436 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007437 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007438 SemaRef.Context.getSizeType(),
7439 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007440 AllocType = ConsArrayT->getElementType();
7441 } else if (const DependentSizedArrayType *DepArrayT
7442 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7443 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007444 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007445 AllocType = DepArrayT->getElementType();
7446 }
7447 }
7448 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007449
Douglas Gregorb98b1992009-08-11 05:31:07 +00007450 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7451 E->isGlobalNew(),
7452 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007453 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007454 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007455 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007456 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007457 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007458 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007459 E->getDirectInitRange(),
7460 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007461}
Mike Stump1eb44332009-09-09 15:08:12 +00007462
Douglas Gregorb98b1992009-08-11 05:31:07 +00007463template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007464ExprResult
John McCall454feb92009-12-08 09:21:05 +00007465TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007466 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007467 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007468 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007469
Douglas Gregor1af74512010-02-26 00:38:10 +00007470 // Transform the delete operator, if known.
7471 FunctionDecl *OperatorDelete = 0;
7472 if (E->getOperatorDelete()) {
7473 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007474 getDerived().TransformDecl(E->getLocStart(),
7475 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007476 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007477 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007478 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007479
Douglas Gregorb98b1992009-08-11 05:31:07 +00007480 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007481 Operand.get() == E->getArgument() &&
7482 OperatorDelete == E->getOperatorDelete()) {
7483 // Mark any declarations we need as referenced.
7484 // FIXME: instantiation-specific.
7485 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007486 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007487
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007488 if (!E->getArgument()->isTypeDependent()) {
7489 QualType Destroyed = SemaRef.Context.getBaseElementType(
7490 E->getDestroyedType());
7491 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7492 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007493 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007494 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007495 }
7496 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007497
John McCall3fa5cae2010-10-26 07:05:15 +00007498 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007499 }
Mike Stump1eb44332009-09-09 15:08:12 +00007500
Douglas Gregorb98b1992009-08-11 05:31:07 +00007501 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7502 E->isGlobalDelete(),
7503 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007504 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007505}
Mike Stump1eb44332009-09-09 15:08:12 +00007506
Douglas Gregorb98b1992009-08-11 05:31:07 +00007507template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007508ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007509TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007510 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007511 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007512 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007513 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007514
John McCallb3d87482010-08-24 05:47:05 +00007515 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007516 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007517 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007518 E->getOperatorLoc(),
7519 E->isArrow()? tok::arrow : tok::period,
7520 ObjectTypePtr,
7521 MayBePseudoDestructor);
7522 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007523 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007524
John McCallb3d87482010-08-24 05:47:05 +00007525 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007526 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7527 if (QualifierLoc) {
7528 QualifierLoc
7529 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7530 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007531 return ExprError();
7532 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007533 CXXScopeSpec SS;
7534 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007535
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007536 PseudoDestructorTypeStorage Destroyed;
7537 if (E->getDestroyedTypeInfo()) {
7538 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007539 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007540 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007541 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007542 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007543 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007544 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007545 // We aren't likely to be able to resolve the identifier down to a type
7546 // now anyway, so just retain the identifier.
7547 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7548 E->getDestroyedTypeLoc());
7549 } else {
7550 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007551 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007552 *E->getDestroyedTypeIdentifier(),
7553 E->getDestroyedTypeLoc(),
7554 /*Scope=*/0,
7555 SS, ObjectTypePtr,
7556 false);
7557 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007558 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007559
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007560 Destroyed
7561 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7562 E->getDestroyedTypeLoc());
7563 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007564
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007565 TypeSourceInfo *ScopeTypeInfo = 0;
7566 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007567 CXXScopeSpec EmptySS;
7568 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7569 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007570 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007571 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007572 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007573
John McCall9ae2f072010-08-23 23:25:46 +00007574 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007575 E->getOperatorLoc(),
7576 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007577 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007578 ScopeTypeInfo,
7579 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007580 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007581 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007582}
Mike Stump1eb44332009-09-09 15:08:12 +00007583
Douglas Gregora71d8192009-09-04 17:36:40 +00007584template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007585ExprResult
John McCallba135432009-11-21 08:51:07 +00007586TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007587 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007588 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7589 Sema::LookupOrdinaryName);
7590
7591 // Transform all the decls.
7592 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7593 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007594 NamedDecl *InstD = static_cast<NamedDecl*>(
7595 getDerived().TransformDecl(Old->getNameLoc(),
7596 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007597 if (!InstD) {
7598 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7599 // This can happen because of dependent hiding.
7600 if (isa<UsingShadowDecl>(*I))
7601 continue;
7602 else
John McCallf312b1e2010-08-26 23:41:50 +00007603 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007604 }
John McCallf7a1a742009-11-24 19:00:30 +00007605
7606 // Expand using declarations.
7607 if (isa<UsingDecl>(InstD)) {
7608 UsingDecl *UD = cast<UsingDecl>(InstD);
7609 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7610 E = UD->shadow_end(); I != E; ++I)
7611 R.addDecl(*I);
7612 continue;
7613 }
7614
7615 R.addDecl(InstD);
7616 }
7617
7618 // Resolve a kind, but don't do any further analysis. If it's
7619 // ambiguous, the callee needs to deal with it.
7620 R.resolveKind();
7621
7622 // Rebuild the nested-name qualifier, if present.
7623 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007624 if (Old->getQualifierLoc()) {
7625 NestedNameSpecifierLoc QualifierLoc
7626 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7627 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007628 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007629
Douglas Gregor4c9be892011-02-28 20:01:57 +00007630 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007631 }
7632
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007633 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007634 CXXRecordDecl *NamingClass
7635 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7636 Old->getNameLoc(),
7637 Old->getNamingClass()));
7638 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007639 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007640
Douglas Gregor66c45152010-04-27 16:10:10 +00007641 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007642 }
7643
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007644 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7645
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007646 // If we have neither explicit template arguments, nor the template keyword,
7647 // it's a normal declaration name.
7648 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007649 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7650
7651 // If we have template arguments, rebuild them, then rebuild the
7652 // templateid expression.
7653 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007654 if (Old->hasExplicitTemplateArgs() &&
7655 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007656 Old->getNumTemplateArgs(),
7657 TransArgs))
7658 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007659
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007660 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007661 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007662}
Mike Stump1eb44332009-09-09 15:08:12 +00007663
Douglas Gregorb98b1992009-08-11 05:31:07 +00007664template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007665ExprResult
John McCall454feb92009-12-08 09:21:05 +00007666TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007667 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7668 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007669 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007670
Douglas Gregorb98b1992009-08-11 05:31:07 +00007671 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007672 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007673 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007674
Mike Stump1eb44332009-09-09 15:08:12 +00007675 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007676 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007677 T,
7678 E->getLocEnd());
7679}
Mike Stump1eb44332009-09-09 15:08:12 +00007680
Douglas Gregorb98b1992009-08-11 05:31:07 +00007681template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007682ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007683TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7684 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7685 if (!LhsT)
7686 return ExprError();
7687
7688 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7689 if (!RhsT)
7690 return ExprError();
7691
7692 if (!getDerived().AlwaysRebuild() &&
7693 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7694 return SemaRef.Owned(E);
7695
7696 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7697 E->getLocStart(),
7698 LhsT, RhsT,
7699 E->getLocEnd());
7700}
7701
7702template<typename Derived>
7703ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007704TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7705 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007706 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007707 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7708 TypeSourceInfo *From = E->getArg(I);
7709 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007710 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007711 TypeLocBuilder TLB;
7712 TLB.reserve(FromTL.getFullDataSize());
7713 QualType To = getDerived().TransformType(TLB, FromTL);
7714 if (To.isNull())
7715 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007716
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007717 if (To == From->getType())
7718 Args.push_back(From);
7719 else {
7720 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7721 ArgChanged = true;
7722 }
7723 continue;
7724 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007725
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007726 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007727
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007728 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007729 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007730 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7731 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7732 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007733
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007734 // Determine whether the set of unexpanded parameter packs can and should
7735 // be expanded.
7736 bool Expand = true;
7737 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007738 Optional<unsigned> OrigNumExpansions =
7739 ExpansionTL.getTypePtr()->getNumExpansions();
7740 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007741 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7742 PatternTL.getSourceRange(),
7743 Unexpanded,
7744 Expand, RetainExpansion,
7745 NumExpansions))
7746 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007747
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007748 if (!Expand) {
7749 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007750 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007751 // expansion.
7752 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007753
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007754 TypeLocBuilder TLB;
7755 TLB.reserve(From->getTypeLoc().getFullDataSize());
7756
7757 QualType To = getDerived().TransformType(TLB, PatternTL);
7758 if (To.isNull())
7759 return ExprError();
7760
Chad Rosier4a9d7952012-08-08 18:46:20 +00007761 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007762 PatternTL.getSourceRange(),
7763 ExpansionTL.getEllipsisLoc(),
7764 NumExpansions);
7765 if (To.isNull())
7766 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007767
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007768 PackExpansionTypeLoc ToExpansionTL
7769 = TLB.push<PackExpansionTypeLoc>(To);
7770 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7771 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7772 continue;
7773 }
7774
7775 // Expand the pack expansion by substituting for each argument in the
7776 // pack(s).
7777 for (unsigned I = 0; I != *NumExpansions; ++I) {
7778 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7779 TypeLocBuilder TLB;
7780 TLB.reserve(PatternTL.getFullDataSize());
7781 QualType To = getDerived().TransformType(TLB, PatternTL);
7782 if (To.isNull())
7783 return ExprError();
7784
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 (!RetainExpansion)
7789 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007790
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007791 // If we're supposed to retain a pack expansion, do so by temporarily
7792 // forgetting the partially-substituted parameter pack.
7793 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7794
7795 TypeLocBuilder TLB;
7796 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007797
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007798 QualType To = getDerived().TransformType(TLB, PatternTL);
7799 if (To.isNull())
7800 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007801
7802 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007803 PatternTL.getSourceRange(),
7804 ExpansionTL.getEllipsisLoc(),
7805 NumExpansions);
7806 if (To.isNull())
7807 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007808
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007809 PackExpansionTypeLoc ToExpansionTL
7810 = TLB.push<PackExpansionTypeLoc>(To);
7811 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7812 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7813 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007814
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007815 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7816 return SemaRef.Owned(E);
7817
7818 return getDerived().RebuildTypeTrait(E->getTrait(),
7819 E->getLocStart(),
7820 Args,
7821 E->getLocEnd());
7822}
7823
7824template<typename Derived>
7825ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007826TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7827 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7828 if (!T)
7829 return ExprError();
7830
7831 if (!getDerived().AlwaysRebuild() &&
7832 T == E->getQueriedTypeSourceInfo())
7833 return SemaRef.Owned(E);
7834
7835 ExprResult SubExpr;
7836 {
7837 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7838 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7839 if (SubExpr.isInvalid())
7840 return ExprError();
7841
7842 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7843 return SemaRef.Owned(E);
7844 }
7845
7846 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7847 E->getLocStart(),
7848 T,
7849 SubExpr.get(),
7850 E->getLocEnd());
7851}
7852
7853template<typename Derived>
7854ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007855TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7856 ExprResult SubExpr;
7857 {
7858 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7859 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7860 if (SubExpr.isInvalid())
7861 return ExprError();
7862
7863 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7864 return SemaRef.Owned(E);
7865 }
7866
7867 return getDerived().RebuildExpressionTrait(
7868 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7869}
7870
7871template<typename Derived>
7872ExprResult
John McCall865d4472009-11-19 22:55:06 +00007873TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007874 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00007875 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
7876}
7877
7878template<typename Derived>
7879ExprResult
7880TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7881 DependentScopeDeclRefExpr *E,
7882 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007883 NestedNameSpecifierLoc QualifierLoc
7884 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7885 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007886 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007887 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007888
John McCall43fed0d2010-11-12 08:19:04 +00007889 // TODO: If this is a conversion-function-id, verify that the
7890 // destination type name (if present) resolves the same way after
7891 // instantiation as it did in the local scope.
7892
Abramo Bagnara25777432010-08-11 22:01:17 +00007893 DeclarationNameInfo NameInfo
7894 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7895 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007896 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007897
John McCallf7a1a742009-11-24 19:00:30 +00007898 if (!E->hasExplicitTemplateArgs()) {
7899 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007900 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007901 // Note: it is sufficient to compare the Name component of NameInfo:
7902 // if name has not changed, DNLoc has not changed either.
7903 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007904 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007905
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007906 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007907 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007908 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007909 /*TemplateArgs*/ 0,
7910 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007911 }
John McCalld5532b62009-11-23 01:53:49 +00007912
7913 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007914 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7915 E->getNumTemplateArgs(),
7916 TransArgs))
7917 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007918
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007919 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007920 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007921 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007922 &TransArgs,
7923 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007924}
7925
7926template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007927ExprResult
John McCall454feb92009-12-08 09:21:05 +00007928TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00007929 // CXXConstructExprs other than for list-initialization and
7930 // CXXTemporaryObjectExpr are always implicit, so when we have
7931 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00007932 if ((E->getNumArgs() == 1 ||
7933 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00007934 (!getDerived().DropCallArgument(E->getArg(0))) &&
7935 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00007936 return getDerived().TransformExpr(E->getArg(0));
7937
Douglas Gregorb98b1992009-08-11 05:31:07 +00007938 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7939
7940 QualType T = getDerived().TransformType(E->getType());
7941 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007942 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007943
7944 CXXConstructorDecl *Constructor
7945 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007946 getDerived().TransformDecl(E->getLocStart(),
7947 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007948 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007949 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007950
Douglas Gregorb98b1992009-08-11 05:31:07 +00007951 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007952 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007953 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007954 &ArgumentChanged))
7955 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007956
Douglas Gregorb98b1992009-08-11 05:31:07 +00007957 if (!getDerived().AlwaysRebuild() &&
7958 T == E->getType() &&
7959 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007960 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007961 // Mark the constructor as referenced.
7962 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007963 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007964 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007965 }
Mike Stump1eb44332009-09-09 15:08:12 +00007966
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007967 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7968 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007969 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007970 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00007971 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007972 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007973 E->getConstructionKind(),
7974 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007975}
Mike Stump1eb44332009-09-09 15:08:12 +00007976
Douglas Gregorb98b1992009-08-11 05:31:07 +00007977/// \brief Transform a C++ temporary-binding expression.
7978///
Douglas Gregor51326552009-12-24 18:51:59 +00007979/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7980/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007981template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007982ExprResult
John McCall454feb92009-12-08 09:21:05 +00007983TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007984 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007985}
Mike Stump1eb44332009-09-09 15:08:12 +00007986
John McCall4765fa02010-12-06 08:20:24 +00007987/// \brief Transform a C++ expression that contains cleanups that should
7988/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007989///
John McCall4765fa02010-12-06 08:20:24 +00007990/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007991/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007992template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007993ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007994TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007995 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007996}
Mike Stump1eb44332009-09-09 15:08:12 +00007997
Douglas Gregorb98b1992009-08-11 05:31:07 +00007998template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007999ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008000TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00008001 CXXTemporaryObjectExpr *E) {
8002 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8003 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008004 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008005
Douglas Gregorb98b1992009-08-11 05:31:07 +00008006 CXXConstructorDecl *Constructor
8007 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008008 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008009 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008010 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008011 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008012
Douglas Gregorb98b1992009-08-11 05:31:07 +00008013 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008014 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00008015 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008016 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008017 &ArgumentChanged))
8018 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008019
Douglas Gregorb98b1992009-08-11 05:31:07 +00008020 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008021 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008022 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00008023 !ArgumentChanged) {
8024 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008025 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008026 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00008027 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008028
Richard Smithc83c2302012-12-19 01:39:02 +00008029 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00008030 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8031 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008032 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008033 E->getLocEnd());
8034}
Mike Stump1eb44332009-09-09 15:08:12 +00008035
Douglas Gregorb98b1992009-08-11 05:31:07 +00008036template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008037ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008038TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00008039 // Transform the type of the lambda parameters and start the definition of
8040 // the lambda itself.
8041 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00008042 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00008043 if (!MethodTy)
8044 return ExprError();
8045
Eli Friedman8da8a662012-09-19 01:18:11 +00008046 // Create the local class that will describe the lambda.
8047 CXXRecordDecl *Class
8048 = getSema().createLambdaClosureType(E->getIntroducerRange(),
8049 MethodTy,
8050 /*KnownDependent=*/false);
8051 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8052
Douglas Gregorc6889e72012-02-14 22:28:59 +00008053 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008054 SmallVector<QualType, 4> ParamTypes;
8055 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00008056 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
8057 E->getCallOperator()->param_begin(),
8058 E->getCallOperator()->param_size(),
8059 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00008060 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00008061
Douglas Gregordfca6f52012-02-13 22:00:16 +00008062 // Build the call operator.
8063 CXXMethodDecl *CallOperator
8064 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008065 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008066 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008067 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008068 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00008069
Richard Smith612409e2012-07-25 03:56:55 +00008070 return getDerived().TransformLambdaScope(E, CallOperator);
8071}
8072
8073template<typename Derived>
8074ExprResult
8075TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8076 CXXMethodDecl *CallOperator) {
Richard Smith0d8e9642013-05-16 06:20:58 +00008077 bool Invalid = false;
8078
8079 // Transform any init-capture expressions before entering the scope of the
8080 // lambda.
8081 llvm::SmallVector<ExprResult, 8> InitCaptureExprs;
8082 InitCaptureExprs.resize(E->explicit_capture_end() -
8083 E->explicit_capture_begin());
8084 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8085 CEnd = E->capture_end();
8086 C != CEnd; ++C) {
8087 if (!C->isInitCapture())
8088 continue;
8089 InitCaptureExprs[C - E->capture_begin()] =
8090 getDerived().TransformExpr(E->getInitCaptureInit(C));
8091 }
8092
Douglas Gregord5387e82012-02-14 00:00:48 +00008093 // Introduce the context of the call operator.
8094 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8095
Douglas Gregordfca6f52012-02-13 22:00:16 +00008096 // Enter the scope of the lambda.
8097 sema::LambdaScopeInfo *LSI
8098 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
8099 E->getCaptureDefault(),
8100 E->hasExplicitParameters(),
8101 E->hasExplicitResultType(),
8102 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008103
Douglas Gregordfca6f52012-02-13 22:00:16 +00008104 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00008105 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008106 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008107 CEnd = E->capture_end();
8108 C != CEnd; ++C) {
8109 // When we hit the first implicit capture, tell Sema that we've finished
8110 // the list of explicit captures.
8111 if (!FinishedExplicitCaptures && C->isImplicit()) {
8112 getSema().finishLambdaExplicitCaptures(LSI);
8113 FinishedExplicitCaptures = true;
8114 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008115
Douglas Gregordfca6f52012-02-13 22:00:16 +00008116 // Capturing 'this' is trivial.
8117 if (C->capturesThis()) {
8118 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8119 continue;
8120 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008121
Richard Smith0d8e9642013-05-16 06:20:58 +00008122 // Rebuild init-captures, including the implied field declaration.
8123 if (C->isInitCapture()) {
8124 ExprResult Init = InitCaptureExprs[C - E->capture_begin()];
8125 if (Init.isInvalid()) {
8126 Invalid = true;
8127 continue;
8128 }
8129 FieldDecl *OldFD = C->getInitCaptureField();
8130 FieldDecl *NewFD = getSema().checkInitCapture(
8131 C->getLocation(), OldFD->getType()->isReferenceType(),
8132 OldFD->getIdentifier(), Init.take());
8133 if (!NewFD)
8134 Invalid = true;
8135 else
8136 getDerived().transformedLocalDecl(OldFD, NewFD);
8137 continue;
8138 }
8139
8140 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8141
Douglas Gregora7365242012-02-14 19:27:52 +00008142 // Determine the capture kind for Sema.
8143 Sema::TryCaptureKind Kind
8144 = C->isImplicit()? Sema::TryCapture_Implicit
8145 : C->getCaptureKind() == LCK_ByCopy
8146 ? Sema::TryCapture_ExplicitByVal
8147 : Sema::TryCapture_ExplicitByRef;
8148 SourceLocation EllipsisLoc;
8149 if (C->isPackExpansion()) {
8150 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8151 bool ShouldExpand = false;
8152 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008153 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008154 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8155 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008156 Unexpanded,
8157 ShouldExpand, RetainExpansion,
Richard Smith0d8e9642013-05-16 06:20:58 +00008158 NumExpansions)) {
8159 Invalid = true;
8160 continue;
8161 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008162
Douglas Gregora7365242012-02-14 19:27:52 +00008163 if (ShouldExpand) {
8164 // The transform has determined that we should perform an expansion;
8165 // transform and capture each of the arguments.
8166 // expansion of the pattern. Do so.
8167 VarDecl *Pack = C->getCapturedVar();
8168 for (unsigned I = 0; I != *NumExpansions; ++I) {
8169 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8170 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008171 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008172 Pack));
8173 if (!CapturedVar) {
8174 Invalid = true;
8175 continue;
8176 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008177
Douglas Gregora7365242012-02-14 19:27:52 +00008178 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008179 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8180 }
Douglas Gregora7365242012-02-14 19:27:52 +00008181 continue;
8182 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008183
Douglas Gregora7365242012-02-14 19:27:52 +00008184 EllipsisLoc = C->getEllipsisLoc();
8185 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008186
Douglas Gregordfca6f52012-02-13 22:00:16 +00008187 // Transform the captured variable.
8188 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008189 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008190 C->getCapturedVar()));
8191 if (!CapturedVar) {
8192 Invalid = true;
8193 continue;
8194 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008195
Douglas Gregordfca6f52012-02-13 22:00:16 +00008196 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008197 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008198 }
8199 if (!FinishedExplicitCaptures)
8200 getSema().finishLambdaExplicitCaptures(LSI);
8201
Douglas Gregordfca6f52012-02-13 22:00:16 +00008202
8203 // Enter a new evaluation context to insulate the lambda from any
8204 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008205 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008206
8207 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008208 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008209 /*IsInstantiation=*/true);
8210 return ExprError();
8211 }
8212
8213 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008214 StmtResult Body = getDerived().TransformStmt(E->getBody());
8215 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008216 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008217 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008218 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008219 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008220
Chad Rosier4a9d7952012-08-08 18:46:20 +00008221 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008222 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008223}
8224
8225template<typename Derived>
8226ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008227TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008228 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008229 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8230 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008231 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008232
Douglas Gregorb98b1992009-08-11 05:31:07 +00008233 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008234 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008235 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008236 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008237 &ArgumentChanged))
8238 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008239
Douglas Gregorb98b1992009-08-11 05:31:07 +00008240 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008241 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008242 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008243 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008244
Douglas Gregorb98b1992009-08-11 05:31:07 +00008245 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008246 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008247 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008248 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008249 E->getRParenLoc());
8250}
Mike Stump1eb44332009-09-09 15:08:12 +00008251
Douglas Gregorb98b1992009-08-11 05:31:07 +00008252template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008253ExprResult
John McCall865d4472009-11-19 22:55:06 +00008254TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008255 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008256 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008257 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008258 Expr *OldBase;
8259 QualType BaseType;
8260 QualType ObjectType;
8261 if (!E->isImplicitAccess()) {
8262 OldBase = E->getBase();
8263 Base = getDerived().TransformExpr(OldBase);
8264 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008265 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008266
John McCallaa81e162009-12-01 22:10:20 +00008267 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008268 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008269 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008270 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008271 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008272 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008273 ObjectTy,
8274 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008275 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008276 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008277
John McCallb3d87482010-08-24 05:47:05 +00008278 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008279 BaseType = ((Expr*) Base.get())->getType();
8280 } else {
8281 OldBase = 0;
8282 BaseType = getDerived().TransformType(E->getBaseType());
8283 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8284 }
Mike Stump1eb44332009-09-09 15:08:12 +00008285
Douglas Gregor6cd21982009-10-20 05:58:46 +00008286 // Transform the first part of the nested-name-specifier that qualifies
8287 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008288 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008289 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008290 E->getFirstQualifierFoundInScope(),
8291 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008292
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008293 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008294 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008295 QualifierLoc
8296 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8297 ObjectType,
8298 FirstQualifierInScope);
8299 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008300 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008301 }
Mike Stump1eb44332009-09-09 15:08:12 +00008302
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008303 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8304
John McCall43fed0d2010-11-12 08:19:04 +00008305 // TODO: If this is a conversion-function-id, verify that the
8306 // destination type name (if present) resolves the same way after
8307 // instantiation as it did in the local scope.
8308
Abramo Bagnara25777432010-08-11 22:01:17 +00008309 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008310 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008311 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008312 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008313
John McCallaa81e162009-12-01 22:10:20 +00008314 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008315 // This is a reference to a member without an explicitly-specified
8316 // template argument list. Optimize for this common case.
8317 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008318 Base.get() == OldBase &&
8319 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008320 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008321 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008322 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008323 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008324
John McCall9ae2f072010-08-23 23:25:46 +00008325 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008326 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008327 E->isArrow(),
8328 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008329 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008330 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008331 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008332 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008333 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008334 }
8335
John McCalld5532b62009-11-23 01:53:49 +00008336 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008337 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8338 E->getNumTemplateArgs(),
8339 TransArgs))
8340 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008341
John McCall9ae2f072010-08-23 23:25:46 +00008342 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008343 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008344 E->isArrow(),
8345 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008346 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008347 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008348 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008349 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008350 &TransArgs);
8351}
8352
8353template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008354ExprResult
John McCall454feb92009-12-08 09:21:05 +00008355TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008356 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008357 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008358 QualType BaseType;
8359 if (!Old->isImplicitAccess()) {
8360 Base = getDerived().TransformExpr(Old->getBase());
8361 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008362 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008363 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8364 Old->isArrow());
8365 if (Base.isInvalid())
8366 return ExprError();
8367 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008368 } else {
8369 BaseType = getDerived().TransformType(Old->getBaseType());
8370 }
John McCall129e2df2009-11-30 22:42:35 +00008371
Douglas Gregor4c9be892011-02-28 20:01:57 +00008372 NestedNameSpecifierLoc QualifierLoc;
8373 if (Old->getQualifierLoc()) {
8374 QualifierLoc
8375 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8376 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008377 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008378 }
8379
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008380 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8381
Abramo Bagnara25777432010-08-11 22:01:17 +00008382 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008383 Sema::LookupOrdinaryName);
8384
8385 // Transform all the decls.
8386 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8387 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008388 NamedDecl *InstD = static_cast<NamedDecl*>(
8389 getDerived().TransformDecl(Old->getMemberLoc(),
8390 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008391 if (!InstD) {
8392 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8393 // This can happen because of dependent hiding.
8394 if (isa<UsingShadowDecl>(*I))
8395 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008396 else {
8397 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008398 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008399 }
John McCall9f54ad42009-12-10 09:41:52 +00008400 }
John McCall129e2df2009-11-30 22:42:35 +00008401
8402 // Expand using declarations.
8403 if (isa<UsingDecl>(InstD)) {
8404 UsingDecl *UD = cast<UsingDecl>(InstD);
8405 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8406 E = UD->shadow_end(); I != E; ++I)
8407 R.addDecl(*I);
8408 continue;
8409 }
8410
8411 R.addDecl(InstD);
8412 }
8413
8414 R.resolveKind();
8415
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008416 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008417 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008418 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008419 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008420 Old->getMemberLoc(),
8421 Old->getNamingClass()));
8422 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008423 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008424
Douglas Gregor66c45152010-04-27 16:10:10 +00008425 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008426 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008427
John McCall129e2df2009-11-30 22:42:35 +00008428 TemplateArgumentListInfo TransArgs;
8429 if (Old->hasExplicitTemplateArgs()) {
8430 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8431 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008432 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8433 Old->getNumTemplateArgs(),
8434 TransArgs))
8435 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008436 }
John McCallc2233c52010-01-15 08:34:02 +00008437
8438 // FIXME: to do this check properly, we will need to preserve the
8439 // first-qualifier-in-scope here, just in case we had a dependent
8440 // base (and therefore couldn't do the check) and a
8441 // nested-name-qualifier (and therefore could do the lookup).
8442 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008443
John McCall9ae2f072010-08-23 23:25:46 +00008444 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008445 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008446 Old->getOperatorLoc(),
8447 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008448 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008449 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008450 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008451 R,
8452 (Old->hasExplicitTemplateArgs()
8453 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008454}
8455
8456template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008457ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008458TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008459 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008460 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8461 if (SubExpr.isInvalid())
8462 return ExprError();
8463
8464 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008465 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008466
8467 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8468}
8469
8470template<typename Derived>
8471ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008472TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008473 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8474 if (Pattern.isInvalid())
8475 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008476
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008477 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8478 return SemaRef.Owned(E);
8479
Douglas Gregor67fd1252011-01-14 21:20:45 +00008480 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8481 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008482}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008483
8484template<typename Derived>
8485ExprResult
8486TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8487 // If E is not value-dependent, then nothing will change when we transform it.
8488 // Note: This is an instantiation-centric view.
8489 if (!E->isValueDependent())
8490 return SemaRef.Owned(E);
8491
8492 // Note: None of the implementations of TryExpandParameterPacks can ever
8493 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008494 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008495 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8496 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008497 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008498 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008499 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008500 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008501 ShouldExpand, RetainExpansion,
8502 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008503 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008504
Douglas Gregor089e8932011-10-10 18:59:29 +00008505 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008506 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008507
Douglas Gregor089e8932011-10-10 18:59:29 +00008508 NamedDecl *Pack = E->getPack();
8509 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008510 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008511 Pack));
8512 if (!Pack)
8513 return ExprError();
8514 }
8515
Chad Rosier4a9d7952012-08-08 18:46:20 +00008516
Douglas Gregoree8aff02011-01-04 17:33:58 +00008517 // We now know the length of the parameter pack, so build a new expression
8518 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008519 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8520 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008521 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008522}
8523
Douglas Gregorbe230c32011-01-03 17:17:50 +00008524template<typename Derived>
8525ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008526TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8527 SubstNonTypeTemplateParmPackExpr *E) {
8528 // Default behavior is to do nothing with this transformation.
8529 return SemaRef.Owned(E);
8530}
8531
8532template<typename Derived>
8533ExprResult
John McCall91a57552011-07-15 05:09:51 +00008534TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8535 SubstNonTypeTemplateParmExpr *E) {
8536 // Default behavior is to do nothing with this transformation.
8537 return SemaRef.Owned(E);
8538}
8539
8540template<typename Derived>
8541ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008542TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8543 // Default behavior is to do nothing with this transformation.
8544 return SemaRef.Owned(E);
8545}
8546
8547template<typename Derived>
8548ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008549TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8550 MaterializeTemporaryExpr *E) {
8551 return getDerived().TransformExpr(E->GetTemporaryExpr());
8552}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008553
Douglas Gregor03e80032011-06-21 17:03:29 +00008554template<typename Derived>
8555ExprResult
John McCall454feb92009-12-08 09:21:05 +00008556TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008557 return SemaRef.MaybeBindToTemporary(E);
8558}
8559
8560template<typename Derived>
8561ExprResult
8562TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008563 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008564}
8565
8566template<typename Derived>
8567ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008568TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8569 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8570 if (SubExpr.isInvalid())
8571 return ExprError();
8572
8573 if (!getDerived().AlwaysRebuild() &&
8574 SubExpr.get() == E->getSubExpr())
8575 return SemaRef.Owned(E);
8576
8577 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008578}
8579
8580template<typename Derived>
8581ExprResult
8582TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8583 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008584 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008585 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008586 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008587 /*IsCall=*/false, Elements, &ArgChanged))
8588 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008589
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008590 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8591 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008592
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008593 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8594 Elements.data(),
8595 Elements.size());
8596}
8597
8598template<typename Derived>
8599ExprResult
8600TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008601 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008602 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008603 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008604 bool ArgChanged = false;
8605 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8606 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008607
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008608 if (OrigElement.isPackExpansion()) {
8609 // This key/value element is a pack expansion.
8610 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8611 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8612 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8613 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8614
8615 // Determine whether the set of unexpanded parameter packs can
8616 // and should be expanded.
8617 bool Expand = true;
8618 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008619 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8620 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008621 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8622 OrigElement.Value->getLocEnd());
8623 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8624 PatternRange,
8625 Unexpanded,
8626 Expand, RetainExpansion,
8627 NumExpansions))
8628 return ExprError();
8629
8630 if (!Expand) {
8631 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008632 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008633 // expansion.
8634 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8635 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8636 if (Key.isInvalid())
8637 return ExprError();
8638
8639 if (Key.get() != OrigElement.Key)
8640 ArgChanged = true;
8641
8642 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8643 if (Value.isInvalid())
8644 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008645
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008646 if (Value.get() != OrigElement.Value)
8647 ArgChanged = true;
8648
Chad Rosier4a9d7952012-08-08 18:46:20 +00008649 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008650 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8651 };
8652 Elements.push_back(Expansion);
8653 continue;
8654 }
8655
8656 // Record right away that the argument was changed. This needs
8657 // to happen even if the array expands to nothing.
8658 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008659
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008660 // The transform has determined that we should perform an elementwise
8661 // expansion of the pattern. Do so.
8662 for (unsigned I = 0; I != *NumExpansions; ++I) {
8663 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8664 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8665 if (Key.isInvalid())
8666 return ExprError();
8667
8668 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8669 if (Value.isInvalid())
8670 return ExprError();
8671
Chad Rosier4a9d7952012-08-08 18:46:20 +00008672 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008673 Key.get(), Value.get(), SourceLocation(), NumExpansions
8674 };
8675
8676 // If any unexpanded parameter packs remain, we still have a
8677 // pack expansion.
8678 if (Key.get()->containsUnexpandedParameterPack() ||
8679 Value.get()->containsUnexpandedParameterPack())
8680 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008681
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008682 Elements.push_back(Element);
8683 }
8684
8685 // We've finished with this pack expansion.
8686 continue;
8687 }
8688
8689 // Transform and check key.
8690 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8691 if (Key.isInvalid())
8692 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008693
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008694 if (Key.get() != OrigElement.Key)
8695 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008696
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008697 // Transform and check value.
8698 ExprResult Value
8699 = getDerived().TransformExpr(OrigElement.Value);
8700 if (Value.isInvalid())
8701 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008702
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008703 if (Value.get() != OrigElement.Value)
8704 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008705
8706 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008707 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008708 };
8709 Elements.push_back(Element);
8710 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008711
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008712 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8713 return SemaRef.MaybeBindToTemporary(E);
8714
8715 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8716 Elements.data(),
8717 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008718}
8719
Mike Stump1eb44332009-09-09 15:08:12 +00008720template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008721ExprResult
John McCall454feb92009-12-08 09:21:05 +00008722TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008723 TypeSourceInfo *EncodedTypeInfo
8724 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8725 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008726 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008727
Douglas Gregorb98b1992009-08-11 05:31:07 +00008728 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008729 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008730 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008731
8732 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008733 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008734 E->getRParenLoc());
8735}
Mike Stump1eb44332009-09-09 15:08:12 +00008736
Douglas Gregorb98b1992009-08-11 05:31:07 +00008737template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008738ExprResult TreeTransform<Derived>::
8739TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00008740 // This is a kind of implicit conversion, and it needs to get dropped
8741 // and recomputed for the same general reasons that ImplicitCastExprs
8742 // do, as well a more specific one: this expression is only valid when
8743 // it appears *immediately* as an argument expression.
8744 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00008745}
8746
8747template<typename Derived>
8748ExprResult TreeTransform<Derived>::
8749TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008750 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008751 = getDerived().TransformType(E->getTypeInfoAsWritten());
8752 if (!TSInfo)
8753 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008754
John McCallf85e1932011-06-15 23:02:42 +00008755 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008756 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008757 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008758
John McCallf85e1932011-06-15 23:02:42 +00008759 if (!getDerived().AlwaysRebuild() &&
8760 TSInfo == E->getTypeInfoAsWritten() &&
8761 Result.get() == E->getSubExpr())
8762 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008763
John McCallf85e1932011-06-15 23:02:42 +00008764 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008765 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008766 Result.get());
8767}
8768
8769template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008770ExprResult
John McCall454feb92009-12-08 09:21:05 +00008771TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008772 // Transform arguments.
8773 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008774 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008775 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008776 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008777 &ArgChanged))
8778 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008779
Douglas Gregor92e986e2010-04-22 16:44:27 +00008780 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8781 // Class message: transform the receiver type.
8782 TypeSourceInfo *ReceiverTypeInfo
8783 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8784 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008785 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008786
Douglas Gregor92e986e2010-04-22 16:44:27 +00008787 // If nothing changed, just retain the existing message send.
8788 if (!getDerived().AlwaysRebuild() &&
8789 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008790 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008791
8792 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008793 SmallVector<SourceLocation, 16> SelLocs;
8794 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008795 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8796 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008797 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008798 E->getMethodDecl(),
8799 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008800 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008801 E->getRightLoc());
8802 }
8803
8804 // Instance message: transform the receiver
8805 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8806 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008807 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008808 = getDerived().TransformExpr(E->getInstanceReceiver());
8809 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008810 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008811
8812 // If nothing changed, just retain the existing message send.
8813 if (!getDerived().AlwaysRebuild() &&
8814 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008815 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008816
Douglas Gregor92e986e2010-04-22 16:44:27 +00008817 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008818 SmallVector<SourceLocation, 16> SelLocs;
8819 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008820 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008821 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008822 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008823 E->getMethodDecl(),
8824 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008825 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008826 E->getRightLoc());
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
John McCall454feb92009-12-08 09:21:05 +00008831TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008832 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008833}
8834
Mike Stump1eb44332009-09-09 15:08:12 +00008835template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008836ExprResult
John McCall454feb92009-12-08 09:21:05 +00008837TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008838 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008839}
8840
Mike Stump1eb44332009-09-09 15:08:12 +00008841template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008842ExprResult
John McCall454feb92009-12-08 09:21:05 +00008843TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008844 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008845 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008846 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008847 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008848
8849 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008850
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008851 // If nothing changed, just retain the existing expression.
8852 if (!getDerived().AlwaysRebuild() &&
8853 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008854 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008855
John McCall9ae2f072010-08-23 23:25:46 +00008856 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008857 E->getLocation(),
8858 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008859}
8860
Mike Stump1eb44332009-09-09 15:08:12 +00008861template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008862ExprResult
John McCall454feb92009-12-08 09:21:05 +00008863TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008864 // 'super' and types never change. Property never changes. Just
8865 // retain the existing expression.
8866 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008867 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008868
Douglas Gregore3303542010-04-26 20:47:02 +00008869 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008870 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008871 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008872 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008873
Douglas Gregore3303542010-04-26 20:47:02 +00008874 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008875
Douglas Gregore3303542010-04-26 20:47:02 +00008876 // If nothing changed, just retain the existing expression.
8877 if (!getDerived().AlwaysRebuild() &&
8878 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008879 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008880
John McCall12f78a62010-12-02 01:19:52 +00008881 if (E->isExplicitProperty())
8882 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8883 E->getExplicitProperty(),
8884 E->getLocation());
8885
8886 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008887 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008888 E->getImplicitPropertyGetter(),
8889 E->getImplicitPropertySetter(),
8890 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008891}
8892
Mike Stump1eb44332009-09-09 15:08:12 +00008893template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008894ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008895TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8896 // Transform the base expression.
8897 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8898 if (Base.isInvalid())
8899 return ExprError();
8900
8901 // Transform the key expression.
8902 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8903 if (Key.isInvalid())
8904 return ExprError();
8905
8906 // If nothing changed, just retain the existing expression.
8907 if (!getDerived().AlwaysRebuild() &&
8908 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8909 return SemaRef.Owned(E);
8910
Chad Rosier4a9d7952012-08-08 18:46:20 +00008911 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008912 Base.get(), Key.get(),
8913 E->getAtIndexMethodDecl(),
8914 E->setAtIndexMethodDecl());
8915}
8916
8917template<typename Derived>
8918ExprResult
John McCall454feb92009-12-08 09:21:05 +00008919TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008920 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008921 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008922 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008923 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008924
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008925 // If nothing changed, just retain the existing expression.
8926 if (!getDerived().AlwaysRebuild() &&
8927 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008928 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008929
John McCall9ae2f072010-08-23 23:25:46 +00008930 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00008931 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008932 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008933}
8934
Mike Stump1eb44332009-09-09 15:08:12 +00008935template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008936ExprResult
John McCall454feb92009-12-08 09:21:05 +00008937TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008938 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008939 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008940 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008941 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008942 SubExprs, &ArgumentChanged))
8943 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008944
Douglas Gregorb98b1992009-08-11 05:31:07 +00008945 if (!getDerived().AlwaysRebuild() &&
8946 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008947 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008948
Douglas Gregorb98b1992009-08-11 05:31:07 +00008949 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008950 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008951 E->getRParenLoc());
8952}
8953
Mike Stump1eb44332009-09-09 15:08:12 +00008954template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008955ExprResult
John McCall454feb92009-12-08 09:21:05 +00008956TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008957 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008958
John McCallc6ac9c32011-02-04 18:33:18 +00008959 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8960 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8961
8962 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008963 blockScope->TheDecl->setBlockMissingReturnType(
8964 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008965
Chris Lattner686775d2011-07-20 06:58:45 +00008966 SmallVector<ParmVarDecl*, 4> params;
8967 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008968
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008969 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008970 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8971 oldBlock->param_begin(),
8972 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008973 0, paramTypes, &params)) {
8974 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008975 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008976 }
John McCallc6ac9c32011-02-04 18:33:18 +00008977
Jordan Rose09189892013-03-08 22:25:36 +00008978 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008979 QualType exprResultType =
8980 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008981
8982 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008983 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008984 getSema().Diag(E->getCaretLocation(),
8985 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008986 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008987 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008988 return ExprError();
8989 }
John McCall711c52b2011-01-05 12:14:39 +00008990
Jordan Rosebea522f2013-03-08 21:51:21 +00008991 QualType functionType =
8992 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00008993 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00008994 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008995
8996 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008997 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008998 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008999
9000 if (!oldBlock->blockMissingReturnType()) {
9001 blockScope->HasImplicitReturnType = false;
9002 blockScope->ReturnType = exprResultType;
9003 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009004
John McCall711c52b2011-01-05 12:14:39 +00009005 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00009006 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009007 if (body.isInvalid()) {
9008 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00009009 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009010 }
John McCall711c52b2011-01-05 12:14:39 +00009011
John McCallc6ac9c32011-02-04 18:33:18 +00009012#ifndef NDEBUG
9013 // In builds with assertions, make sure that we captured everything we
9014 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00009015 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9016 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9017 e = oldBlock->capture_end(); i != e; ++i) {
9018 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00009019
Douglas Gregorfc921372011-05-20 15:32:55 +00009020 // Ignore parameter packs.
9021 if (isa<ParmVarDecl>(oldCapture) &&
9022 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9023 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00009024
Douglas Gregorfc921372011-05-20 15:32:55 +00009025 VarDecl *newCapture =
9026 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9027 oldCapture));
9028 assert(blockScope->CaptureMap.count(newCapture));
9029 }
Douglas Gregorec79d872012-02-24 17:41:38 +00009030 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00009031 }
9032#endif
9033
9034 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9035 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009036}
9037
Mike Stump1eb44332009-09-09 15:08:12 +00009038template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009039ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009040TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00009041 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009042}
Eli Friedman276b0612011-10-11 02:20:01 +00009043
9044template<typename Derived>
9045ExprResult
9046TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009047 QualType RetTy = getDerived().TransformType(E->getType());
9048 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009049 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009050 SubExprs.reserve(E->getNumSubExprs());
9051 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9052 SubExprs, &ArgumentChanged))
9053 return ExprError();
9054
9055 if (!getDerived().AlwaysRebuild() &&
9056 !ArgumentChanged)
9057 return SemaRef.Owned(E);
9058
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009059 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009060 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00009061}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009062
Douglas Gregorb98b1992009-08-11 05:31:07 +00009063//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00009064// Type reconstruction
9065//===----------------------------------------------------------------------===//
9066
Mike Stump1eb44332009-09-09 15:08:12 +00009067template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009068QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9069 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009070 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009071 getDerived().getBaseEntity());
9072}
9073
Mike Stump1eb44332009-09-09 15:08:12 +00009074template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009075QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9076 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009077 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009078 getDerived().getBaseEntity());
9079}
9080
Mike Stump1eb44332009-09-09 15:08:12 +00009081template<typename Derived>
9082QualType
John McCall85737a72009-10-30 00:06:24 +00009083TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9084 bool WrittenAsLValue,
9085 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009086 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009087 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009088}
9089
9090template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009091QualType
John McCall85737a72009-10-30 00:06:24 +00009092TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9093 QualType ClassType,
9094 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009095 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009096 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009097}
9098
9099template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009100QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009101TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9102 ArrayType::ArraySizeModifier SizeMod,
9103 const llvm::APInt *Size,
9104 Expr *SizeExpr,
9105 unsigned IndexTypeQuals,
9106 SourceRange BracketsRange) {
9107 if (SizeExpr || !Size)
9108 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9109 IndexTypeQuals, BracketsRange,
9110 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009111
9112 QualType Types[] = {
9113 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9114 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9115 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009116 };
9117 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
9118 QualType SizeType;
9119 for (unsigned I = 0; I != NumTypes; ++I)
9120 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9121 SizeType = Types[I];
9122 break;
9123 }
Mike Stump1eb44332009-09-09 15:08:12 +00009124
Eli Friedman01f276d2012-01-25 23:20:27 +00009125 // Note that we can return a VariableArrayType here in the case where
9126 // the element type was a dependent VariableArrayType.
9127 IntegerLiteral *ArraySize
9128 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9129 /*FIXME*/BracketsRange.getBegin());
9130 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009131 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009132 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009133}
Mike Stump1eb44332009-09-09 15:08:12 +00009134
Douglas Gregor577f75a2009-08-04 16:50:30 +00009135template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009136QualType
9137TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009138 ArrayType::ArraySizeModifier SizeMod,
9139 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009140 unsigned IndexTypeQuals,
9141 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009142 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009143 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009144}
9145
9146template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009147QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009148TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009149 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009150 unsigned IndexTypeQuals,
9151 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009152 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009153 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009154}
Mike Stump1eb44332009-09-09 15:08:12 +00009155
Douglas Gregor577f75a2009-08-04 16:50:30 +00009156template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009157QualType
9158TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009159 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009160 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009161 unsigned IndexTypeQuals,
9162 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009163 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009164 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009165 IndexTypeQuals, BracketsRange);
9166}
9167
9168template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009169QualType
9170TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009171 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009172 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009173 unsigned IndexTypeQuals,
9174 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009175 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009176 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009177 IndexTypeQuals, BracketsRange);
9178}
9179
9180template<typename Derived>
9181QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009182 unsigned NumElements,
9183 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009184 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009185 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009186}
Mike Stump1eb44332009-09-09 15:08:12 +00009187
Douglas Gregor577f75a2009-08-04 16:50:30 +00009188template<typename Derived>
9189QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9190 unsigned NumElements,
9191 SourceLocation AttributeLoc) {
9192 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9193 NumElements, true);
9194 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009195 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9196 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009197 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009198}
Mike Stump1eb44332009-09-09 15:08:12 +00009199
Douglas Gregor577f75a2009-08-04 16:50:30 +00009200template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009201QualType
9202TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009203 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009204 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009205 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009206}
Mike Stump1eb44332009-09-09 15:08:12 +00009207
Douglas Gregor577f75a2009-08-04 16:50:30 +00009208template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009209QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9210 QualType T,
9211 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009212 const FunctionProtoType::ExtProtoInfo &EPI) {
9213 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009214 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009215 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009216 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009217}
Mike Stump1eb44332009-09-09 15:08:12 +00009218
Douglas Gregor577f75a2009-08-04 16:50:30 +00009219template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009220QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9221 return SemaRef.Context.getFunctionNoProtoType(T);
9222}
9223
9224template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009225QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9226 assert(D && "no decl found");
9227 if (D->isInvalidDecl()) return QualType();
9228
Douglas Gregor92e986e2010-04-22 16:44:27 +00009229 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009230 TypeDecl *Ty;
9231 if (isa<UsingDecl>(D)) {
9232 UsingDecl *Using = cast<UsingDecl>(D);
9233 assert(Using->isTypeName() &&
9234 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9235
9236 // A valid resolved using typename decl points to exactly one type decl.
9237 assert(++Using->shadow_begin() == Using->shadow_end());
9238 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009239
John McCalled976492009-12-04 22:46:56 +00009240 } else {
9241 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9242 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9243 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9244 }
9245
9246 return SemaRef.Context.getTypeDeclType(Ty);
9247}
9248
9249template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009250QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9251 SourceLocation Loc) {
9252 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009253}
9254
9255template<typename Derived>
9256QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9257 return SemaRef.Context.getTypeOfType(Underlying);
9258}
9259
9260template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009261QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9262 SourceLocation Loc) {
9263 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009264}
9265
9266template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009267QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9268 UnaryTransformType::UTTKind UKind,
9269 SourceLocation Loc) {
9270 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9271}
9272
9273template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009274QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009275 TemplateName Template,
9276 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009277 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009278 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009279}
Mike Stump1eb44332009-09-09 15:08:12 +00009280
Douglas Gregordcee1a12009-08-06 05:28:30 +00009281template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009282QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9283 SourceLocation KWLoc) {
9284 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9285}
9286
9287template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009288TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009289TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009290 bool TemplateKW,
9291 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009292 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009293 Template);
9294}
9295
9296template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009297TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009298TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9299 const IdentifierInfo &Name,
9300 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009301 QualType ObjectType,
9302 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009303 UnqualifiedId TemplateName;
9304 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009305 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009306 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009307 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009308 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009309 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009310 /*EnteringContext=*/false,
9311 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009312 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009313}
Mike Stump1eb44332009-09-09 15:08:12 +00009314
Douglas Gregorb98b1992009-08-11 05:31:07 +00009315template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009316TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009317TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009318 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009319 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009320 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009321 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009322 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009323 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009324 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009325 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009326 Sema::TemplateTy Template;
9327 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009328 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009329 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009330 /*EnteringContext=*/false,
9331 Template);
9332 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009333}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009334
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009335template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009336ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009337TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9338 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009339 Expr *OrigCallee,
9340 Expr *First,
9341 Expr *Second) {
9342 Expr *Callee = OrigCallee->IgnoreParenCasts();
9343 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009344
Douglas Gregorb98b1992009-08-11 05:31:07 +00009345 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009346 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009347 if (!First->getType()->isOverloadableType() &&
9348 !Second->getType()->isOverloadableType())
9349 return getSema().CreateBuiltinArraySubscriptExpr(First,
9350 Callee->getLocStart(),
9351 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009352 } else if (Op == OO_Arrow) {
9353 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009354 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9355 } else if (Second == 0 || isPostIncDec) {
9356 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009357 // The argument is not of overloadable type, so try to create a
9358 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009359 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009360 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009361
John McCall9ae2f072010-08-23 23:25:46 +00009362 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009363 }
9364 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009365 if (!First->getType()->isOverloadableType() &&
9366 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009367 // Neither of the arguments is an overloadable type, so try to
9368 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009369 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009370 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009371 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009372 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009373 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009374
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009375 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009376 }
9377 }
Mike Stump1eb44332009-09-09 15:08:12 +00009378
9379 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009380 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009381 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009382
John McCall9ae2f072010-08-23 23:25:46 +00009383 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009384 assert(ULE->requiresADL());
9385
9386 // FIXME: Do we have to check
9387 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009388 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009389 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009390 // If we've resolved this to a particular non-member function, just call
9391 // that function. If we resolved it to a member function,
9392 // CreateOverloaded* will find that function for us.
9393 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9394 if (!isa<CXXMethodDecl>(ND))
9395 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009396 }
Mike Stump1eb44332009-09-09 15:08:12 +00009397
Douglas Gregorb98b1992009-08-11 05:31:07 +00009398 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009399 Expr *Args[2] = { First, Second };
9400 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009401
Douglas Gregorb98b1992009-08-11 05:31:07 +00009402 // Create the overloaded operator invocation for unary operators.
9403 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009404 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009405 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009406 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009407 }
Mike Stump1eb44332009-09-09 15:08:12 +00009408
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009409 if (Op == OO_Subscript) {
9410 SourceLocation LBrace;
9411 SourceLocation RBrace;
9412
9413 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9414 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9415 LBrace = SourceLocation::getFromRawEncoding(
9416 NameLoc.CXXOperatorName.BeginOpNameLoc);
9417 RBrace = SourceLocation::getFromRawEncoding(
9418 NameLoc.CXXOperatorName.EndOpNameLoc);
9419 } else {
9420 LBrace = Callee->getLocStart();
9421 RBrace = OpLoc;
9422 }
9423
9424 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9425 First, Second);
9426 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009427
Douglas Gregorb98b1992009-08-11 05:31:07 +00009428 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009429 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009430 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009431 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9432 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009433 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009434
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009435 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009436}
Mike Stump1eb44332009-09-09 15:08:12 +00009437
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009438template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009439ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009440TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009441 SourceLocation OperatorLoc,
9442 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009443 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009444 TypeSourceInfo *ScopeType,
9445 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009446 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009447 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009448 QualType BaseType = Base->getType();
9449 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009450 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009451 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009452 !BaseType->getAs<PointerType>()->getPointeeType()
9453 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009454 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009455 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009456 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009457 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009458 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009459 /*FIXME?*/true);
9460 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009461
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009462 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009463 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9464 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9465 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9466 NameInfo.setNamedTypeInfo(DestroyedType);
9467
Richard Smith6314db92012-05-15 06:15:11 +00009468 // The scope type is now known to be a valid nested name specifier
9469 // component. Tack it on to the end of the nested name specifier.
9470 if (ScopeType)
9471 SS.Extend(SemaRef.Context, SourceLocation(),
9472 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009473
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009474 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009475 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009476 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009477 SS, TemplateKWLoc,
9478 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009479 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009480 /*TemplateArgs*/ 0);
9481}
9482
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009483template<typename Derived>
9484StmtResult
9485TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan9fd6b8f2013-05-04 03:59:06 +00009486 SourceLocation Loc = S->getLocStart();
9487 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9488 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9489 S->getCapturedRegionKind(), NumParams);
9490 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9491
9492 if (Body.isInvalid()) {
9493 getSema().ActOnCapturedRegionError();
9494 return StmtError();
9495 }
9496
9497 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009498}
9499
Douglas Gregor577f75a2009-08-04 16:50:30 +00009500} // end namespace clang
9501
9502#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H