blob: 5b4716f5be2e0497a20f70e9321f46935721eef5 [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.
Rafael Espindola4549d7f2013-07-09 12:05:01 +00001166 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1167 SourceLocation StartLoc, SourceLocation EndLoc) {
1168 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith406c38e2011-02-23 00:37:57 +00001169 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001170 }
Mike Stump1eb44332009-09-09 15:08:12 +00001171
Anders Carlsson703e3942010-01-24 05:50:09 +00001172 /// \brief Build a new inline asm statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001176 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1177 bool IsVolatile, unsigned NumOutputs,
1178 unsigned NumInputs, IdentifierInfo **Names,
1179 MultiExprArg Constraints, MultiExprArg Exprs,
1180 Expr *AsmString, MultiExprArg Clobbers,
1181 SourceLocation RParenLoc) {
1182 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1183 NumInputs, Names, Constraints, Exprs,
1184 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001185 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001186
Chad Rosier8cd64b42012-06-11 20:47:18 +00001187 /// \brief Build a new MS style inline asm statement.
1188 ///
1189 /// By default, performs semantic analysis to build the new statement.
1190 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001191 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallaeeacf72013-05-03 00:10:13 +00001192 ArrayRef<Token> AsmToks,
1193 StringRef AsmString,
1194 unsigned NumOutputs, unsigned NumInputs,
1195 ArrayRef<StringRef> Constraints,
1196 ArrayRef<StringRef> Clobbers,
1197 ArrayRef<Expr*> Exprs,
1198 SourceLocation EndLoc) {
1199 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1200 NumOutputs, NumInputs,
1201 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001202 }
1203
James Dennett699c9042012-06-15 07:13:21 +00001204 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001205 ///
1206 /// By default, performs semantic analysis to build the new statement.
1207 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001208 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001209 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001210 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001211 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001212 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001213 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001214 }
1215
Douglas Gregorbe270a02010-04-26 17:57:08 +00001216 /// \brief Rebuild an Objective-C exception declaration.
1217 ///
1218 /// By default, performs semantic analysis to build the new declaration.
1219 /// Subclasses may override this routine to provide different behavior.
1220 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1221 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001222 return getSema().BuildObjCExceptionDecl(TInfo, T,
1223 ExceptionDecl->getInnerLocStart(),
1224 ExceptionDecl->getLocation(),
1225 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001226 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001227
James Dennett699c9042012-06-15 07:13:21 +00001228 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001229 ///
1230 /// By default, performs semantic analysis to build the new statement.
1231 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001232 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001233 SourceLocation RParenLoc,
1234 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001235 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001236 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001237 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001238 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001239
James Dennett699c9042012-06-15 07:13:21 +00001240 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001241 ///
1242 /// By default, performs semantic analysis to build the new statement.
1243 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001244 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001245 Stmt *Body) {
1246 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001247 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001248
James Dennett699c9042012-06-15 07:13:21 +00001249 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001250 ///
1251 /// By default, performs semantic analysis to build the new statement.
1252 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001253 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001254 Expr *Operand) {
1255 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001256 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001257
James Dennett699c9042012-06-15 07:13:21 +00001258 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001259 ///
1260 /// By default, performs semantic analysis to build the new statement.
1261 /// Subclasses may override this routine to provide different behavior.
1262 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1263 Expr *object) {
1264 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1265 }
1266
James Dennett699c9042012-06-15 07:13:21 +00001267 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001268 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001269 /// By default, performs semantic analysis to build the new statement.
1270 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001271 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001272 Expr *Object, Stmt *Body) {
1273 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001274 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001275
James Dennett699c9042012-06-15 07:13:21 +00001276 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001277 ///
1278 /// By default, performs semantic analysis to build the new statement.
1279 /// Subclasses may override this routine to provide different behavior.
1280 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1281 Stmt *Body) {
1282 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1283 }
John McCall990567c2011-07-27 01:07:15 +00001284
Douglas Gregorc3203e72010-04-22 23:10:45 +00001285 /// \brief Build a new Objective-C fast enumeration statement.
1286 ///
1287 /// By default, performs semantic analysis to build the new statement.
1288 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001289 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001290 Stmt *Element,
1291 Expr *Collection,
1292 SourceLocation RParenLoc,
1293 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001294 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001295 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001296 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001297 RParenLoc);
1298 if (ForEachStmt.isInvalid())
1299 return StmtError();
1300
1301 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001302 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001303
Douglas Gregor43959a92009-08-20 07:17:43 +00001304 /// \brief Build a new C++ exception declaration.
1305 ///
1306 /// By default, performs semantic analysis to build the new decaration.
1307 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001308 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001309 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001310 SourceLocation StartLoc,
1311 SourceLocation IdLoc,
1312 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001313 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1314 StartLoc, IdLoc, Id);
1315 if (Var)
1316 getSema().CurContext->addDecl(Var);
1317 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001318 }
1319
1320 /// \brief Build a new C++ catch statement.
1321 ///
1322 /// By default, performs semantic analysis to build the new statement.
1323 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001324 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001325 VarDecl *ExceptionDecl,
1326 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001327 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1328 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001329 }
Mike Stump1eb44332009-09-09 15:08:12 +00001330
Douglas Gregor43959a92009-08-20 07:17:43 +00001331 /// \brief Build a new C++ try statement.
1332 ///
1333 /// By default, performs semantic analysis to build the new statement.
1334 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001335 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001336 Stmt *TryBlock,
1337 MultiStmtArg Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001338 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001339 }
Mike Stump1eb44332009-09-09 15:08:12 +00001340
Richard Smithad762fc2011-04-14 22:09:26 +00001341 /// \brief Build a new C++0x range-based for statement.
1342 ///
1343 /// By default, performs semantic analysis to build the new statement.
1344 /// Subclasses may override this routine to provide different behavior.
1345 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1346 SourceLocation ColonLoc,
1347 Stmt *Range, Stmt *BeginEnd,
1348 Expr *Cond, Expr *Inc,
1349 Stmt *LoopVar,
1350 SourceLocation RParenLoc) {
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001351 // If we've just learned that the range is actually an Objective-C
1352 // collection, treat this as an Objective-C fast enumeration loop.
1353 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1354 if (RangeStmt->isSingleDecl()) {
1355 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39b60dc2013-05-02 18:35:56 +00001356 if (RangeVar->isInvalidDecl())
1357 return StmtError();
1358
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001359 Expr *RangeExpr = RangeVar->getInit();
1360 if (!RangeExpr->isTypeDependent() &&
1361 RangeExpr->getType()->isObjCObjectPointerType())
1362 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1363 RParenLoc);
1364 }
1365 }
1366 }
1367
Richard Smithad762fc2011-04-14 22:09:26 +00001368 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001369 Cond, Inc, LoopVar, RParenLoc,
1370 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001371 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001372
1373 /// \brief Build a new C++0x range-based for statement.
1374 ///
1375 /// By default, performs semantic analysis to build the new statement.
1376 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001377 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001378 bool IsIfExists,
1379 NestedNameSpecifierLoc QualifierLoc,
1380 DeclarationNameInfo NameInfo,
1381 Stmt *Nested) {
1382 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1383 QualifierLoc, NameInfo, Nested);
1384 }
1385
Richard Smithad762fc2011-04-14 22:09:26 +00001386 /// \brief Attach body to a C++0x range-based for statement.
1387 ///
1388 /// By default, performs semantic analysis to finish the new statement.
1389 /// Subclasses may override this routine to provide different behavior.
1390 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1391 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1392 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001393
John Wiegley28bbe4b2011-04-28 01:08:34 +00001394 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1395 SourceLocation TryLoc,
1396 Stmt *TryBlock,
1397 Stmt *Handler) {
1398 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1399 }
1400
1401 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1402 Expr *FilterExpr,
1403 Stmt *Block) {
1404 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1405 }
1406
1407 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1408 Stmt *Block) {
1409 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1410 }
1411
Douglas Gregorb98b1992009-08-11 05:31:07 +00001412 /// \brief Build a new expression that references a declaration.
1413 ///
1414 /// By default, performs semantic analysis to build the new expression.
1415 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001416 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001417 LookupResult &R,
1418 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001419 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1420 }
1421
1422
1423 /// \brief Build a new expression that references a declaration.
1424 ///
1425 /// By default, performs semantic analysis to build the new expression.
1426 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001427 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001428 ValueDecl *VD,
1429 const DeclarationNameInfo &NameInfo,
1430 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001431 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001432 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001433
1434 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001435
1436 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001437 }
Mike Stump1eb44332009-09-09 15:08:12 +00001438
Douglas Gregorb98b1992009-08-11 05:31:07 +00001439 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001440 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001441 /// By default, performs semantic analysis to build the new expression.
1442 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001443 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001444 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001445 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001446 }
1447
Douglas Gregora71d8192009-09-04 17:36:40 +00001448 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001449 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001450 /// By default, performs semantic analysis to build the new expression.
1451 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001452 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001453 SourceLocation OperatorLoc,
1454 bool isArrow,
1455 CXXScopeSpec &SS,
1456 TypeSourceInfo *ScopeType,
1457 SourceLocation CCLoc,
1458 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001459 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001460
Douglas Gregorb98b1992009-08-11 05:31:07 +00001461 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001462 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001463 /// By default, performs semantic analysis to build the new expression.
1464 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001465 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001466 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001467 Expr *SubExpr) {
1468 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001469 }
Mike Stump1eb44332009-09-09 15:08:12 +00001470
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001471 /// \brief Build a new builtin offsetof expression.
1472 ///
1473 /// By default, performs semantic analysis to build the new expression.
1474 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001475 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001476 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001477 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001478 unsigned NumComponents,
1479 SourceLocation RParenLoc) {
1480 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1481 NumComponents, RParenLoc);
1482 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001483
1484 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001485 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001486 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001487 /// By default, performs semantic analysis to build the new expression.
1488 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001489 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1490 SourceLocation OpLoc,
1491 UnaryExprOrTypeTrait ExprKind,
1492 SourceRange R) {
1493 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001494 }
1495
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001496 /// \brief Build a new sizeof, alignof or vec step expression with an
1497 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001498 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001499 /// By default, performs semantic analysis to build the new expression.
1500 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001501 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1502 UnaryExprOrTypeTrait ExprKind,
1503 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001504 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001505 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001506 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001507 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001508
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001509 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001510 }
Mike Stump1eb44332009-09-09 15:08:12 +00001511
Douglas Gregorb98b1992009-08-11 05:31:07 +00001512 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001513 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001514 /// By default, performs semantic analysis to build the new expression.
1515 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001516 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001517 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001518 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001519 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001520 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1521 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001522 RBracketLoc);
1523 }
1524
1525 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001526 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001527 /// By default, performs semantic analysis to build the new expression.
1528 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001529 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001530 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001531 SourceLocation RParenLoc,
1532 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001533 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001534 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001535 }
1536
1537 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001538 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001539 /// By default, performs semantic analysis to build the new expression.
1540 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001541 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001542 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001543 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001544 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001545 const DeclarationNameInfo &MemberNameInfo,
1546 ValueDecl *Member,
1547 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001548 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001549 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001550 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1551 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001552 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001553 // We have a reference to an unnamed field. This is always the
1554 // base of an anonymous struct/union member access, i.e. the
1555 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001556 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001557 assert(Member->getType()->isRecordType() &&
1558 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001559
Richard Smith9138b4e2011-10-26 19:06:56 +00001560 BaseResult =
1561 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001562 QualifierLoc.getNestedNameSpecifier(),
1563 FoundDecl, Member);
1564 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001565 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001566 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001567 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001568 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001569 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001570 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001571 cast<FieldDecl>(Member)->getType(),
1572 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001573 return getSema().Owned(ME);
1574 }
Mike Stump1eb44332009-09-09 15:08:12 +00001575
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001576 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001577 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001578
John Wiegley429bb272011-04-08 18:41:53 +00001579 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001580 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001581
John McCall6bb80172010-03-30 21:47:33 +00001582 // FIXME: this involves duplicating earlier analysis in a lot of
1583 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001584 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001585 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001586 R.resolveKind();
1587
John McCall9ae2f072010-08-23 23:25:46 +00001588 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001589 SS, TemplateKWLoc,
1590 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001591 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 }
Mike Stump1eb44332009-09-09 15:08:12 +00001593
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001595 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001598 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001599 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001600 Expr *LHS, Expr *RHS) {
1601 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 }
1603
1604 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001605 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001606 /// By default, performs semantic analysis to build the new expression.
1607 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001608 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001609 SourceLocation QuestionLoc,
1610 Expr *LHS,
1611 SourceLocation ColonLoc,
1612 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001613 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1614 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001615 }
1616
Douglas Gregorb98b1992009-08-11 05:31:07 +00001617 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001618 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001619 /// By default, performs semantic analysis to build the new expression.
1620 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001621 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001622 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001623 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001624 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001625 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001626 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001627 }
Mike Stump1eb44332009-09-09 15:08:12 +00001628
Douglas Gregorb98b1992009-08-11 05:31:07 +00001629 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001630 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001631 /// By default, performs semantic analysis to build the new expression.
1632 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001633 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001634 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001635 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001636 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001637 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001638 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001639 }
Mike Stump1eb44332009-09-09 15:08:12 +00001640
Douglas Gregorb98b1992009-08-11 05:31:07 +00001641 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001642 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001643 /// By default, performs semantic analysis to build the new expression.
1644 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001645 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 SourceLocation OpLoc,
1647 SourceLocation AccessorLoc,
1648 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001649
John McCall129e2df2009-11-30 22:42:35 +00001650 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001651 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001652 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001653 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001654 SS, SourceLocation(),
1655 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001656 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001657 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 }
Mike Stump1eb44332009-09-09 15:08:12 +00001659
Douglas Gregorb98b1992009-08-11 05:31:07 +00001660 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001661 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001662 /// By default, performs semantic analysis to build the new expression.
1663 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001664 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001665 MultiExprArg Inits,
1666 SourceLocation RBraceLoc,
1667 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001668 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001669 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001670 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001671 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001672
Douglas Gregore48319a2009-11-09 17:16:50 +00001673 // Patch in the result type we were given, which may have been computed
1674 // when the initial InitListExpr was built.
1675 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1676 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001677 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001678 }
Mike Stump1eb44332009-09-09 15:08:12 +00001679
Douglas Gregorb98b1992009-08-11 05:31:07 +00001680 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001681 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001682 /// By default, performs semantic analysis to build the new expression.
1683 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001684 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001685 MultiExprArg ArrayExprs,
1686 SourceLocation EqualOrColonLoc,
1687 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001688 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001689 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001690 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001691 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001692 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001693 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001694
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001695 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 }
Mike Stump1eb44332009-09-09 15:08:12 +00001697
Douglas Gregorb98b1992009-08-11 05:31:07 +00001698 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001699 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 /// By default, builds the implicit value initialization without performing
1701 /// any semantic analysis. Subclasses may override this routine to provide
1702 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001703 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1705 }
Mike Stump1eb44332009-09-09 15:08:12 +00001706
Douglas Gregorb98b1992009-08-11 05:31:07 +00001707 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001708 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001709 /// By default, performs semantic analysis to build the new expression.
1710 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001711 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001712 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001713 SourceLocation RParenLoc) {
1714 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001715 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001716 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717 }
1718
1719 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001720 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001721 /// By default, performs semantic analysis to build the new expression.
1722 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001723 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001724 MultiExprArg SubExprs,
1725 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001726 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001727 }
Mike Stump1eb44332009-09-09 15:08:12 +00001728
Douglas Gregorb98b1992009-08-11 05:31:07 +00001729 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001730 ///
1731 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001732 /// rather than attempting to map the label statement itself.
1733 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001734 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001735 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001736 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001737 }
Mike Stump1eb44332009-09-09 15:08:12 +00001738
Douglas Gregorb98b1992009-08-11 05:31:07 +00001739 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001740 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001741 /// By default, performs semantic analysis to build the new expression.
1742 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001743 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001744 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001745 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001746 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001747 }
Mike Stump1eb44332009-09-09 15:08:12 +00001748
Douglas Gregorb98b1992009-08-11 05:31:07 +00001749 /// \brief Build a new __builtin_choose_expr expression.
1750 ///
1751 /// By default, performs semantic analysis to build the new expression.
1752 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001753 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001754 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 SourceLocation RParenLoc) {
1756 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001757 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001758 RParenLoc);
1759 }
Mike Stump1eb44332009-09-09 15:08:12 +00001760
Peter Collingbournef111d932011-04-15 00:35:48 +00001761 /// \brief Build a new generic selection expression.
1762 ///
1763 /// By default, performs semantic analysis to build the new expression.
1764 /// Subclasses may override this routine to provide different behavior.
1765 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1766 SourceLocation DefaultLoc,
1767 SourceLocation RParenLoc,
1768 Expr *ControllingExpr,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001769 ArrayRef<TypeSourceInfo *> Types,
1770 ArrayRef<Expr *> Exprs) {
Peter Collingbournef111d932011-04-15 00:35:48 +00001771 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001772 ControllingExpr, Types, Exprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00001773 }
1774
Douglas Gregorb98b1992009-08-11 05:31:07 +00001775 /// \brief Build a new overloaded operator call expression.
1776 ///
1777 /// By default, performs semantic analysis to build the new expression.
1778 /// The semantic analysis provides the behavior of template instantiation,
1779 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001780 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781 /// argument-dependent lookup, etc. Subclasses may override this routine to
1782 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001783 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001784 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001785 Expr *Callee,
1786 Expr *First,
1787 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001788
1789 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001790 /// reinterpret_cast.
1791 ///
1792 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001793 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001794 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001795 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001796 Stmt::StmtClass Class,
1797 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001798 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 SourceLocation RAngleLoc,
1800 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001801 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001802 SourceLocation RParenLoc) {
1803 switch (Class) {
1804 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001805 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001806 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001807 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001808
1809 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001810 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001811 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001812 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001813
Douglas Gregorb98b1992009-08-11 05:31:07 +00001814 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001815 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001816 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001817 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001818 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001819
Douglas Gregorb98b1992009-08-11 05:31:07 +00001820 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001821 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001822 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001823 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001824
Douglas Gregorb98b1992009-08-11 05:31:07 +00001825 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001826 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001827 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001828 }
Mike Stump1eb44332009-09-09 15:08:12 +00001829
Douglas Gregorb98b1992009-08-11 05:31:07 +00001830 /// \brief Build a new C++ static_cast expression.
1831 ///
1832 /// By default, performs semantic analysis to build the new expression.
1833 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001834 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001835 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001836 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001837 SourceLocation RAngleLoc,
1838 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001839 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001840 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001841 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001842 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001843 SourceRange(LAngleLoc, RAngleLoc),
1844 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001845 }
1846
1847 /// \brief Build a new C++ dynamic_cast expression.
1848 ///
1849 /// By default, performs semantic analysis to build the new expression.
1850 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001851 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001852 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001853 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001854 SourceLocation RAngleLoc,
1855 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001856 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001857 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001858 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001859 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001860 SourceRange(LAngleLoc, RAngleLoc),
1861 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001862 }
1863
1864 /// \brief Build a new C++ reinterpret_cast expression.
1865 ///
1866 /// By default, performs semantic analysis to build the new expression.
1867 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001868 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001869 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001870 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001871 SourceLocation RAngleLoc,
1872 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001873 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001874 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001875 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001876 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001877 SourceRange(LAngleLoc, RAngleLoc),
1878 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001879 }
1880
1881 /// \brief Build a new C++ const_cast expression.
1882 ///
1883 /// By default, performs semantic analysis to build the new expression.
1884 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001885 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001886 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001887 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001888 SourceLocation RAngleLoc,
1889 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001890 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001891 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001892 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001893 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001894 SourceRange(LAngleLoc, RAngleLoc),
1895 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001896 }
Mike Stump1eb44332009-09-09 15:08:12 +00001897
Douglas Gregorb98b1992009-08-11 05:31:07 +00001898 /// \brief Build a new C++ functional-style cast expression.
1899 ///
1900 /// By default, performs semantic analysis to build the new expression.
1901 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001902 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1903 SourceLocation LParenLoc,
1904 Expr *Sub,
1905 SourceLocation RParenLoc) {
1906 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001907 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001908 RParenLoc);
1909 }
Mike Stump1eb44332009-09-09 15:08:12 +00001910
Douglas Gregorb98b1992009-08-11 05:31:07 +00001911 /// \brief Build a new C++ typeid(type) expression.
1912 ///
1913 /// By default, performs semantic analysis to build the new expression.
1914 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001915 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001916 SourceLocation TypeidLoc,
1917 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001918 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001919 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001920 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001921 }
Mike Stump1eb44332009-09-09 15:08:12 +00001922
Francois Pichet01b7c302010-09-08 12:20:18 +00001923
Douglas Gregorb98b1992009-08-11 05:31:07 +00001924 /// \brief Build a new C++ typeid(expr) expression.
1925 ///
1926 /// By default, performs semantic analysis to build the new expression.
1927 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001928 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001929 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001930 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001931 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001932 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001933 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001934 }
1935
Francois Pichet01b7c302010-09-08 12:20:18 +00001936 /// \brief Build a new C++ __uuidof(type) expression.
1937 ///
1938 /// By default, performs semantic analysis to build the new expression.
1939 /// Subclasses may override this routine to provide different behavior.
1940 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1941 SourceLocation TypeidLoc,
1942 TypeSourceInfo *Operand,
1943 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001944 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001945 RParenLoc);
1946 }
1947
1948 /// \brief Build a new C++ __uuidof(expr) expression.
1949 ///
1950 /// By default, performs semantic analysis to build the new expression.
1951 /// Subclasses may override this routine to provide different behavior.
1952 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1953 SourceLocation TypeidLoc,
1954 Expr *Operand,
1955 SourceLocation RParenLoc) {
1956 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1957 RParenLoc);
1958 }
1959
Douglas Gregorb98b1992009-08-11 05:31:07 +00001960 /// \brief Build a new C++ "this" expression.
1961 ///
1962 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001963 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001964 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001965 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001966 QualType ThisType,
1967 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001968 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001969 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001970 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1971 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001972 }
1973
1974 /// \brief Build a new C++ throw expression.
1975 ///
1976 /// By default, performs semantic analysis to build the new expression.
1977 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001978 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1979 bool IsThrownVariableInScope) {
1980 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001981 }
1982
1983 /// \brief Build a new C++ default-argument expression.
1984 ///
1985 /// By default, builds a new default-argument expression, which does not
1986 /// require any semantic analysis. Subclasses may override this routine to
1987 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001988 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001989 ParmVarDecl *Param) {
1990 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1991 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001992 }
1993
Richard Smithc3bf52c2013-04-20 22:23:05 +00001994 /// \brief Build a new C++11 default-initialization expression.
1995 ///
1996 /// By default, builds a new default field initialization expression, which
1997 /// does not require any semantic analysis. Subclasses may override this
1998 /// routine to provide different behavior.
1999 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2000 FieldDecl *Field) {
2001 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2002 Field));
2003 }
2004
Douglas Gregorb98b1992009-08-11 05:31:07 +00002005 /// \brief Build a new C++ zero-initialization expression.
2006 ///
2007 /// By default, performs semantic analysis to build the new expression.
2008 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002009 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2010 SourceLocation LParenLoc,
2011 SourceLocation RParenLoc) {
2012 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002013 None, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002014 }
Mike Stump1eb44332009-09-09 15:08:12 +00002015
Douglas Gregorb98b1992009-08-11 05:31:07 +00002016 /// \brief Build a new C++ "new" expression.
2017 ///
2018 /// By default, performs semantic analysis to build the new expression.
2019 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002020 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002021 bool UseGlobal,
2022 SourceLocation PlacementLParen,
2023 MultiExprArg PlacementArgs,
2024 SourceLocation PlacementRParen,
2025 SourceRange TypeIdParens,
2026 QualType AllocatedType,
2027 TypeSourceInfo *AllocatedTypeInfo,
2028 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002029 SourceRange DirectInitRange,
2030 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002031 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002032 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002033 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002034 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002035 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002036 AllocatedType,
2037 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002038 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002039 DirectInitRange,
2040 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002041 }
Mike Stump1eb44332009-09-09 15:08:12 +00002042
Douglas Gregorb98b1992009-08-11 05:31:07 +00002043 /// \brief Build a new C++ "delete" expression.
2044 ///
2045 /// By default, performs semantic analysis to build the new expression.
2046 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002047 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002048 bool IsGlobalDelete,
2049 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002050 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002051 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002052 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002053 }
Mike Stump1eb44332009-09-09 15:08:12 +00002054
Douglas Gregorb98b1992009-08-11 05:31:07 +00002055 /// \brief Build a new unary type trait expression.
2056 ///
2057 /// By default, performs semantic analysis to build the new expression.
2058 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002059 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002060 SourceLocation StartLoc,
2061 TypeSourceInfo *T,
2062 SourceLocation RParenLoc) {
2063 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002064 }
2065
Francois Pichet6ad6f282010-12-07 00:08:36 +00002066 /// \brief Build a new binary type trait expression.
2067 ///
2068 /// By default, performs semantic analysis to build the new expression.
2069 /// Subclasses may override this routine to provide different behavior.
2070 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2071 SourceLocation StartLoc,
2072 TypeSourceInfo *LhsT,
2073 TypeSourceInfo *RhsT,
2074 SourceLocation RParenLoc) {
2075 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2076 }
2077
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002078 /// \brief Build a new type trait expression.
2079 ///
2080 /// By default, performs semantic analysis to build the new expression.
2081 /// Subclasses may override this routine to provide different behavior.
2082 ExprResult RebuildTypeTrait(TypeTrait Trait,
2083 SourceLocation StartLoc,
2084 ArrayRef<TypeSourceInfo *> Args,
2085 SourceLocation RParenLoc) {
2086 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2087 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002088
John Wiegley21ff2e52011-04-28 00:16:57 +00002089 /// \brief Build a new array type trait expression.
2090 ///
2091 /// By default, performs semantic analysis to build the new expression.
2092 /// Subclasses may override this routine to provide different behavior.
2093 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2094 SourceLocation StartLoc,
2095 TypeSourceInfo *TSInfo,
2096 Expr *DimExpr,
2097 SourceLocation RParenLoc) {
2098 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2099 }
2100
John Wiegley55262202011-04-25 06:54:41 +00002101 /// \brief Build a new expression trait expression.
2102 ///
2103 /// By default, performs semantic analysis to build the new expression.
2104 /// Subclasses may override this routine to provide different behavior.
2105 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2106 SourceLocation StartLoc,
2107 Expr *Queried,
2108 SourceLocation RParenLoc) {
2109 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2110 }
2111
Mike Stump1eb44332009-09-09 15:08:12 +00002112 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002113 /// expression.
2114 ///
2115 /// By default, performs semantic analysis to build the new expression.
2116 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002117 ExprResult RebuildDependentScopeDeclRefExpr(
2118 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002119 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002120 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002121 const TemplateArgumentListInfo *TemplateArgs,
2122 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002123 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002124 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002125
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002126 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002127 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002128 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002129
Richard Smithefeeccf2012-10-21 03:28:35 +00002130 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2131 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002132 }
2133
2134 /// \brief Build a new template-id expression.
2135 ///
2136 /// By default, performs semantic analysis to build the new expression.
2137 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002138 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002139 SourceLocation TemplateKWLoc,
2140 LookupResult &R,
2141 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002142 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002143 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2144 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002145 }
2146
2147 /// \brief Build a new object-construction expression.
2148 ///
2149 /// By default, performs semantic analysis to build the new expression.
2150 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002151 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002152 SourceLocation Loc,
2153 CXXConstructorDecl *Constructor,
2154 bool IsElidable,
2155 MultiExprArg Args,
2156 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002157 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002158 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002159 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002160 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002161 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002162 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002163 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002164 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002165
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002166 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002167 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002168 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002169 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002170 RequiresZeroInit, ConstructKind,
2171 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002172 }
2173
2174 /// \brief Build a new object-construction expression.
2175 ///
2176 /// By default, performs semantic analysis to build the new expression.
2177 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002178 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2179 SourceLocation LParenLoc,
2180 MultiExprArg Args,
2181 SourceLocation RParenLoc) {
2182 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002183 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002184 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002185 RParenLoc);
2186 }
2187
2188 /// \brief Build a new object-construction expression.
2189 ///
2190 /// By default, performs semantic analysis to build the new expression.
2191 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002192 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2193 SourceLocation LParenLoc,
2194 MultiExprArg Args,
2195 SourceLocation RParenLoc) {
2196 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002197 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002198 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002199 RParenLoc);
2200 }
Mike Stump1eb44332009-09-09 15:08:12 +00002201
Douglas Gregorb98b1992009-08-11 05:31:07 +00002202 /// \brief Build a new member reference expression.
2203 ///
2204 /// By default, performs semantic analysis to build the new expression.
2205 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002206 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002207 QualType BaseType,
2208 bool IsArrow,
2209 SourceLocation OperatorLoc,
2210 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002211 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002212 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002213 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002214 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002215 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002216 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002217
John McCall9ae2f072010-08-23 23:25:46 +00002218 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002219 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002220 SS, TemplateKWLoc,
2221 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002222 MemberNameInfo,
2223 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002224 }
2225
John McCall129e2df2009-11-30 22:42:35 +00002226 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002227 ///
2228 /// By default, performs semantic analysis to build the new expression.
2229 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002230 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2231 SourceLocation OperatorLoc,
2232 bool IsArrow,
2233 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002234 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002235 NamedDecl *FirstQualifierInScope,
2236 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002237 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002238 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002239 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002240
John McCall9ae2f072010-08-23 23:25:46 +00002241 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002242 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002243 SS, TemplateKWLoc,
2244 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002245 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002246 }
Mike Stump1eb44332009-09-09 15:08:12 +00002247
Sebastian Redl2e156222010-09-10 20:55:43 +00002248 /// \brief Build a new noexcept expression.
2249 ///
2250 /// By default, performs semantic analysis to build the new expression.
2251 /// Subclasses may override this routine to provide different behavior.
2252 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2253 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2254 }
2255
Douglas Gregoree8aff02011-01-04 17:33:58 +00002256 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002257 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2258 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002259 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002260 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002261 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002262 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2263 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002264 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002265
2266 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2267 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002268 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002269 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002270
Patrick Beardeb382ec2012-04-19 00:25:12 +00002271 /// \brief Build a new Objective-C boxed expression.
2272 ///
2273 /// By default, performs semantic analysis to build the new expression.
2274 /// Subclasses may override this routine to provide different behavior.
2275 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2276 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2277 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002278
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002279 /// \brief Build a new Objective-C array literal.
2280 ///
2281 /// By default, performs semantic analysis to build the new expression.
2282 /// Subclasses may override this routine to provide different behavior.
2283 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2284 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002285 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002286 MultiExprArg(Elements, NumElements));
2287 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002288
2289 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002290 Expr *Base, Expr *Key,
2291 ObjCMethodDecl *getterMethod,
2292 ObjCMethodDecl *setterMethod) {
2293 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2294 getterMethod, setterMethod);
2295 }
2296
2297 /// \brief Build a new Objective-C dictionary literal.
2298 ///
2299 /// By default, performs semantic analysis to build the new expression.
2300 /// Subclasses may override this routine to provide different behavior.
2301 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2302 ObjCDictionaryElement *Elements,
2303 unsigned NumElements) {
2304 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2305 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002306
James Dennett699c9042012-06-15 07:13:21 +00002307 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002308 ///
2309 /// By default, performs semantic analysis to build the new expression.
2310 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002311 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002312 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002313 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002314 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002315 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002316 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002317
Douglas Gregor92e986e2010-04-22 16:44:27 +00002318 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002319 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002320 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002321 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002322 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002323 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002324 MultiExprArg Args,
2325 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002326 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2327 ReceiverTypeInfo->getType(),
2328 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002329 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002330 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002331 }
2332
2333 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002334 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002335 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002336 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002337 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002338 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002339 MultiExprArg Args,
2340 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002341 return SemaRef.BuildInstanceMessage(Receiver,
2342 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002343 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002344 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002345 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002346 }
2347
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002348 /// \brief Build a new Objective-C ivar reference expression.
2349 ///
2350 /// By default, performs semantic analysis to build the new expression.
2351 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002352 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002353 SourceLocation IvarLoc,
2354 bool IsArrow, bool IsFreeIvar) {
2355 // FIXME: We lose track of the IsFreeIvar bit.
2356 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002357 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002358 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2359 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002360 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002361 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002362 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002363 false);
John Wiegley429bb272011-04-08 18:41:53 +00002364 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002365 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002366
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002367 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002368 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002369
John Wiegley429bb272011-04-08 18:41:53 +00002370 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002371 /*FIXME:*/IvarLoc, IsArrow,
2372 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002373 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002374 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002375 /*TemplateArgs=*/0);
2376 }
Douglas Gregore3303542010-04-26 20:47:02 +00002377
2378 /// \brief Build a new Objective-C property reference expression.
2379 ///
2380 /// By default, performs semantic analysis to build the new expression.
2381 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002382 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002383 ObjCPropertyDecl *Property,
2384 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002385 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002386 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002387 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2388 Sema::LookupMemberName);
2389 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002390 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002391 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002392 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002393 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002394 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002395
Douglas Gregore3303542010-04-26 20:47:02 +00002396 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002397 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002398
John Wiegley429bb272011-04-08 18:41:53 +00002399 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002400 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002401 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002402 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002403 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002404 /*TemplateArgs=*/0);
2405 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002406
John McCall12f78a62010-12-02 01:19:52 +00002407 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002408 ///
2409 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002410 /// Subclasses may override this routine to provide different behavior.
2411 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2412 ObjCMethodDecl *Getter,
2413 ObjCMethodDecl *Setter,
2414 SourceLocation PropertyLoc) {
2415 // Since these expressions can only be value-dependent, we do not
2416 // need to perform semantic analysis again.
2417 return Owned(
2418 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2419 VK_LValue, OK_ObjCProperty,
2420 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002421 }
2422
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002423 /// \brief Build a new Objective-C "isa" expression.
2424 ///
2425 /// By default, performs semantic analysis to build the new expression.
2426 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002427 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002428 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002429 bool IsArrow) {
2430 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002431 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002432 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2433 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002434 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002435 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002436 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002437 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002438 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002439
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002440 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002441 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002442
John Wiegley429bb272011-04-08 18:41:53 +00002443 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002444 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002445 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002446 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002447 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002448 /*TemplateArgs=*/0);
2449 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002450
Douglas Gregorb98b1992009-08-11 05:31:07 +00002451 /// \brief Build a new shuffle vector expression.
2452 ///
2453 /// By default, performs semantic analysis to build the new expression.
2454 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002455 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002456 MultiExprArg SubExprs,
2457 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002458 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002459 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002460 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2461 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2462 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002463 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002464
Douglas Gregorb98b1992009-08-11 05:31:07 +00002465 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002466 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002467 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2468 SemaRef.Context.BuiltinFnTy,
2469 VK_RValue, BuiltinLoc);
2470 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2471 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2472 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002473
2474 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002475 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002476 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002477 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002478 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002479 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002480
Douglas Gregorb98b1992009-08-11 05:31:07 +00002481 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002482 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002483 }
John McCall43fed0d2010-11-12 08:19:04 +00002484
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002485 /// \brief Build a new template argument pack expansion.
2486 ///
2487 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002488 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002489 /// different behavior.
2490 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002491 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002492 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002493 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002494 case TemplateArgument::Expression: {
2495 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002496 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2497 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002498 if (Result.isInvalid())
2499 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002500
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002501 return TemplateArgumentLoc(Result.get(), Result.get());
2502 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002503
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002504 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002505 return TemplateArgumentLoc(TemplateArgument(
2506 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002507 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002508 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002509 Pattern.getTemplateNameLoc(),
2510 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002511
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002512 case TemplateArgument::Null:
2513 case TemplateArgument::Integral:
2514 case TemplateArgument::Declaration:
2515 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002516 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002517 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002518 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002519
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002520 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002521 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002522 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002523 EllipsisLoc,
2524 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002525 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2526 Expansion);
2527 break;
2528 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002529
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002530 return TemplateArgumentLoc();
2531 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002532
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002533 /// \brief Build a new expression pack expansion.
2534 ///
2535 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002536 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002537 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002538 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002539 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002540 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002541 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002542
2543 /// \brief Build a new atomic operation expression.
2544 ///
2545 /// By default, performs semantic analysis to build the new expression.
2546 /// Subclasses may override this routine to provide different behavior.
2547 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2548 MultiExprArg SubExprs,
2549 QualType RetTy,
2550 AtomicExpr::AtomicOp Op,
2551 SourceLocation RParenLoc) {
2552 // Just create the expression; there is not any interesting semantic
2553 // analysis here because we can't actually build an AtomicExpr until
2554 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002555 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002556 RParenLoc);
2557 }
2558
John McCall43fed0d2010-11-12 08:19:04 +00002559private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002560 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2561 QualType ObjectType,
2562 NamedDecl *FirstQualifierInScope,
2563 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002564
2565 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2566 QualType ObjectType,
2567 NamedDecl *FirstQualifierInScope,
2568 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002569};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002570
Douglas Gregor43959a92009-08-20 07:17:43 +00002571template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002572StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002573 if (!S)
2574 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002575
Douglas Gregor43959a92009-08-20 07:17:43 +00002576 switch (S->getStmtClass()) {
2577 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002578
Douglas Gregor43959a92009-08-20 07:17:43 +00002579 // Transform individual statement nodes
2580#define STMT(Node, Parent) \
2581 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002582#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002583#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002584#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002585
Douglas Gregor43959a92009-08-20 07:17:43 +00002586 // Transform expressions by calling TransformExpr.
2587#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002588#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002589#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002590#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002591 {
John McCall60d7b3a2010-08-24 06:29:42 +00002592 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002593 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002594 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002595
Richard Smith41956372013-01-14 22:39:08 +00002596 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002597 }
Mike Stump1eb44332009-09-09 15:08:12 +00002598 }
2599
John McCall3fa5cae2010-10-26 07:05:15 +00002600 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002601}
Mike Stump1eb44332009-09-09 15:08:12 +00002602
2603
Douglas Gregor670444e2009-08-04 22:27:00 +00002604template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002605ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002606 if (!E)
2607 return SemaRef.Owned(E);
2608
2609 switch (E->getStmtClass()) {
2610 case Stmt::NoStmtClass: break;
2611#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002612#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002613#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002614 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002615#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002616 }
2617
John McCall3fa5cae2010-10-26 07:05:15 +00002618 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002619}
2620
2621template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002622ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2623 bool CXXDirectInit) {
2624 // Initializers are instantiated like expressions, except that various outer
2625 // layers are stripped.
2626 if (!Init)
2627 return SemaRef.Owned(Init);
2628
2629 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2630 Init = ExprTemp->getSubExpr();
2631
Richard Smith858c2c32013-05-30 22:40:16 +00002632 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2633 Init = MTE->GetTemporaryExpr();
2634
Richard Smithc83c2302012-12-19 01:39:02 +00002635 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2636 Init = Binder->getSubExpr();
2637
2638 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2639 Init = ICE->getSubExprAsWritten();
2640
Richard Smith7c3e6152013-06-12 22:31:48 +00002641 if (CXXStdInitializerListExpr *ILE =
2642 dyn_cast<CXXStdInitializerListExpr>(Init))
2643 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2644
Richard Smith5cf15892012-12-21 08:13:35 +00002645 // If this is not a direct-initializer, we only need to reconstruct
2646 // InitListExprs. Other forms of copy-initialization will be a no-op if
2647 // the initializer is already the right type.
2648 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2649 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2650 return getDerived().TransformExpr(Init);
2651
2652 // Revert value-initialization back to empty parens.
2653 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2654 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002655 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002656 Parens.getEnd());
2657 }
2658
2659 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2660 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002661 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002662 SourceLocation());
2663
2664 // Revert initialization by constructor back to a parenthesized or braced list
2665 // of expressions. Any other form of initializer can just be reused directly.
2666 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002667 return getDerived().TransformExpr(Init);
2668
2669 SmallVector<Expr*, 8> NewArgs;
2670 bool ArgChanged = false;
2671 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2672 /*IsCall*/true, NewArgs, &ArgChanged))
2673 return ExprError();
2674
2675 // If this was list initialization, revert to list form.
2676 if (Construct->isListInitialization())
2677 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2678 Construct->getLocEnd(),
2679 Construct->getType());
2680
Richard Smithc83c2302012-12-19 01:39:02 +00002681 // Build a ParenListExpr to represent anything else.
2682 SourceRange Parens = Construct->getParenRange();
2683 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2684 Parens.getEnd());
2685}
2686
2687template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002688bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2689 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002690 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002691 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002692 bool *ArgChanged) {
2693 for (unsigned I = 0; I != NumInputs; ++I) {
2694 // If requested, drop call arguments that need to be dropped.
2695 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2696 if (ArgChanged)
2697 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002698
Douglas Gregoraa165f82011-01-03 19:04:46 +00002699 break;
2700 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002701
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002702 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2703 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002704
Chris Lattner686775d2011-07-20 06:58:45 +00002705 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002706 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2707 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002708
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002709 // Determine whether the set of unexpanded parameter packs can and should
2710 // be expanded.
2711 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002712 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002713 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2714 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002715 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2716 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002717 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002718 Expand, RetainExpansion,
2719 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002720 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002721
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002722 if (!Expand) {
2723 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002724 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002725 // expansion.
2726 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2727 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2728 if (OutPattern.isInvalid())
2729 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002730
2731 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002732 Expansion->getEllipsisLoc(),
2733 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002734 if (Out.isInvalid())
2735 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002736
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002737 if (ArgChanged)
2738 *ArgChanged = true;
2739 Outputs.push_back(Out.get());
2740 continue;
2741 }
John McCallc8fc90a2011-07-06 07:30:07 +00002742
2743 // Record right away that the argument was changed. This needs
2744 // to happen even if the array expands to nothing.
2745 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002746
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002747 // The transform has determined that we should perform an elementwise
2748 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002749 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002750 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2751 ExprResult Out = getDerived().TransformExpr(Pattern);
2752 if (Out.isInvalid())
2753 return true;
2754
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002755 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002756 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2757 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002758 if (Out.isInvalid())
2759 return true;
2760 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002761
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002762 Outputs.push_back(Out.get());
2763 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002764
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002765 continue;
2766 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002767
Richard Smithc83c2302012-12-19 01:39:02 +00002768 ExprResult Result =
2769 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2770 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002771 if (Result.isInvalid())
2772 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002773
Douglas Gregoraa165f82011-01-03 19:04:46 +00002774 if (Result.get() != Inputs[I] && ArgChanged)
2775 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002776
2777 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002778 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002779
Douglas Gregoraa165f82011-01-03 19:04:46 +00002780 return false;
2781}
2782
2783template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002784NestedNameSpecifierLoc
2785TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2786 NestedNameSpecifierLoc NNS,
2787 QualType ObjectType,
2788 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002789 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002790 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002791 Qualifier = Qualifier.getPrefix())
2792 Qualifiers.push_back(Qualifier);
2793
2794 CXXScopeSpec SS;
2795 while (!Qualifiers.empty()) {
2796 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2797 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002798
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002799 switch (QNNS->getKind()) {
2800 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002801 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002802 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002803 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002804 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002805 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002806 FirstQualifierInScope, false))
2807 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002808
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002809 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002810
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002811 case NestedNameSpecifier::Namespace: {
2812 NamespaceDecl *NS
2813 = cast_or_null<NamespaceDecl>(
2814 getDerived().TransformDecl(
2815 Q.getLocalBeginLoc(),
2816 QNNS->getAsNamespace()));
2817 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2818 break;
2819 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002820
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002821 case NestedNameSpecifier::NamespaceAlias: {
2822 NamespaceAliasDecl *Alias
2823 = cast_or_null<NamespaceAliasDecl>(
2824 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2825 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002826 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002827 Q.getLocalEndLoc());
2828 break;
2829 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002830
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002831 case NestedNameSpecifier::Global:
2832 // There is no meaningful transformation that one could perform on the
2833 // global scope.
2834 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2835 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002836
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002837 case NestedNameSpecifier::TypeSpecWithTemplate:
2838 case NestedNameSpecifier::TypeSpec: {
2839 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2840 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002841
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002842 if (!TL)
2843 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002844
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002845 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002846 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002847 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002848 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002849 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002850 if (TL.getType()->isEnumeralType())
2851 SemaRef.Diag(TL.getBeginLoc(),
2852 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002853 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2854 Q.getLocalEndLoc());
2855 break;
2856 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002857 // If the nested-name-specifier is an invalid type def, don't emit an
2858 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002859 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2860 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002861 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002862 << TL.getType() << SS.getRange();
2863 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002864 return NestedNameSpecifierLoc();
2865 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002866 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002867
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002868 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002869 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002870 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002871 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002872
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002873 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002874 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002875 !getDerived().AlwaysRebuild())
2876 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002877
2878 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002879 // nested-name-specifier, do so.
2880 if (SS.location_size() == NNS.getDataLength() &&
2881 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2882 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2883
2884 // Allocate new nested-name-specifier location information.
2885 return SS.getWithLocInContext(SemaRef.Context);
2886}
2887
2888template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002889DeclarationNameInfo
2890TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002891::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002892 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002893 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002894 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002895
2896 switch (Name.getNameKind()) {
2897 case DeclarationName::Identifier:
2898 case DeclarationName::ObjCZeroArgSelector:
2899 case DeclarationName::ObjCOneArgSelector:
2900 case DeclarationName::ObjCMultiArgSelector:
2901 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002902 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002903 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002904 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002905
Douglas Gregor81499bb2009-09-03 22:13:48 +00002906 case DeclarationName::CXXConstructorName:
2907 case DeclarationName::CXXDestructorName:
2908 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002909 TypeSourceInfo *NewTInfo;
2910 CanQualType NewCanTy;
2911 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002912 NewTInfo = getDerived().TransformType(OldTInfo);
2913 if (!NewTInfo)
2914 return DeclarationNameInfo();
2915 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002916 }
2917 else {
2918 NewTInfo = 0;
2919 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002920 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002921 if (NewT.isNull())
2922 return DeclarationNameInfo();
2923 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2924 }
Mike Stump1eb44332009-09-09 15:08:12 +00002925
Abramo Bagnara25777432010-08-11 22:01:17 +00002926 DeclarationName NewName
2927 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2928 NewCanTy);
2929 DeclarationNameInfo NewNameInfo(NameInfo);
2930 NewNameInfo.setName(NewName);
2931 NewNameInfo.setNamedTypeInfo(NewTInfo);
2932 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002933 }
Mike Stump1eb44332009-09-09 15:08:12 +00002934 }
2935
David Blaikieb219cfc2011-09-23 05:06:16 +00002936 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002937}
2938
2939template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002940TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002941TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2942 TemplateName Name,
2943 SourceLocation NameLoc,
2944 QualType ObjectType,
2945 NamedDecl *FirstQualifierInScope) {
2946 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2947 TemplateDecl *Template = QTN->getTemplateDecl();
2948 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002949
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002950 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002951 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002952 Template));
2953 if (!TransTemplate)
2954 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002955
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002956 if (!getDerived().AlwaysRebuild() &&
2957 SS.getScopeRep() == QTN->getQualifier() &&
2958 TransTemplate == Template)
2959 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002960
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002961 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2962 TransTemplate);
2963 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002964
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002965 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2966 if (SS.getScopeRep()) {
2967 // These apply to the scope specifier, not the template.
2968 ObjectType = QualType();
2969 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002970 }
2971
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002972 if (!getDerived().AlwaysRebuild() &&
2973 SS.getScopeRep() == DTN->getQualifier() &&
2974 ObjectType.isNull())
2975 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002976
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002977 if (DTN->isIdentifier()) {
2978 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002979 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002980 NameLoc,
2981 ObjectType,
2982 FirstQualifierInScope);
2983 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002984
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002985 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2986 ObjectType);
2987 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002988
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002989 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2990 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002991 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002992 Template));
2993 if (!TransTemplate)
2994 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002995
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002996 if (!getDerived().AlwaysRebuild() &&
2997 TransTemplate == Template)
2998 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002999
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003000 return TemplateName(TransTemplate);
3001 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003002
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003003 if (SubstTemplateTemplateParmPackStorage *SubstPack
3004 = Name.getAsSubstTemplateTemplateParmPack()) {
3005 TemplateTemplateParmDecl *TransParam
3006 = cast_or_null<TemplateTemplateParmDecl>(
3007 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3008 if (!TransParam)
3009 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003010
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003011 if (!getDerived().AlwaysRebuild() &&
3012 TransParam == SubstPack->getParameterPack())
3013 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003014
3015 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003016 SubstPack->getArgumentPack());
3017 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003018
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003019 // These should be getting filtered out before they reach the AST.
3020 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003021}
3022
3023template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003024void TreeTransform<Derived>::InventTemplateArgumentLoc(
3025 const TemplateArgument &Arg,
3026 TemplateArgumentLoc &Output) {
3027 SourceLocation Loc = getDerived().getBaseLocation();
3028 switch (Arg.getKind()) {
3029 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003030 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003031 break;
3032
3033 case TemplateArgument::Type:
3034 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003035 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003036
John McCall833ca992009-10-29 08:12:44 +00003037 break;
3038
Douglas Gregor788cd062009-11-11 01:00:40 +00003039 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003040 case TemplateArgument::TemplateExpansion: {
3041 NestedNameSpecifierLocBuilder Builder;
3042 TemplateName Template = Arg.getAsTemplate();
3043 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3044 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3045 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3046 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003047
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003048 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003049 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003050 Builder.getWithLocInContext(SemaRef.Context),
3051 Loc);
3052 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003053 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003054 Builder.getWithLocInContext(SemaRef.Context),
3055 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003056
Douglas Gregor788cd062009-11-11 01:00:40 +00003057 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003058 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003059
John McCall833ca992009-10-29 08:12:44 +00003060 case TemplateArgument::Expression:
3061 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3062 break;
3063
3064 case TemplateArgument::Declaration:
3065 case TemplateArgument::Integral:
3066 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003067 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003068 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003069 break;
3070 }
3071}
3072
3073template<typename Derived>
3074bool TreeTransform<Derived>::TransformTemplateArgument(
3075 const TemplateArgumentLoc &Input,
3076 TemplateArgumentLoc &Output) {
3077 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003078 switch (Arg.getKind()) {
3079 case TemplateArgument::Null:
3080 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003081 case TemplateArgument::Pack:
3082 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003083 case TemplateArgument::NullPtr:
3084 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003085
Douglas Gregor670444e2009-08-04 22:27:00 +00003086 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003087 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003088 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003089 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003090
3091 DI = getDerived().TransformType(DI);
3092 if (!DI) return true;
3093
3094 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3095 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003096 }
Mike Stump1eb44332009-09-09 15:08:12 +00003097
Douglas Gregor788cd062009-11-11 01:00:40 +00003098 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003099 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3100 if (QualifierLoc) {
3101 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3102 if (!QualifierLoc)
3103 return true;
3104 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003105
Douglas Gregor1d752d72011-03-02 18:46:51 +00003106 CXXScopeSpec SS;
3107 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003108 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003109 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3110 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003111 if (Template.isNull())
3112 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003113
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003114 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003115 Input.getTemplateNameLoc());
3116 return false;
3117 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003118
3119 case TemplateArgument::TemplateExpansion:
3120 llvm_unreachable("Caller should expand pack expansions");
3121
Douglas Gregor670444e2009-08-04 22:27:00 +00003122 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003123 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003124 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003125 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003126
John McCall833ca992009-10-29 08:12:44 +00003127 Expr *InputExpr = Input.getSourceExpression();
3128 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3129
Chris Lattner223de242011-04-25 20:37:58 +00003130 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003131 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003132 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003133 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003134 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003135 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003136 }
Mike Stump1eb44332009-09-09 15:08:12 +00003137
Douglas Gregor670444e2009-08-04 22:27:00 +00003138 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003139 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003140}
3141
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003142/// \brief Iterator adaptor that invents template argument location information
3143/// for each of the template arguments in its underlying iterator.
3144template<typename Derived, typename InputIterator>
3145class TemplateArgumentLocInventIterator {
3146 TreeTransform<Derived> &Self;
3147 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003148
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003149public:
3150 typedef TemplateArgumentLoc value_type;
3151 typedef TemplateArgumentLoc reference;
3152 typedef typename std::iterator_traits<InputIterator>::difference_type
3153 difference_type;
3154 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003155
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003156 class pointer {
3157 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003158
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003159 public:
3160 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003161
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003162 const TemplateArgumentLoc *operator->() const { return &Arg; }
3163 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003164
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003165 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003166
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003167 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3168 InputIterator Iter)
3169 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003170
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003171 TemplateArgumentLocInventIterator &operator++() {
3172 ++Iter;
3173 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003174 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003175
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003176 TemplateArgumentLocInventIterator operator++(int) {
3177 TemplateArgumentLocInventIterator Old(*this);
3178 ++(*this);
3179 return Old;
3180 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003181
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003182 reference operator*() const {
3183 TemplateArgumentLoc Result;
3184 Self.InventTemplateArgumentLoc(*Iter, Result);
3185 return Result;
3186 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003187
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003188 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003189
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003190 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3191 const TemplateArgumentLocInventIterator &Y) {
3192 return X.Iter == Y.Iter;
3193 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003194
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003195 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3196 const TemplateArgumentLocInventIterator &Y) {
3197 return X.Iter != Y.Iter;
3198 }
3199};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003200
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003201template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003202template<typename InputIterator>
3203bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3204 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003205 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003206 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003207 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003208 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003209
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003210 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3211 // Unpack argument packs, which we translate them into separate
3212 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003213 // FIXME: We could do much better if we could guarantee that the
3214 // TemplateArgumentLocInfo for the pack expansion would be usable for
3215 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003216 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003217 TemplateArgument::pack_iterator>
3218 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003219 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003220 In.getArgument().pack_begin()),
3221 PackLocIterator(*this,
3222 In.getArgument().pack_end()),
3223 Outputs))
3224 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003225
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003226 continue;
3227 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003228
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003229 if (In.getArgument().isPackExpansion()) {
3230 // We have a pack expansion, for which we will be substituting into
3231 // the pattern.
3232 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003233 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003234 TemplateArgumentLoc Pattern
Eli Friedman850cf512013-06-20 04:11:21 +00003235 = getSema().getTemplateArgumentPackExpansionPattern(
3236 In, Ellipsis, OrigNumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003237
Chris Lattner686775d2011-07-20 06:58:45 +00003238 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003239 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3240 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003241
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003242 // Determine whether the set of unexpanded parameter packs can and should
3243 // be expanded.
3244 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003245 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003246 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003247 if (getDerived().TryExpandParameterPacks(Ellipsis,
3248 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003249 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003250 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003251 RetainExpansion,
3252 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003253 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003254
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003255 if (!Expand) {
3256 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003257 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003258 // expansion.
3259 TemplateArgumentLoc OutPattern;
3260 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3261 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3262 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003263
Douglas Gregorcded4f62011-01-14 17:04:44 +00003264 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3265 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003266 if (Out.getArgument().isNull())
3267 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003268
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003269 Outputs.addArgument(Out);
3270 continue;
3271 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003272
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003273 // The transform has determined that we should perform an elementwise
3274 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003275 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003276 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3277
3278 if (getDerived().TransformTemplateArgument(Pattern, Out))
3279 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003280
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003281 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003282 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3283 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003284 if (Out.getArgument().isNull())
3285 return true;
3286 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003287
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003288 Outputs.addArgument(Out);
3289 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003290
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003291 // If we're supposed to retain a pack expansion, do so by temporarily
3292 // forgetting the partially-substituted parameter pack.
3293 if (RetainExpansion) {
3294 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003295
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003296 if (getDerived().TransformTemplateArgument(Pattern, Out))
3297 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003298
Douglas Gregorcded4f62011-01-14 17:04:44 +00003299 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3300 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003301 if (Out.getArgument().isNull())
3302 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003303
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003304 Outputs.addArgument(Out);
3305 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003306
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003307 continue;
3308 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003309
3310 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003311 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003312 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003313
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003314 Outputs.addArgument(Out);
3315 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003316
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003317 return false;
3318
3319}
3320
Douglas Gregor577f75a2009-08-04 16:50:30 +00003321//===----------------------------------------------------------------------===//
3322// Type transformation
3323//===----------------------------------------------------------------------===//
3324
3325template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003326QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003327 if (getDerived().AlreadyTransformed(T))
3328 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003329
John McCalla2becad2009-10-21 00:40:46 +00003330 // Temporary workaround. All of these transformations should
3331 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003332 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3333 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003334
John McCall43fed0d2010-11-12 08:19:04 +00003335 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003336
John McCalla2becad2009-10-21 00:40:46 +00003337 if (!NewDI)
3338 return QualType();
3339
3340 return NewDI->getType();
3341}
3342
3343template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003344TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003345 // Refine the base location to the type's location.
3346 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3347 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003348 if (getDerived().AlreadyTransformed(DI->getType()))
3349 return DI;
3350
3351 TypeLocBuilder TLB;
3352
3353 TypeLoc TL = DI->getTypeLoc();
3354 TLB.reserve(TL.getFullDataSize());
3355
John McCall43fed0d2010-11-12 08:19:04 +00003356 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003357 if (Result.isNull())
3358 return 0;
3359
John McCalla93c9342009-12-07 02:54:59 +00003360 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003361}
3362
3363template<typename Derived>
3364QualType
John McCall43fed0d2010-11-12 08:19:04 +00003365TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003366 switch (T.getTypeLocClass()) {
3367#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003368#define TYPELOC(CLASS, PARENT) \
3369 case TypeLoc::CLASS: \
3370 return getDerived().Transform##CLASS##Type(TLB, \
3371 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003372#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003373 }
Mike Stump1eb44332009-09-09 15:08:12 +00003374
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003375 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003376}
3377
3378/// FIXME: By default, this routine adds type qualifiers only to types
3379/// that can have qualifiers, and silently suppresses those qualifiers
3380/// that are not permitted (e.g., qualifiers on reference or function
3381/// types). This is the right thing for template instantiation, but
3382/// probably not for other clients.
3383template<typename Derived>
3384QualType
3385TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003386 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003387 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003388
John McCall43fed0d2010-11-12 08:19:04 +00003389 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003390 if (Result.isNull())
3391 return QualType();
3392
3393 // Silently suppress qualifiers if the result type can't be qualified.
3394 // FIXME: this is the right thing for template instantiation, but
3395 // probably not for other clients.
3396 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003397 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003398
John McCallf85e1932011-06-15 23:02:42 +00003399 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003400 // resulting type.
3401 if (Quals.hasObjCLifetime()) {
3402 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3403 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003404 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003405 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003406 // A lifetime qualifier applied to a substituted template parameter
3407 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003408 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003409 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003410 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3411 QualType Replacement = SubstTypeParam->getReplacementType();
3412 Qualifiers Qs = Replacement.getQualifiers();
3413 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003414 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003415 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3416 Qs);
3417 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003418 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003419 Replacement);
3420 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003421 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3422 // 'auto' types behave the same way as template parameters.
3423 QualType Deduced = AutoTy->getDeducedType();
3424 Qualifiers Qs = Deduced.getQualifiers();
3425 Qs.removeObjCLifetime();
3426 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3427 Qs);
Richard Smitha2c36462013-04-26 16:15:35 +00003428 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto());
Douglas Gregor92d13872013-01-17 23:59:28 +00003429 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003430 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003431 // Otherwise, complain about the addition of a qualifier to an
3432 // already-qualified type.
Eli Friedman44ee0a72013-06-07 20:31:48 +00003433 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003434 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003435 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003436
Douglas Gregore559ca12011-06-17 22:11:49 +00003437 Quals.removeObjCLifetime();
3438 }
3439 }
3440 }
John McCall28654742010-06-05 06:41:15 +00003441 if (!Quals.empty()) {
3442 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003443 // BuildQualifiedType might not add qualifiers if they are invalid.
3444 if (Result.hasLocalQualifiers())
3445 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003446 // No location information to preserve.
3447 }
John McCalla2becad2009-10-21 00:40:46 +00003448
3449 return Result;
3450}
3451
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003452template<typename Derived>
3453TypeLoc
3454TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3455 QualType ObjectType,
3456 NamedDecl *UnqualLookup,
3457 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003458 QualType T = TL.getType();
3459 if (getDerived().AlreadyTransformed(T))
3460 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003461
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003462 TypeLocBuilder TLB;
3463 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003464
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003465 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003466 TemplateSpecializationTypeLoc SpecTL =
3467 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003468
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003469 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003470 getDerived().TransformTemplateName(SS,
3471 SpecTL.getTypePtr()->getTemplateName(),
3472 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003473 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003474 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003475 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003476
3477 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003478 Template);
3479 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003480 DependentTemplateSpecializationTypeLoc SpecTL =
3481 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003482
Douglas Gregora88f09f2011-02-28 17:23:35 +00003483 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003484 = getDerived().RebuildTemplateName(SS,
3485 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003486 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003487 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003488 if (Template.isNull())
3489 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003490
3491 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003492 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003493 Template,
3494 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003495 } else {
3496 // Nothing special needs to be done for these.
3497 Result = getDerived().TransformType(TLB, TL);
3498 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003499
3500 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003501 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003502
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003503 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3504}
3505
Douglas Gregorb71d8212011-03-02 18:32:08 +00003506template<typename Derived>
3507TypeSourceInfo *
3508TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3509 QualType ObjectType,
3510 NamedDecl *UnqualLookup,
3511 CXXScopeSpec &SS) {
3512 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003513
Douglas Gregorb71d8212011-03-02 18:32:08 +00003514 QualType T = TSInfo->getType();
3515 if (getDerived().AlreadyTransformed(T))
3516 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003517
Douglas Gregorb71d8212011-03-02 18:32:08 +00003518 TypeLocBuilder TLB;
3519 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003520
Douglas Gregorb71d8212011-03-02 18:32:08 +00003521 TypeLoc TL = TSInfo->getTypeLoc();
3522 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003523 TemplateSpecializationTypeLoc SpecTL =
3524 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003525
Douglas Gregorb71d8212011-03-02 18:32:08 +00003526 TemplateName Template
3527 = getDerived().TransformTemplateName(SS,
3528 SpecTL.getTypePtr()->getTemplateName(),
3529 SpecTL.getTemplateNameLoc(),
3530 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003531 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003532 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003533
3534 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003535 Template);
3536 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003537 DependentTemplateSpecializationTypeLoc SpecTL =
3538 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003539
Douglas Gregorb71d8212011-03-02 18:32:08 +00003540 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003541 = getDerived().RebuildTemplateName(SS,
3542 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003543 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003544 ObjectType, UnqualLookup);
3545 if (Template.isNull())
3546 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003547
3548 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003549 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003550 Template,
3551 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003552 } else {
3553 // Nothing special needs to be done for these.
3554 Result = getDerived().TransformType(TLB, TL);
3555 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003556
3557 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003558 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003559
Douglas Gregorb71d8212011-03-02 18:32:08 +00003560 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3561}
3562
John McCalla2becad2009-10-21 00:40:46 +00003563template <class TyLoc> static inline
3564QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3565 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3566 NewT.setNameLoc(T.getNameLoc());
3567 return T.getType();
3568}
3569
John McCalla2becad2009-10-21 00:40:46 +00003570template<typename Derived>
3571QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003572 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003573 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3574 NewT.setBuiltinLoc(T.getBuiltinLoc());
3575 if (T.needsExtraLocalData())
3576 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3577 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003578}
Mike Stump1eb44332009-09-09 15:08:12 +00003579
Douglas Gregor577f75a2009-08-04 16:50:30 +00003580template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003581QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003582 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003583 // FIXME: recurse?
3584 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003585}
Mike Stump1eb44332009-09-09 15:08:12 +00003586
Douglas Gregor577f75a2009-08-04 16:50:30 +00003587template<typename Derived>
Reid Kleckner12df2462013-06-24 17:51:48 +00003588QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3589 DecayedTypeLoc TL) {
3590 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3591 if (OriginalType.isNull())
3592 return QualType();
3593
3594 QualType Result = TL.getType();
3595 if (getDerived().AlwaysRebuild() ||
3596 OriginalType != TL.getOriginalLoc().getType())
3597 Result = SemaRef.Context.getDecayedType(OriginalType);
3598 TLB.push<DecayedTypeLoc>(Result);
3599 // Nothing to set for DecayedTypeLoc.
3600 return Result;
3601}
3602
3603template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003604QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003605 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003606 QualType PointeeType
3607 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003608 if (PointeeType.isNull())
3609 return QualType();
3610
3611 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003612 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003613 // A dependent pointer type 'T *' has is being transformed such
3614 // that an Objective-C class type is being replaced for 'T'. The
3615 // resulting pointer type is an ObjCObjectPointerType, not a
3616 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003617 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003618
John McCallc12c5bb2010-05-15 11:32:37 +00003619 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3620 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003621 return Result;
3622 }
John McCall43fed0d2010-11-12 08:19:04 +00003623
Douglas Gregor92e986e2010-04-22 16:44:27 +00003624 if (getDerived().AlwaysRebuild() ||
3625 PointeeType != TL.getPointeeLoc().getType()) {
3626 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3627 if (Result.isNull())
3628 return QualType();
3629 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003630
John McCallf85e1932011-06-15 23:02:42 +00003631 // Objective-C ARC can add lifetime qualifiers to the type that we're
3632 // pointing to.
3633 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003634
Douglas Gregor92e986e2010-04-22 16:44:27 +00003635 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3636 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003637 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003638}
Mike Stump1eb44332009-09-09 15:08:12 +00003639
3640template<typename Derived>
3641QualType
John McCalla2becad2009-10-21 00:40:46 +00003642TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003643 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003644 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003645 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3646 if (PointeeType.isNull())
3647 return QualType();
3648
3649 QualType Result = TL.getType();
3650 if (getDerived().AlwaysRebuild() ||
3651 PointeeType != TL.getPointeeLoc().getType()) {
3652 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003653 TL.getSigilLoc());
3654 if (Result.isNull())
3655 return QualType();
3656 }
3657
Douglas Gregor39968ad2010-04-22 16:50:51 +00003658 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003659 NewT.setSigilLoc(TL.getSigilLoc());
3660 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003661}
3662
John McCall85737a72009-10-30 00:06:24 +00003663/// Transforms a reference type. Note that somewhat paradoxically we
3664/// don't care whether the type itself is an l-value type or an r-value
3665/// type; we only care if the type was *written* as an l-value type
3666/// or an r-value type.
3667template<typename Derived>
3668QualType
3669TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003670 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003671 const ReferenceType *T = TL.getTypePtr();
3672
3673 // Note that this works with the pointee-as-written.
3674 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3675 if (PointeeType.isNull())
3676 return QualType();
3677
3678 QualType Result = TL.getType();
3679 if (getDerived().AlwaysRebuild() ||
3680 PointeeType != T->getPointeeTypeAsWritten()) {
3681 Result = getDerived().RebuildReferenceType(PointeeType,
3682 T->isSpelledAsLValue(),
3683 TL.getSigilLoc());
3684 if (Result.isNull())
3685 return QualType();
3686 }
3687
John McCallf85e1932011-06-15 23:02:42 +00003688 // Objective-C ARC can add lifetime qualifiers to the type that we're
3689 // referring to.
3690 TLB.TypeWasModifiedSafely(
3691 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3692
John McCall85737a72009-10-30 00:06:24 +00003693 // r-value references can be rebuilt as l-value references.
3694 ReferenceTypeLoc NewTL;
3695 if (isa<LValueReferenceType>(Result))
3696 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3697 else
3698 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3699 NewTL.setSigilLoc(TL.getSigilLoc());
3700
3701 return Result;
3702}
3703
Mike Stump1eb44332009-09-09 15:08:12 +00003704template<typename Derived>
3705QualType
John McCalla2becad2009-10-21 00:40:46 +00003706TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003707 LValueReferenceTypeLoc TL) {
3708 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003709}
3710
Mike Stump1eb44332009-09-09 15:08:12 +00003711template<typename Derived>
3712QualType
John McCalla2becad2009-10-21 00:40:46 +00003713TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003714 RValueReferenceTypeLoc TL) {
3715 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003716}
Mike Stump1eb44332009-09-09 15:08:12 +00003717
Douglas Gregor577f75a2009-08-04 16:50:30 +00003718template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003719QualType
John McCalla2becad2009-10-21 00:40:46 +00003720TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003721 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003722 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003723 if (PointeeType.isNull())
3724 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003725
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003726 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3727 TypeSourceInfo* NewClsTInfo = 0;
3728 if (OldClsTInfo) {
3729 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3730 if (!NewClsTInfo)
3731 return QualType();
3732 }
3733
3734 const MemberPointerType *T = TL.getTypePtr();
3735 QualType OldClsType = QualType(T->getClass(), 0);
3736 QualType NewClsType;
3737 if (NewClsTInfo)
3738 NewClsType = NewClsTInfo->getType();
3739 else {
3740 NewClsType = getDerived().TransformType(OldClsType);
3741 if (NewClsType.isNull())
3742 return QualType();
3743 }
Mike Stump1eb44332009-09-09 15:08:12 +00003744
John McCalla2becad2009-10-21 00:40:46 +00003745 QualType Result = TL.getType();
3746 if (getDerived().AlwaysRebuild() ||
3747 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003748 NewClsType != OldClsType) {
3749 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003750 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003751 if (Result.isNull())
3752 return QualType();
3753 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003754
John McCalla2becad2009-10-21 00:40:46 +00003755 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3756 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003757 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003758
3759 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003760}
3761
Mike Stump1eb44332009-09-09 15:08:12 +00003762template<typename Derived>
3763QualType
John McCalla2becad2009-10-21 00:40:46 +00003764TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003765 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003766 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003767 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003768 if (ElementType.isNull())
3769 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003770
John McCalla2becad2009-10-21 00:40:46 +00003771 QualType Result = TL.getType();
3772 if (getDerived().AlwaysRebuild() ||
3773 ElementType != T->getElementType()) {
3774 Result = getDerived().RebuildConstantArrayType(ElementType,
3775 T->getSizeModifier(),
3776 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003777 T->getIndexTypeCVRQualifiers(),
3778 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003779 if (Result.isNull())
3780 return QualType();
3781 }
Eli Friedman457a3772012-01-25 22:19:07 +00003782
3783 // We might have either a ConstantArrayType or a VariableArrayType now:
3784 // a ConstantArrayType is allowed to have an element type which is a
3785 // VariableArrayType if the type is dependent. Fortunately, all array
3786 // types have the same location layout.
3787 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003788 NewTL.setLBracketLoc(TL.getLBracketLoc());
3789 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003790
John McCalla2becad2009-10-21 00:40:46 +00003791 Expr *Size = TL.getSizeExpr();
3792 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003793 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3794 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003795 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003796 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003797 }
3798 NewTL.setSizeExpr(Size);
3799
3800 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003801}
Mike Stump1eb44332009-09-09 15:08:12 +00003802
Douglas Gregor577f75a2009-08-04 16:50:30 +00003803template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003804QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003805 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003806 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003807 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003808 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003809 if (ElementType.isNull())
3810 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003811
John McCalla2becad2009-10-21 00:40:46 +00003812 QualType Result = TL.getType();
3813 if (getDerived().AlwaysRebuild() ||
3814 ElementType != T->getElementType()) {
3815 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003816 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003817 T->getIndexTypeCVRQualifiers(),
3818 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003819 if (Result.isNull())
3820 return QualType();
3821 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003822
John McCalla2becad2009-10-21 00:40:46 +00003823 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3824 NewTL.setLBracketLoc(TL.getLBracketLoc());
3825 NewTL.setRBracketLoc(TL.getRBracketLoc());
3826 NewTL.setSizeExpr(0);
3827
3828 return Result;
3829}
3830
3831template<typename Derived>
3832QualType
3833TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003834 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003835 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003836 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3837 if (ElementType.isNull())
3838 return QualType();
3839
John McCall60d7b3a2010-08-24 06:29:42 +00003840 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003841 = getDerived().TransformExpr(T->getSizeExpr());
3842 if (SizeResult.isInvalid())
3843 return QualType();
3844
John McCall9ae2f072010-08-23 23:25:46 +00003845 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003846
3847 QualType Result = TL.getType();
3848 if (getDerived().AlwaysRebuild() ||
3849 ElementType != T->getElementType() ||
3850 Size != T->getSizeExpr()) {
3851 Result = getDerived().RebuildVariableArrayType(ElementType,
3852 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003853 Size,
John McCalla2becad2009-10-21 00:40:46 +00003854 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003855 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003856 if (Result.isNull())
3857 return QualType();
3858 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003859
John McCalla2becad2009-10-21 00:40:46 +00003860 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3861 NewTL.setLBracketLoc(TL.getLBracketLoc());
3862 NewTL.setRBracketLoc(TL.getRBracketLoc());
3863 NewTL.setSizeExpr(Size);
3864
3865 return Result;
3866}
3867
3868template<typename Derived>
3869QualType
3870TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003871 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003872 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003873 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3874 if (ElementType.isNull())
3875 return QualType();
3876
Richard Smithf6702a32011-12-20 02:08:33 +00003877 // Array bounds are constant expressions.
3878 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3879 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003880
John McCall3b657512011-01-19 10:06:00 +00003881 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3882 Expr *origSize = TL.getSizeExpr();
3883 if (!origSize) origSize = T->getSizeExpr();
3884
3885 ExprResult sizeResult
3886 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003887 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003888 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003889 return QualType();
3890
John McCall3b657512011-01-19 10:06:00 +00003891 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003892
3893 QualType Result = TL.getType();
3894 if (getDerived().AlwaysRebuild() ||
3895 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003896 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003897 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3898 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003899 size,
John McCalla2becad2009-10-21 00:40:46 +00003900 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003901 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003902 if (Result.isNull())
3903 return QualType();
3904 }
John McCalla2becad2009-10-21 00:40:46 +00003905
3906 // We might have any sort of array type now, but fortunately they
3907 // all have the same location layout.
3908 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3909 NewTL.setLBracketLoc(TL.getLBracketLoc());
3910 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003911 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003912
3913 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003914}
Mike Stump1eb44332009-09-09 15:08:12 +00003915
3916template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003917QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003918 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003919 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003920 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003921
3922 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003923 QualType ElementType = getDerived().TransformType(T->getElementType());
3924 if (ElementType.isNull())
3925 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003926
Richard Smithf6702a32011-12-20 02:08:33 +00003927 // Vector sizes are constant expressions.
3928 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3929 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003930
John McCall60d7b3a2010-08-24 06:29:42 +00003931 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003932 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003933 if (Size.isInvalid())
3934 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003935
John McCalla2becad2009-10-21 00:40:46 +00003936 QualType Result = TL.getType();
3937 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003938 ElementType != T->getElementType() ||
3939 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003940 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003941 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003942 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003943 if (Result.isNull())
3944 return QualType();
3945 }
John McCalla2becad2009-10-21 00:40:46 +00003946
3947 // Result might be dependent or not.
3948 if (isa<DependentSizedExtVectorType>(Result)) {
3949 DependentSizedExtVectorTypeLoc NewTL
3950 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3951 NewTL.setNameLoc(TL.getNameLoc());
3952 } else {
3953 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3954 NewTL.setNameLoc(TL.getNameLoc());
3955 }
3956
3957 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003958}
Mike Stump1eb44332009-09-09 15:08:12 +00003959
3960template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003961QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003962 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003963 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003964 QualType ElementType = getDerived().TransformType(T->getElementType());
3965 if (ElementType.isNull())
3966 return QualType();
3967
John McCalla2becad2009-10-21 00:40:46 +00003968 QualType Result = TL.getType();
3969 if (getDerived().AlwaysRebuild() ||
3970 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003971 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003972 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003973 if (Result.isNull())
3974 return QualType();
3975 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003976
John McCalla2becad2009-10-21 00:40:46 +00003977 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3978 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003979
John McCalla2becad2009-10-21 00:40:46 +00003980 return Result;
3981}
3982
3983template<typename Derived>
3984QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003985 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003986 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003987 QualType ElementType = getDerived().TransformType(T->getElementType());
3988 if (ElementType.isNull())
3989 return QualType();
3990
3991 QualType Result = TL.getType();
3992 if (getDerived().AlwaysRebuild() ||
3993 ElementType != T->getElementType()) {
3994 Result = getDerived().RebuildExtVectorType(ElementType,
3995 T->getNumElements(),
3996 /*FIXME*/ SourceLocation());
3997 if (Result.isNull())
3998 return QualType();
3999 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004000
John McCalla2becad2009-10-21 00:40:46 +00004001 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4002 NewTL.setNameLoc(TL.getNameLoc());
4003
4004 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004005}
Mike Stump1eb44332009-09-09 15:08:12 +00004006
David Blaikiedc84cd52013-02-20 22:23:23 +00004007template <typename Derived>
4008ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4009 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4010 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00004011 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004012 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004013
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004014 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004015 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004016 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004017 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004018 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004019
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004020 TypeLocBuilder TLB;
4021 TypeLoc NewTL = OldDI->getTypeLoc();
4022 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004023
4024 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004025 OldExpansionTL.getPatternLoc());
4026 if (Result.isNull())
4027 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004028
4029 Result = RebuildPackExpansionType(Result,
4030 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004031 OldExpansionTL.getEllipsisLoc(),
4032 NumExpansions);
4033 if (Result.isNull())
4034 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004035
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004036 PackExpansionTypeLoc NewExpansionTL
4037 = TLB.push<PackExpansionTypeLoc>(Result);
4038 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4039 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4040 } else
4041 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004042 if (!NewDI)
4043 return 0;
4044
John McCallfb44de92011-05-01 22:35:37 +00004045 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004046 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004047
4048 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4049 OldParm->getDeclContext(),
4050 OldParm->getInnerLocStart(),
4051 OldParm->getLocation(),
4052 OldParm->getIdentifier(),
4053 NewDI->getType(),
4054 NewDI,
4055 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004056 /* DefArg */ NULL);
4057 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4058 OldParm->getFunctionScopeIndex() + indexAdjustment);
4059 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004060}
4061
4062template<typename Derived>
4063bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004064 TransformFunctionTypeParams(SourceLocation Loc,
4065 ParmVarDecl **Params, unsigned NumParams,
4066 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004067 SmallVectorImpl<QualType> &OutParamTypes,
4068 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004069 int indexAdjustment = 0;
4070
Douglas Gregora009b592011-01-07 00:20:55 +00004071 for (unsigned i = 0; i != NumParams; ++i) {
4072 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004073 assert(OldParm->getFunctionScopeIndex() == i);
4074
David Blaikiedc84cd52013-02-20 22:23:23 +00004075 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004076 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004077 if (OldParm->isParameterPack()) {
4078 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004079 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004080
Douglas Gregor603cfb42011-01-05 23:12:31 +00004081 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004082 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004083 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004084 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4085 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004086 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4087
Douglas Gregor603cfb42011-01-05 23:12:31 +00004088 // Determine whether we should expand the parameter packs.
4089 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004090 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004091 Optional<unsigned> OrigNumExpansions =
4092 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004093 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004094 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4095 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004096 Unexpanded,
4097 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004098 RetainExpansion,
4099 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004100 return true;
4101 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004102
Douglas Gregor603cfb42011-01-05 23:12:31 +00004103 if (ShouldExpand) {
4104 // Expand the function parameter pack into multiple, separate
4105 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004106 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004107 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004108 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004109 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004110 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004111 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004112 OrigNumExpansions,
4113 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004114 if (!NewParm)
4115 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004116
Douglas Gregora009b592011-01-07 00:20:55 +00004117 OutParamTypes.push_back(NewParm->getType());
4118 if (PVars)
4119 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004120 }
Douglas Gregord3731192011-01-10 07:32:04 +00004121
4122 // If we're supposed to retain a pack expansion, do so by temporarily
4123 // forgetting the partially-substituted parameter pack.
4124 if (RetainExpansion) {
4125 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004126 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004127 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004128 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004129 OrigNumExpansions,
4130 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004131 if (!NewParm)
4132 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004133
Douglas Gregord3731192011-01-10 07:32:04 +00004134 OutParamTypes.push_back(NewParm->getType());
4135 if (PVars)
4136 PVars->push_back(NewParm);
4137 }
4138
John McCallfb44de92011-05-01 22:35:37 +00004139 // The next parameter should have the same adjustment as the
4140 // last thing we pushed, but we post-incremented indexAdjustment
4141 // on every push. Also, if we push nothing, the adjustment should
4142 // go down by one.
4143 indexAdjustment--;
4144
Douglas Gregor603cfb42011-01-05 23:12:31 +00004145 // We're done with the pack expansion.
4146 continue;
4147 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004148
4149 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004150 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004151 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4152 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004153 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004154 NumExpansions,
4155 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004156 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004157 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004158 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004159 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004160
John McCall21ef0fa2010-03-11 09:03:00 +00004161 if (!NewParm)
4162 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004163
Douglas Gregora009b592011-01-07 00:20:55 +00004164 OutParamTypes.push_back(NewParm->getType());
4165 if (PVars)
4166 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004167 continue;
4168 }
John McCall21ef0fa2010-03-11 09:03:00 +00004169
4170 // Deal with the possibility that we don't have a parameter
4171 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004172 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004173 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004174 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004175 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004176 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004177 = dyn_cast<PackExpansionType>(OldType)) {
4178 // We have a function parameter pack that may need to be expanded.
4179 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004180 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004181 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004182
Douglas Gregor603cfb42011-01-05 23:12:31 +00004183 // Determine whether we should expand the parameter packs.
4184 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004185 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004186 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004187 Unexpanded,
4188 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004189 RetainExpansion,
4190 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004191 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004192 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004193
Douglas Gregor603cfb42011-01-05 23:12:31 +00004194 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004195 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004196 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004197 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004198 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4199 QualType NewType = getDerived().TransformType(Pattern);
4200 if (NewType.isNull())
4201 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004202
Douglas Gregora009b592011-01-07 00:20:55 +00004203 OutParamTypes.push_back(NewType);
4204 if (PVars)
4205 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004206 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004207
Douglas Gregor603cfb42011-01-05 23:12:31 +00004208 // We're done with the pack expansion.
4209 continue;
4210 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004211
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004212 // If we're supposed to retain a pack expansion, do so by temporarily
4213 // forgetting the partially-substituted parameter pack.
4214 if (RetainExpansion) {
4215 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4216 QualType NewType = getDerived().TransformType(Pattern);
4217 if (NewType.isNull())
4218 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004219
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004220 OutParamTypes.push_back(NewType);
4221 if (PVars)
4222 PVars->push_back(0);
4223 }
Douglas Gregord3731192011-01-10 07:32:04 +00004224
Chad Rosier4a9d7952012-08-08 18:46:20 +00004225 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004226 // expansion.
4227 OldType = Expansion->getPattern();
4228 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004229 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4230 NewType = getDerived().TransformType(OldType);
4231 } else {
4232 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004233 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004234
Douglas Gregor603cfb42011-01-05 23:12:31 +00004235 if (NewType.isNull())
4236 return true;
4237
4238 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004239 NewType = getSema().Context.getPackExpansionType(NewType,
4240 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004241
Douglas Gregora009b592011-01-07 00:20:55 +00004242 OutParamTypes.push_back(NewType);
4243 if (PVars)
4244 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004245 }
4246
John McCallfb44de92011-05-01 22:35:37 +00004247#ifndef NDEBUG
4248 if (PVars) {
4249 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4250 if (ParmVarDecl *parm = (*PVars)[i])
4251 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004252 }
John McCallfb44de92011-05-01 22:35:37 +00004253#endif
4254
4255 return false;
4256}
John McCall21ef0fa2010-03-11 09:03:00 +00004257
4258template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004259QualType
John McCalla2becad2009-10-21 00:40:46 +00004260TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004261 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004262 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4263}
4264
4265template<typename Derived>
4266QualType
4267TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4268 FunctionProtoTypeLoc TL,
4269 CXXRecordDecl *ThisContext,
4270 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004271 // Transform the parameters and return type.
4272 //
Richard Smithe6975e92012-04-17 00:58:00 +00004273 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004274 // When the function has a trailing return type, we instantiate the
4275 // parameters before the return type, since the return type can then refer
4276 // to the parameters themselves (via decltype, sizeof, etc.).
4277 //
Chris Lattner686775d2011-07-20 06:58:45 +00004278 SmallVector<QualType, 4> ParamTypes;
4279 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004280 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004281
Douglas Gregordab60ad2010-10-01 18:44:50 +00004282 QualType ResultType;
4283
Richard Smith9fbf3272012-08-14 22:51:13 +00004284 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004285 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004286 TL.getParmArray(),
4287 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004288 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004289 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004290 return QualType();
4291
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004292 {
4293 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004294 // If a declaration declares a member function or member function
4295 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004296 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004297 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004298 // declarator.
4299 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004300
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004301 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4302 if (ResultType.isNull())
4303 return QualType();
4304 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004305 }
4306 else {
4307 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4308 if (ResultType.isNull())
4309 return QualType();
4310
Chad Rosier4a9d7952012-08-08 18:46:20 +00004311 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004312 TL.getParmArray(),
4313 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004314 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004315 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004316 return QualType();
4317 }
4318
Richard Smithe6975e92012-04-17 00:58:00 +00004319 // FIXME: Need to transform the exception-specification too.
4320
John McCalla2becad2009-10-21 00:40:46 +00004321 QualType Result = TL.getType();
4322 if (getDerived().AlwaysRebuild() ||
4323 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004324 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004325 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004326 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004327 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004328 if (Result.isNull())
4329 return QualType();
4330 }
Mike Stump1eb44332009-09-09 15:08:12 +00004331
John McCalla2becad2009-10-21 00:40:46 +00004332 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004333 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004334 NewTL.setLParenLoc(TL.getLParenLoc());
4335 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004336 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004337 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4338 NewTL.setArg(i, ParamDecls[i]);
4339
4340 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004341}
Mike Stump1eb44332009-09-09 15:08:12 +00004342
Douglas Gregor577f75a2009-08-04 16:50:30 +00004343template<typename Derived>
4344QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004345 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004346 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004347 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004348 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4349 if (ResultType.isNull())
4350 return QualType();
4351
4352 QualType Result = TL.getType();
4353 if (getDerived().AlwaysRebuild() ||
4354 ResultType != T->getResultType())
4355 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4356
4357 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004358 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004359 NewTL.setLParenLoc(TL.getLParenLoc());
4360 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004361 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004362
4363 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004364}
Mike Stump1eb44332009-09-09 15:08:12 +00004365
John McCalled976492009-12-04 22:46:56 +00004366template<typename Derived> QualType
4367TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004368 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004369 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004370 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004371 if (!D)
4372 return QualType();
4373
4374 QualType Result = TL.getType();
4375 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4376 Result = getDerived().RebuildUnresolvedUsingType(D);
4377 if (Result.isNull())
4378 return QualType();
4379 }
4380
4381 // We might get an arbitrary type spec type back. We should at
4382 // least always get a type spec type, though.
4383 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4384 NewTL.setNameLoc(TL.getNameLoc());
4385
4386 return Result;
4387}
4388
Douglas Gregor577f75a2009-08-04 16:50:30 +00004389template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004390QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004391 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004392 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004393 TypedefNameDecl *Typedef
4394 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4395 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004396 if (!Typedef)
4397 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004398
John McCalla2becad2009-10-21 00:40:46 +00004399 QualType Result = TL.getType();
4400 if (getDerived().AlwaysRebuild() ||
4401 Typedef != T->getDecl()) {
4402 Result = getDerived().RebuildTypedefType(Typedef);
4403 if (Result.isNull())
4404 return QualType();
4405 }
Mike Stump1eb44332009-09-09 15:08:12 +00004406
John McCalla2becad2009-10-21 00:40:46 +00004407 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4408 NewTL.setNameLoc(TL.getNameLoc());
4409
4410 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004411}
Mike Stump1eb44332009-09-09 15:08:12 +00004412
Douglas Gregor577f75a2009-08-04 16:50:30 +00004413template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004414QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004415 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004416 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004417 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4418 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004419
John McCall60d7b3a2010-08-24 06:29:42 +00004420 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004421 if (E.isInvalid())
4422 return QualType();
4423
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004424 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4425 if (E.isInvalid())
4426 return QualType();
4427
John McCalla2becad2009-10-21 00:40:46 +00004428 QualType Result = TL.getType();
4429 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004430 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004431 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004432 if (Result.isNull())
4433 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004434 }
John McCalla2becad2009-10-21 00:40:46 +00004435 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004436
John McCalla2becad2009-10-21 00:40:46 +00004437 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004438 NewTL.setTypeofLoc(TL.getTypeofLoc());
4439 NewTL.setLParenLoc(TL.getLParenLoc());
4440 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004441
4442 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004443}
Mike Stump1eb44332009-09-09 15:08:12 +00004444
4445template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004446QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004447 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004448 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4449 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4450 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004451 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004452
John McCalla2becad2009-10-21 00:40:46 +00004453 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004454 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4455 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004456 if (Result.isNull())
4457 return QualType();
4458 }
Mike Stump1eb44332009-09-09 15:08:12 +00004459
John McCalla2becad2009-10-21 00:40:46 +00004460 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004461 NewTL.setTypeofLoc(TL.getTypeofLoc());
4462 NewTL.setLParenLoc(TL.getLParenLoc());
4463 NewTL.setRParenLoc(TL.getRParenLoc());
4464 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004465
4466 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004467}
Mike Stump1eb44332009-09-09 15:08:12 +00004468
4469template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004470QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004471 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004472 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004473
Douglas Gregor670444e2009-08-04 22:27:00 +00004474 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004475 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4476 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004477
John McCall60d7b3a2010-08-24 06:29:42 +00004478 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004479 if (E.isInvalid())
4480 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004481
Richard Smith76f3f692012-02-22 02:04:18 +00004482 E = getSema().ActOnDecltypeExpression(E.take());
4483 if (E.isInvalid())
4484 return QualType();
4485
John McCalla2becad2009-10-21 00:40:46 +00004486 QualType Result = TL.getType();
4487 if (getDerived().AlwaysRebuild() ||
4488 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004489 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004490 if (Result.isNull())
4491 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004492 }
John McCalla2becad2009-10-21 00:40:46 +00004493 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004494
John McCalla2becad2009-10-21 00:40:46 +00004495 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4496 NewTL.setNameLoc(TL.getNameLoc());
4497
4498 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004499}
4500
4501template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004502QualType TreeTransform<Derived>::TransformUnaryTransformType(
4503 TypeLocBuilder &TLB,
4504 UnaryTransformTypeLoc TL) {
4505 QualType Result = TL.getType();
4506 if (Result->isDependentType()) {
4507 const UnaryTransformType *T = TL.getTypePtr();
4508 QualType NewBase =
4509 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4510 Result = getDerived().RebuildUnaryTransformType(NewBase,
4511 T->getUTTKind(),
4512 TL.getKWLoc());
4513 if (Result.isNull())
4514 return QualType();
4515 }
4516
4517 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4518 NewTL.setKWLoc(TL.getKWLoc());
4519 NewTL.setParensRange(TL.getParensRange());
4520 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4521 return Result;
4522}
4523
4524template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004525QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4526 AutoTypeLoc TL) {
4527 const AutoType *T = TL.getTypePtr();
4528 QualType OldDeduced = T->getDeducedType();
4529 QualType NewDeduced;
4530 if (!OldDeduced.isNull()) {
4531 NewDeduced = getDerived().TransformType(OldDeduced);
4532 if (NewDeduced.isNull())
4533 return QualType();
4534 }
4535
4536 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004537 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4538 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004539 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004540 if (Result.isNull())
4541 return QualType();
4542 }
4543
4544 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4545 NewTL.setNameLoc(TL.getNameLoc());
4546
4547 return Result;
4548}
4549
4550template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004551QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004552 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004553 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004554 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004555 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4556 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004557 if (!Record)
4558 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004559
John McCalla2becad2009-10-21 00:40:46 +00004560 QualType Result = TL.getType();
4561 if (getDerived().AlwaysRebuild() ||
4562 Record != T->getDecl()) {
4563 Result = getDerived().RebuildRecordType(Record);
4564 if (Result.isNull())
4565 return QualType();
4566 }
Mike Stump1eb44332009-09-09 15:08:12 +00004567
John McCalla2becad2009-10-21 00:40:46 +00004568 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4569 NewTL.setNameLoc(TL.getNameLoc());
4570
4571 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004572}
Mike Stump1eb44332009-09-09 15:08:12 +00004573
4574template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004575QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004576 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004577 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004578 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004579 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4580 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004581 if (!Enum)
4582 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004583
John McCalla2becad2009-10-21 00:40:46 +00004584 QualType Result = TL.getType();
4585 if (getDerived().AlwaysRebuild() ||
4586 Enum != T->getDecl()) {
4587 Result = getDerived().RebuildEnumType(Enum);
4588 if (Result.isNull())
4589 return QualType();
4590 }
Mike Stump1eb44332009-09-09 15:08:12 +00004591
John McCalla2becad2009-10-21 00:40:46 +00004592 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4593 NewTL.setNameLoc(TL.getNameLoc());
4594
4595 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004596}
John McCall7da24312009-09-05 00:15:47 +00004597
John McCall3cb0ebd2010-03-10 03:28:59 +00004598template<typename Derived>
4599QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4600 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004601 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004602 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4603 TL.getTypePtr()->getDecl());
4604 if (!D) return QualType();
4605
4606 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4607 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4608 return T;
4609}
4610
Douglas Gregor577f75a2009-08-04 16:50:30 +00004611template<typename Derived>
4612QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004613 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004614 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004615 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004616}
4617
Mike Stump1eb44332009-09-09 15:08:12 +00004618template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004619QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004620 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004621 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004622 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004623
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004624 // Substitute into the replacement type, which itself might involve something
4625 // that needs to be transformed. This only tends to occur with default
4626 // template arguments of template template parameters.
4627 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4628 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4629 if (Replacement.isNull())
4630 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004631
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004632 // Always canonicalize the replacement type.
4633 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4634 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004635 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004636 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004637
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004638 // Propagate type-source information.
4639 SubstTemplateTypeParmTypeLoc NewTL
4640 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4641 NewTL.setNameLoc(TL.getNameLoc());
4642 return Result;
4643
John McCall49a832b2009-10-18 09:09:24 +00004644}
4645
4646template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004647QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4648 TypeLocBuilder &TLB,
4649 SubstTemplateTypeParmPackTypeLoc TL) {
4650 return TransformTypeSpecType(TLB, TL);
4651}
4652
4653template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004654QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004655 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004656 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004657 const TemplateSpecializationType *T = TL.getTypePtr();
4658
Douglas Gregor1d752d72011-03-02 18:46:51 +00004659 // The nested-name-specifier never matters in a TemplateSpecializationType,
4660 // because we can't have a dependent nested-name-specifier anyway.
4661 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004662 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004663 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4664 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004665 if (Template.isNull())
4666 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004667
John McCall43fed0d2010-11-12 08:19:04 +00004668 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4669}
4670
Eli Friedmanb001de72011-10-06 23:00:33 +00004671template<typename Derived>
4672QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4673 AtomicTypeLoc TL) {
4674 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4675 if (ValueType.isNull())
4676 return QualType();
4677
4678 QualType Result = TL.getType();
4679 if (getDerived().AlwaysRebuild() ||
4680 ValueType != TL.getValueLoc().getType()) {
4681 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4682 if (Result.isNull())
4683 return QualType();
4684 }
4685
4686 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4687 NewTL.setKWLoc(TL.getKWLoc());
4688 NewTL.setLParenLoc(TL.getLParenLoc());
4689 NewTL.setRParenLoc(TL.getRParenLoc());
4690
4691 return Result;
4692}
4693
Chad Rosier4a9d7952012-08-08 18:46:20 +00004694 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004695 /// container that provides a \c getArgLoc() member function.
4696 ///
4697 /// This iterator is intended to be used with the iterator form of
4698 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4699 template<typename ArgLocContainer>
4700 class TemplateArgumentLocContainerIterator {
4701 ArgLocContainer *Container;
4702 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004703
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004704 public:
4705 typedef TemplateArgumentLoc value_type;
4706 typedef TemplateArgumentLoc reference;
4707 typedef int difference_type;
4708 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004709
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004710 class pointer {
4711 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004712
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004713 public:
4714 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004715
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004716 const TemplateArgumentLoc *operator->() const {
4717 return &Arg;
4718 }
4719 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004720
4721
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004722 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004723
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004724 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4725 unsigned Index)
4726 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004727
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004728 TemplateArgumentLocContainerIterator &operator++() {
4729 ++Index;
4730 return *this;
4731 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004732
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004733 TemplateArgumentLocContainerIterator operator++(int) {
4734 TemplateArgumentLocContainerIterator Old(*this);
4735 ++(*this);
4736 return Old;
4737 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004738
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004739 TemplateArgumentLoc operator*() const {
4740 return Container->getArgLoc(Index);
4741 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004742
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004743 pointer operator->() const {
4744 return pointer(Container->getArgLoc(Index));
4745 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004746
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004747 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004748 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004749 return X.Container == Y.Container && X.Index == Y.Index;
4750 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004751
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004752 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004753 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004754 return !(X == Y);
4755 }
4756 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004757
4758
John McCall43fed0d2010-11-12 08:19:04 +00004759template <typename Derived>
4760QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4761 TypeLocBuilder &TLB,
4762 TemplateSpecializationTypeLoc TL,
4763 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004764 TemplateArgumentListInfo NewTemplateArgs;
4765 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4766 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004767 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4768 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004769 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004770 ArgIterator(TL, TL.getNumArgs()),
4771 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004772 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004773
John McCall833ca992009-10-29 08:12:44 +00004774 // FIXME: maybe don't rebuild if all the template arguments are the same.
4775
4776 QualType Result =
4777 getDerived().RebuildTemplateSpecializationType(Template,
4778 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004779 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004780
4781 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004782 // Specializations of template template parameters are represented as
4783 // TemplateSpecializationTypes, and substitution of type alias templates
4784 // within a dependent context can transform them into
4785 // DependentTemplateSpecializationTypes.
4786 if (isa<DependentTemplateSpecializationType>(Result)) {
4787 DependentTemplateSpecializationTypeLoc NewTL
4788 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004789 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004790 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004791 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004792 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004793 NewTL.setLAngleLoc(TL.getLAngleLoc());
4794 NewTL.setRAngleLoc(TL.getRAngleLoc());
4795 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4796 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4797 return Result;
4798 }
4799
John McCall833ca992009-10-29 08:12:44 +00004800 TemplateSpecializationTypeLoc NewTL
4801 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004802 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004803 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4804 NewTL.setLAngleLoc(TL.getLAngleLoc());
4805 NewTL.setRAngleLoc(TL.getRAngleLoc());
4806 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4807 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004808 }
Mike Stump1eb44332009-09-09 15:08:12 +00004809
John McCall833ca992009-10-29 08:12:44 +00004810 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004811}
Mike Stump1eb44332009-09-09 15:08:12 +00004812
Douglas Gregora88f09f2011-02-28 17:23:35 +00004813template <typename Derived>
4814QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4815 TypeLocBuilder &TLB,
4816 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004817 TemplateName Template,
4818 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004819 TemplateArgumentListInfo NewTemplateArgs;
4820 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4821 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4822 typedef TemplateArgumentLocContainerIterator<
4823 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004824 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004825 ArgIterator(TL, TL.getNumArgs()),
4826 NewTemplateArgs))
4827 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004828
Douglas Gregora88f09f2011-02-28 17:23:35 +00004829 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004830
Douglas Gregora88f09f2011-02-28 17:23:35 +00004831 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4832 QualType Result
4833 = getSema().Context.getDependentTemplateSpecializationType(
4834 TL.getTypePtr()->getKeyword(),
4835 DTN->getQualifier(),
4836 DTN->getIdentifier(),
4837 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004838
Douglas Gregora88f09f2011-02-28 17:23:35 +00004839 DependentTemplateSpecializationTypeLoc NewTL
4840 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004841 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004842 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004843 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004844 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004845 NewTL.setLAngleLoc(TL.getLAngleLoc());
4846 NewTL.setRAngleLoc(TL.getRAngleLoc());
4847 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4848 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4849 return Result;
4850 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004851
4852 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004853 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004854 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004855 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004856
Douglas Gregora88f09f2011-02-28 17:23:35 +00004857 if (!Result.isNull()) {
4858 /// FIXME: Wrap this in an elaborated-type-specifier?
4859 TemplateSpecializationTypeLoc NewTL
4860 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004861 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004862 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004863 NewTL.setLAngleLoc(TL.getLAngleLoc());
4864 NewTL.setRAngleLoc(TL.getRAngleLoc());
4865 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4866 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4867 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004868
Douglas Gregora88f09f2011-02-28 17:23:35 +00004869 return Result;
4870}
4871
Mike Stump1eb44332009-09-09 15:08:12 +00004872template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004873QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004874TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004875 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004876 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004877
Douglas Gregor9e876872011-03-01 18:12:44 +00004878 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004879 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004880 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004881 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004882 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4883 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004884 return QualType();
4885 }
Mike Stump1eb44332009-09-09 15:08:12 +00004886
John McCall43fed0d2010-11-12 08:19:04 +00004887 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4888 if (NamedT.isNull())
4889 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004890
Richard Smith3e4c6c42011-05-05 21:57:07 +00004891 // C++0x [dcl.type.elab]p2:
4892 // If the identifier resolves to a typedef-name or the simple-template-id
4893 // resolves to an alias template specialization, the
4894 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004895 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4896 if (const TemplateSpecializationType *TST =
4897 NamedT->getAs<TemplateSpecializationType>()) {
4898 TemplateName Template = TST->getTemplateName();
4899 if (TypeAliasTemplateDecl *TAT =
4900 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4901 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4902 diag::err_tag_reference_non_tag) << 4;
4903 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4904 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004905 }
4906 }
4907
John McCalla2becad2009-10-21 00:40:46 +00004908 QualType Result = TL.getType();
4909 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004910 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004911 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004912 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004913 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004914 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004915 if (Result.isNull())
4916 return QualType();
4917 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004918
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004919 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004920 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004921 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004922 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004923}
Mike Stump1eb44332009-09-09 15:08:12 +00004924
4925template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004926QualType TreeTransform<Derived>::TransformAttributedType(
4927 TypeLocBuilder &TLB,
4928 AttributedTypeLoc TL) {
4929 const AttributedType *oldType = TL.getTypePtr();
4930 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4931 if (modifiedType.isNull())
4932 return QualType();
4933
4934 QualType result = TL.getType();
4935
4936 // FIXME: dependent operand expressions?
4937 if (getDerived().AlwaysRebuild() ||
4938 modifiedType != oldType->getModifiedType()) {
4939 // TODO: this is really lame; we should really be rebuilding the
4940 // equivalent type from first principles.
4941 QualType equivalentType
4942 = getDerived().TransformType(oldType->getEquivalentType());
4943 if (equivalentType.isNull())
4944 return QualType();
4945 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4946 modifiedType,
4947 equivalentType);
4948 }
4949
4950 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4951 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4952 if (TL.hasAttrOperand())
4953 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4954 if (TL.hasAttrExprOperand())
4955 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4956 else if (TL.hasAttrEnumOperand())
4957 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4958
4959 return result;
4960}
4961
4962template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004963QualType
4964TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4965 ParenTypeLoc TL) {
4966 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4967 if (Inner.isNull())
4968 return QualType();
4969
4970 QualType Result = TL.getType();
4971 if (getDerived().AlwaysRebuild() ||
4972 Inner != TL.getInnerLoc().getType()) {
4973 Result = getDerived().RebuildParenType(Inner);
4974 if (Result.isNull())
4975 return QualType();
4976 }
4977
4978 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4979 NewTL.setLParenLoc(TL.getLParenLoc());
4980 NewTL.setRParenLoc(TL.getRParenLoc());
4981 return Result;
4982}
4983
4984template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004985QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004986 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004987 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004988
Douglas Gregor2494dd02011-03-01 01:34:45 +00004989 NestedNameSpecifierLoc QualifierLoc
4990 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4991 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004992 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004993
John McCall33500952010-06-11 00:33:02 +00004994 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004995 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004996 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004997 QualifierLoc,
4998 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004999 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00005000 if (Result.isNull())
5001 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005002
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005003 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5004 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00005005 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5006
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005007 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005008 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005009 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00005010 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005011 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005012 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00005013 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005014 NewTL.setNameLoc(TL.getNameLoc());
5015 }
John McCalla2becad2009-10-21 00:40:46 +00005016 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005017}
Mike Stump1eb44332009-09-09 15:08:12 +00005018
Douglas Gregor577f75a2009-08-04 16:50:30 +00005019template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00005020QualType TreeTransform<Derived>::
5021 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005022 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005023 NestedNameSpecifierLoc QualifierLoc;
5024 if (TL.getQualifierLoc()) {
5025 QualifierLoc
5026 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5027 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00005028 return QualType();
5029 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005030
John McCall43fed0d2010-11-12 08:19:04 +00005031 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005032 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005033}
5034
5035template<typename Derived>
5036QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005037TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5038 DependentTemplateSpecializationTypeLoc TL,
5039 NestedNameSpecifierLoc QualifierLoc) {
5040 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005041
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005042 TemplateArgumentListInfo NewTemplateArgs;
5043 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5044 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005045
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005046 typedef TemplateArgumentLocContainerIterator<
5047 DependentTemplateSpecializationTypeLoc> ArgIterator;
5048 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5049 ArgIterator(TL, TL.getNumArgs()),
5050 NewTemplateArgs))
5051 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005052
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005053 QualType Result
5054 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5055 QualifierLoc,
5056 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005057 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005058 NewTemplateArgs);
5059 if (Result.isNull())
5060 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005061
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005062 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5063 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005064
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005065 // Copy information relevant to the template specialization.
5066 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005067 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005068 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005069 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005070 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5071 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005072 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005073 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005074
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005075 // Copy information relevant to the elaborated type.
5076 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005077 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005078 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005079 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5080 DependentTemplateSpecializationTypeLoc SpecTL
5081 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005082 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005083 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005084 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005085 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005086 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5087 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005088 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005089 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005090 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005091 TemplateSpecializationTypeLoc SpecTL
5092 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005093 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005094 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005095 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5096 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005097 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005098 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005099 }
5100 return Result;
5101}
5102
5103template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005104QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5105 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005106 QualType Pattern
5107 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005108 if (Pattern.isNull())
5109 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005110
5111 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005112 if (getDerived().AlwaysRebuild() ||
5113 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005114 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005115 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005116 TL.getEllipsisLoc(),
5117 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005118 if (Result.isNull())
5119 return QualType();
5120 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005121
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005122 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5123 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5124 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005125}
5126
5127template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005128QualType
5129TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005130 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005131 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005132 TLB.pushFullCopy(TL);
5133 return TL.getType();
5134}
5135
5136template<typename Derived>
5137QualType
5138TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005139 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005140 // ObjCObjectType is never dependent.
5141 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005142 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005143}
Mike Stump1eb44332009-09-09 15:08:12 +00005144
5145template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005146QualType
5147TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005148 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005149 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005150 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005151 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005152}
5153
Douglas Gregor577f75a2009-08-04 16:50:30 +00005154//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005155// Statement transformation
5156//===----------------------------------------------------------------------===//
5157template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005158StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005159TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005160 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005161}
5162
5163template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005164StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005165TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5166 return getDerived().TransformCompoundStmt(S, false);
5167}
5168
5169template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005170StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005171TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005172 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005173 Sema::CompoundScopeRAII CompoundScope(getSema());
5174
John McCall7114cba2010-08-27 19:56:05 +00005175 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005176 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005177 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005178 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5179 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005180 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005181 if (Result.isInvalid()) {
5182 // Immediately fail if this was a DeclStmt, since it's very
5183 // likely that this will cause problems for future statements.
5184 if (isa<DeclStmt>(*B))
5185 return StmtError();
5186
5187 // Otherwise, just keep processing substatements and fail later.
5188 SubStmtInvalid = true;
5189 continue;
5190 }
Mike Stump1eb44332009-09-09 15:08:12 +00005191
Douglas Gregor43959a92009-08-20 07:17:43 +00005192 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5193 Statements.push_back(Result.takeAs<Stmt>());
5194 }
Mike Stump1eb44332009-09-09 15:08:12 +00005195
John McCall7114cba2010-08-27 19:56:05 +00005196 if (SubStmtInvalid)
5197 return StmtError();
5198
Douglas Gregor43959a92009-08-20 07:17:43 +00005199 if (!getDerived().AlwaysRebuild() &&
5200 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005201 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005202
5203 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005204 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005205 S->getRBracLoc(),
5206 IsStmtExpr);
5207}
Mike Stump1eb44332009-09-09 15:08:12 +00005208
Douglas Gregor43959a92009-08-20 07:17:43 +00005209template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005210StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005211TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005212 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005213 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005214 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5215 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005216
Eli Friedman264c1f82009-11-19 03:14:00 +00005217 // Transform the left-hand case value.
5218 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005219 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005220 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005221 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005222
Eli Friedman264c1f82009-11-19 03:14:00 +00005223 // Transform the right-hand case value (for the GNU case-range extension).
5224 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005225 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005226 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005227 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005228 }
Mike Stump1eb44332009-09-09 15:08:12 +00005229
Douglas Gregor43959a92009-08-20 07:17:43 +00005230 // Build the case statement.
5231 // Case statements are always rebuilt so that they will attached to their
5232 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005233 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005234 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005235 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005236 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005237 S->getColonLoc());
5238 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005239 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005240
Douglas Gregor43959a92009-08-20 07:17:43 +00005241 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005242 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005243 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005244 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005245
Douglas Gregor43959a92009-08-20 07:17:43 +00005246 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005247 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005248}
5249
5250template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005251StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005252TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005253 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005254 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005255 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005256 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005257
Douglas Gregor43959a92009-08-20 07:17:43 +00005258 // Default statements are always rebuilt
5259 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005260 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005261}
Mike Stump1eb44332009-09-09 15:08:12 +00005262
Douglas Gregor43959a92009-08-20 07:17:43 +00005263template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005264StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005265TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005266 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005267 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005268 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005269
Chris Lattner57ad3782011-02-17 20:34:02 +00005270 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5271 S->getDecl());
5272 if (!LD)
5273 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005274
5275
Douglas Gregor43959a92009-08-20 07:17:43 +00005276 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005277 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005278 cast<LabelDecl>(LD), SourceLocation(),
5279 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005280}
Mike Stump1eb44332009-09-09 15:08:12 +00005281
Douglas Gregor43959a92009-08-20 07:17:43 +00005282template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005283StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005284TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5285 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5286 if (SubStmt.isInvalid())
5287 return StmtError();
5288
5289 // TODO: transform attributes
5290 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5291 return S;
5292
5293 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5294 S->getAttrs(),
5295 SubStmt.get());
5296}
5297
5298template<typename Derived>
5299StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005300TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005301 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005302 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005303 VarDecl *ConditionVar = 0;
5304 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005305 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005306 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005307 getDerived().TransformDefinition(
5308 S->getConditionVariable()->getLocation(),
5309 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005310 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005311 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005312 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005313 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005314
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005315 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005316 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005317
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005318 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005319 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005320 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005321 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005322 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005323 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005324
John McCall9ae2f072010-08-23 23:25:46 +00005325 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005326 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005327 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005328
John McCall9ae2f072010-08-23 23:25:46 +00005329 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5330 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005331 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005332
Douglas Gregor43959a92009-08-20 07:17:43 +00005333 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005334 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005335 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005336 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005337
Douglas Gregor43959a92009-08-20 07:17:43 +00005338 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005339 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005340 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005341 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005342
Douglas Gregor43959a92009-08-20 07:17:43 +00005343 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005344 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005345 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005346 Then.get() == S->getThen() &&
5347 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005348 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005349
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005350 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005351 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005352 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005353}
5354
5355template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005356StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005357TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005358 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005359 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005360 VarDecl *ConditionVar = 0;
5361 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005362 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005363 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005364 getDerived().TransformDefinition(
5365 S->getConditionVariable()->getLocation(),
5366 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005367 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005368 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005369 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005370 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005371
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005372 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005373 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005374 }
Mike Stump1eb44332009-09-09 15:08:12 +00005375
Douglas Gregor43959a92009-08-20 07:17:43 +00005376 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005377 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005378 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005379 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005380 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005381 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005382
Douglas Gregor43959a92009-08-20 07:17:43 +00005383 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005384 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005385 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005386 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005387
Douglas Gregor43959a92009-08-20 07:17:43 +00005388 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005389 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5390 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005391}
Mike Stump1eb44332009-09-09 15:08:12 +00005392
Douglas Gregor43959a92009-08-20 07:17:43 +00005393template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005394StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005395TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005396 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005397 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005398 VarDecl *ConditionVar = 0;
5399 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005400 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005401 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005402 getDerived().TransformDefinition(
5403 S->getConditionVariable()->getLocation(),
5404 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005405 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005406 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005407 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005408 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005409
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005410 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005411 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005412
5413 if (S->getCond()) {
5414 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005415 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005416 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005417 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005418 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005419 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005420 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005421 }
Mike Stump1eb44332009-09-09 15:08:12 +00005422
John McCall9ae2f072010-08-23 23:25:46 +00005423 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5424 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005425 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005426
Douglas Gregor43959a92009-08-20 07:17:43 +00005427 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005428 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005429 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005430 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005431
Douglas Gregor43959a92009-08-20 07:17:43 +00005432 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005433 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005434 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005435 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005436 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005437
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005438 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005439 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005440}
Mike Stump1eb44332009-09-09 15:08:12 +00005441
Douglas Gregor43959a92009-08-20 07:17:43 +00005442template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005443StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005444TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005445 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005446 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005447 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005448 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005449
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005450 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005451 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005452 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005453 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005454
Douglas Gregor43959a92009-08-20 07:17:43 +00005455 if (!getDerived().AlwaysRebuild() &&
5456 Cond.get() == S->getCond() &&
5457 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005458 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005459
John McCall9ae2f072010-08-23 23:25:46 +00005460 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5461 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005462 S->getRParenLoc());
5463}
Mike Stump1eb44332009-09-09 15:08:12 +00005464
Douglas Gregor43959a92009-08-20 07:17:43 +00005465template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005466StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005467TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005468 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005469 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005470 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005471 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005472
Douglas Gregor43959a92009-08-20 07:17:43 +00005473 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005474 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005475 VarDecl *ConditionVar = 0;
5476 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005477 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005478 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005479 getDerived().TransformDefinition(
5480 S->getConditionVariable()->getLocation(),
5481 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005482 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005483 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005484 } else {
5485 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005486
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005487 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005488 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005489
5490 if (S->getCond()) {
5491 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005492 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005493 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005494 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005495 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005496
John McCall9ae2f072010-08-23 23:25:46 +00005497 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005498 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005499 }
Mike Stump1eb44332009-09-09 15:08:12 +00005500
Chad Rosier4a9d7952012-08-08 18:46:20 +00005501 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005502 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005503 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005504
Douglas Gregor43959a92009-08-20 07:17:43 +00005505 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005506 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005507 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005508 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005509
Richard Smith41956372013-01-14 22:39:08 +00005510 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005511 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005512 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005513
Douglas Gregor43959a92009-08-20 07:17:43 +00005514 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005515 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005516 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005517 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005518
Douglas Gregor43959a92009-08-20 07:17:43 +00005519 if (!getDerived().AlwaysRebuild() &&
5520 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005521 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005522 Inc.get() == S->getInc() &&
5523 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005524 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005525
Douglas Gregor43959a92009-08-20 07:17:43 +00005526 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005527 Init.get(), FullCond, ConditionVar,
5528 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005529}
5530
5531template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005532StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005533TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005534 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5535 S->getLabel());
5536 if (!LD)
5537 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005538
Douglas Gregor43959a92009-08-20 07:17:43 +00005539 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005540 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005541 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005542}
5543
5544template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005545StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005546TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005547 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005548 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005549 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005550 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005551
Douglas Gregor43959a92009-08-20 07:17:43 +00005552 if (!getDerived().AlwaysRebuild() &&
5553 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005554 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005555
5556 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005557 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005558}
5559
5560template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005561StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005562TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005563 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005564}
Mike Stump1eb44332009-09-09 15:08:12 +00005565
Douglas Gregor43959a92009-08-20 07:17:43 +00005566template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005567StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005568TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005569 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005570}
Mike Stump1eb44332009-09-09 15:08:12 +00005571
Douglas Gregor43959a92009-08-20 07:17:43 +00005572template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005573StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005574TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005575 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005576 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005577 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005578
Mike Stump1eb44332009-09-09 15:08:12 +00005579 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005580 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005581 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005582}
Mike Stump1eb44332009-09-09 15:08:12 +00005583
Douglas Gregor43959a92009-08-20 07:17:43 +00005584template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005585StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005586TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005587 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005588 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005589 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5590 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005591 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5592 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005593 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005594 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005595
Douglas Gregor43959a92009-08-20 07:17:43 +00005596 if (Transformed != *D)
5597 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005598
Douglas Gregor43959a92009-08-20 07:17:43 +00005599 Decls.push_back(Transformed);
5600 }
Mike Stump1eb44332009-09-09 15:08:12 +00005601
Douglas Gregor43959a92009-08-20 07:17:43 +00005602 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005603 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005604
Rafael Espindola4549d7f2013-07-09 12:05:01 +00005605 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005606}
Mike Stump1eb44332009-09-09 15:08:12 +00005607
Douglas Gregor43959a92009-08-20 07:17:43 +00005608template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005609StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005610TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005611
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005612 SmallVector<Expr*, 8> Constraints;
5613 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005614 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005615
John McCall60d7b3a2010-08-24 06:29:42 +00005616 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005617 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005618
5619 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005620
Anders Carlsson703e3942010-01-24 05:50:09 +00005621 // Go through the outputs.
5622 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005623 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005624
Anders Carlsson703e3942010-01-24 05:50:09 +00005625 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005626 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005627
Anders Carlsson703e3942010-01-24 05:50:09 +00005628 // Transform the output expr.
5629 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005630 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005631 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005632 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005633
Anders Carlsson703e3942010-01-24 05:50:09 +00005634 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005635
John McCall9ae2f072010-08-23 23:25:46 +00005636 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005637 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005638
Anders Carlsson703e3942010-01-24 05:50:09 +00005639 // Go through the inputs.
5640 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005641 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005642
Anders Carlsson703e3942010-01-24 05:50:09 +00005643 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005644 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005645
Anders Carlsson703e3942010-01-24 05:50:09 +00005646 // Transform the input expr.
5647 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005648 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005649 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005650 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005651
Anders Carlsson703e3942010-01-24 05:50:09 +00005652 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005653
John McCall9ae2f072010-08-23 23:25:46 +00005654 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005655 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005656
Anders Carlsson703e3942010-01-24 05:50:09 +00005657 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005658 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005659
5660 // Go through the clobbers.
5661 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005662 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005663
5664 // No need to transform the asm string literal.
5665 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005666 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5667 S->isVolatile(), S->getNumOutputs(),
5668 S->getNumInputs(), Names.data(),
5669 Constraints, Exprs, AsmString.get(),
5670 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005671}
5672
Chad Rosier8cd64b42012-06-11 20:47:18 +00005673template<typename Derived>
5674StmtResult
5675TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005676 ArrayRef<Token> AsmToks =
5677 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005678
John McCallaeeacf72013-05-03 00:10:13 +00005679 bool HadError = false, HadChange = false;
5680
5681 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5682 SmallVector<Expr*, 8> TransformedExprs;
5683 TransformedExprs.reserve(SrcExprs.size());
5684 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5685 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5686 if (!Result.isUsable()) {
5687 HadError = true;
5688 } else {
5689 HadChange |= (Result.get() != SrcExprs[i]);
5690 TransformedExprs.push_back(Result.take());
5691 }
5692 }
5693
5694 if (HadError) return StmtError();
5695 if (!HadChange && !getDerived().AlwaysRebuild())
5696 return Owned(S);
5697
Chad Rosier7bd092b2012-08-15 16:53:30 +00005698 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallaeeacf72013-05-03 00:10:13 +00005699 AsmToks, S->getAsmString(),
5700 S->getNumOutputs(), S->getNumInputs(),
5701 S->getAllConstraints(), S->getClobbers(),
5702 TransformedExprs, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005703}
Douglas Gregor43959a92009-08-20 07:17:43 +00005704
5705template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005706StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005707TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005708 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005709 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005710 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005711 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005712
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005713 // Transform the @catch statements (if present).
5714 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005715 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005716 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005717 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005718 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005719 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005720 if (Catch.get() != S->getCatchStmt(I))
5721 AnyCatchChanged = true;
5722 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005723 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005724
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005725 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005726 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005727 if (S->getFinallyStmt()) {
5728 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5729 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005730 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005731 }
5732
5733 // If nothing changed, just retain this statement.
5734 if (!getDerived().AlwaysRebuild() &&
5735 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005736 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005737 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005738 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005739
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005740 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005741 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005742 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005743}
Mike Stump1eb44332009-09-09 15:08:12 +00005744
Douglas Gregor43959a92009-08-20 07:17:43 +00005745template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005746StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005747TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005748 // Transform the @catch parameter, if there is one.
5749 VarDecl *Var = 0;
5750 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5751 TypeSourceInfo *TSInfo = 0;
5752 if (FromVar->getTypeSourceInfo()) {
5753 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5754 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005755 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005756 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005757
Douglas Gregorbe270a02010-04-26 17:57:08 +00005758 QualType T;
5759 if (TSInfo)
5760 T = TSInfo->getType();
5761 else {
5762 T = getDerived().TransformType(FromVar->getType());
5763 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005764 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005765 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005766
Douglas Gregorbe270a02010-04-26 17:57:08 +00005767 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5768 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005769 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005770 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005771
John McCall60d7b3a2010-08-24 06:29:42 +00005772 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005773 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005774 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005775
5776 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005777 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005778 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005779}
Mike Stump1eb44332009-09-09 15:08:12 +00005780
Douglas Gregor43959a92009-08-20 07:17:43 +00005781template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005782StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005783TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005784 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005785 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005786 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005787 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005788
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005789 // If nothing changed, just retain this statement.
5790 if (!getDerived().AlwaysRebuild() &&
5791 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005792 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005793
5794 // Build a new statement.
5795 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005796 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005797}
Mike Stump1eb44332009-09-09 15:08:12 +00005798
Douglas Gregor43959a92009-08-20 07:17:43 +00005799template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005800StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005801TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005802 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005803 if (S->getThrowExpr()) {
5804 Operand = getDerived().TransformExpr(S->getThrowExpr());
5805 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005806 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005807 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005808
Douglas Gregord1377b22010-04-22 21:44:01 +00005809 if (!getDerived().AlwaysRebuild() &&
5810 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005811 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005812
John McCall9ae2f072010-08-23 23:25:46 +00005813 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005814}
Mike Stump1eb44332009-09-09 15:08:12 +00005815
Douglas Gregor43959a92009-08-20 07:17:43 +00005816template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005817StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005818TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005819 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005820 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005821 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005822 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005823 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005824 Object =
5825 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5826 Object.get());
5827 if (Object.isInvalid())
5828 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005829
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005830 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005831 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005832 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005833 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005834
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005835 // If nothing change, just retain the current statement.
5836 if (!getDerived().AlwaysRebuild() &&
5837 Object.get() == S->getSynchExpr() &&
5838 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005839 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005840
5841 // Build a new statement.
5842 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005843 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005844}
5845
5846template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005847StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005848TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5849 ObjCAutoreleasePoolStmt *S) {
5850 // Transform the body.
5851 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5852 if (Body.isInvalid())
5853 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005854
John McCallf85e1932011-06-15 23:02:42 +00005855 // If nothing changed, just retain this statement.
5856 if (!getDerived().AlwaysRebuild() &&
5857 Body.get() == S->getSubStmt())
5858 return SemaRef.Owned(S);
5859
5860 // Build a new statement.
5861 return getDerived().RebuildObjCAutoreleasePoolStmt(
5862 S->getAtLoc(), Body.get());
5863}
5864
5865template<typename Derived>
5866StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005867TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005868 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005869 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005870 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005871 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005872 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005873
Douglas Gregorc3203e72010-04-22 23:10:45 +00005874 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005875 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005876 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005877 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005878
Douglas Gregorc3203e72010-04-22 23:10:45 +00005879 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005880 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005881 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005882 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005883
Douglas Gregorc3203e72010-04-22 23:10:45 +00005884 // If nothing changed, just retain this statement.
5885 if (!getDerived().AlwaysRebuild() &&
5886 Element.get() == S->getElement() &&
5887 Collection.get() == S->getCollection() &&
5888 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005889 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005890
Douglas Gregorc3203e72010-04-22 23:10:45 +00005891 // Build a new statement.
5892 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005893 Element.get(),
5894 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005895 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005896 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005897}
5898
5899
5900template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005901StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005902TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5903 // Transform the exception declaration, if any.
5904 VarDecl *Var = 0;
5905 if (S->getExceptionDecl()) {
5906 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005907 TypeSourceInfo *T = getDerived().TransformType(
5908 ExceptionDecl->getTypeSourceInfo());
5909 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005910 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005911
Douglas Gregor83cb9422010-09-09 17:09:21 +00005912 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005913 ExceptionDecl->getInnerLocStart(),
5914 ExceptionDecl->getLocation(),
5915 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005916 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005917 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005918 }
Mike Stump1eb44332009-09-09 15:08:12 +00005919
Douglas Gregor43959a92009-08-20 07:17:43 +00005920 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005921 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005922 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005923 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005924
Douglas Gregor43959a92009-08-20 07:17:43 +00005925 if (!getDerived().AlwaysRebuild() &&
5926 !Var &&
5927 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005928 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005929
5930 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5931 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005932 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005933}
Mike Stump1eb44332009-09-09 15:08:12 +00005934
Douglas Gregor43959a92009-08-20 07:17:43 +00005935template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005936StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005937TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5938 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005939 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005940 = getDerived().TransformCompoundStmt(S->getTryBlock());
5941 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005942 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005943
Douglas Gregor43959a92009-08-20 07:17:43 +00005944 // Transform the handlers.
5945 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005946 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005947 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005948 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005949 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5950 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005951 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005952
Douglas Gregor43959a92009-08-20 07:17:43 +00005953 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5954 Handlers.push_back(Handler.takeAs<Stmt>());
5955 }
Mike Stump1eb44332009-09-09 15:08:12 +00005956
Douglas Gregor43959a92009-08-20 07:17:43 +00005957 if (!getDerived().AlwaysRebuild() &&
5958 TryBlock.get() == S->getTryBlock() &&
5959 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005960 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005961
John McCall9ae2f072010-08-23 23:25:46 +00005962 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005963 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005964}
Mike Stump1eb44332009-09-09 15:08:12 +00005965
Richard Smithad762fc2011-04-14 22:09:26 +00005966template<typename Derived>
5967StmtResult
5968TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5969 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5970 if (Range.isInvalid())
5971 return StmtError();
5972
5973 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5974 if (BeginEnd.isInvalid())
5975 return StmtError();
5976
5977 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5978 if (Cond.isInvalid())
5979 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005980 if (Cond.get())
5981 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5982 if (Cond.isInvalid())
5983 return StmtError();
5984 if (Cond.get())
5985 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005986
5987 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5988 if (Inc.isInvalid())
5989 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005990 if (Inc.get())
5991 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005992
5993 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5994 if (LoopVar.isInvalid())
5995 return StmtError();
5996
5997 StmtResult NewStmt = S;
5998 if (getDerived().AlwaysRebuild() ||
5999 Range.get() != S->getRangeStmt() ||
6000 BeginEnd.get() != S->getBeginEndStmt() ||
6001 Cond.get() != S->getCond() ||
6002 Inc.get() != S->getInc() ||
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006003 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smithad762fc2011-04-14 22:09:26 +00006004 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6005 S->getColonLoc(), Range.get(),
6006 BeginEnd.get(), Cond.get(),
6007 Inc.get(), LoopVar.get(),
6008 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006009 if (NewStmt.isInvalid())
6010 return StmtError();
6011 }
Richard Smithad762fc2011-04-14 22:09:26 +00006012
6013 StmtResult Body = getDerived().TransformStmt(S->getBody());
6014 if (Body.isInvalid())
6015 return StmtError();
6016
6017 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6018 // it now so we have a new statement to attach the body to.
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006019 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smithad762fc2011-04-14 22:09:26 +00006020 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6021 S->getColonLoc(), Range.get(),
6022 BeginEnd.get(), Cond.get(),
6023 Inc.get(), LoopVar.get(),
6024 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006025 if (NewStmt.isInvalid())
6026 return StmtError();
6027 }
Richard Smithad762fc2011-04-14 22:09:26 +00006028
6029 if (NewStmt.get() == S)
6030 return SemaRef.Owned(S);
6031
6032 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6033}
6034
John Wiegley28bbe4b2011-04-28 01:08:34 +00006035template<typename Derived>
6036StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00006037TreeTransform<Derived>::TransformMSDependentExistsStmt(
6038 MSDependentExistsStmt *S) {
6039 // Transform the nested-name-specifier, if any.
6040 NestedNameSpecifierLoc QualifierLoc;
6041 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006042 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00006043 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6044 if (!QualifierLoc)
6045 return StmtError();
6046 }
6047
6048 // Transform the declaration name.
6049 DeclarationNameInfo NameInfo = S->getNameInfo();
6050 if (NameInfo.getName()) {
6051 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6052 if (!NameInfo.getName())
6053 return StmtError();
6054 }
6055
6056 // Check whether anything changed.
6057 if (!getDerived().AlwaysRebuild() &&
6058 QualifierLoc == S->getQualifierLoc() &&
6059 NameInfo.getName() == S->getNameInfo().getName())
6060 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006061
Douglas Gregorba0513d2011-10-25 01:33:02 +00006062 // Determine whether this name exists, if we can.
6063 CXXScopeSpec SS;
6064 SS.Adopt(QualifierLoc);
6065 bool Dependent = false;
6066 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6067 case Sema::IER_Exists:
6068 if (S->isIfExists())
6069 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006070
Douglas Gregorba0513d2011-10-25 01:33:02 +00006071 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6072
6073 case Sema::IER_DoesNotExist:
6074 if (S->isIfNotExists())
6075 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006076
Douglas Gregorba0513d2011-10-25 01:33:02 +00006077 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006078
Douglas Gregorba0513d2011-10-25 01:33:02 +00006079 case Sema::IER_Dependent:
6080 Dependent = true;
6081 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006082
Douglas Gregor65019ac2011-10-25 03:44:56 +00006083 case Sema::IER_Error:
6084 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006085 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006086
Douglas Gregorba0513d2011-10-25 01:33:02 +00006087 // We need to continue with the instantiation, so do so now.
6088 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6089 if (SubStmt.isInvalid())
6090 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006091
Douglas Gregorba0513d2011-10-25 01:33:02 +00006092 // If we have resolved the name, just transform to the substatement.
6093 if (!Dependent)
6094 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006095
Douglas Gregorba0513d2011-10-25 01:33:02 +00006096 // The name is still dependent, so build a dependent expression again.
6097 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6098 S->isIfExists(),
6099 QualifierLoc,
6100 NameInfo,
6101 SubStmt.get());
6102}
6103
6104template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006105ExprResult
6106TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6107 NestedNameSpecifierLoc QualifierLoc;
6108 if (E->getQualifierLoc()) {
6109 QualifierLoc
6110 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6111 if (!QualifierLoc)
6112 return ExprError();
6113 }
6114
6115 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6116 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6117 if (!PD)
6118 return ExprError();
6119
6120 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6121 if (Base.isInvalid())
6122 return ExprError();
6123
6124 return new (SemaRef.getASTContext())
6125 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6126 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6127 QualifierLoc, E->getMemberLoc());
6128}
6129
6130template<typename Derived>
Douglas Gregorba0513d2011-10-25 01:33:02 +00006131StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006132TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6133 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6134 if(TryBlock.isInvalid()) return StmtError();
6135
6136 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6137 if(!getDerived().AlwaysRebuild() &&
6138 TryBlock.get() == S->getTryBlock() &&
6139 Handler.get() == S->getHandler())
6140 return SemaRef.Owned(S);
6141
6142 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6143 S->getTryLoc(),
6144 TryBlock.take(),
6145 Handler.take());
6146}
6147
6148template<typename Derived>
6149StmtResult
6150TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6151 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6152 if(Block.isInvalid()) return StmtError();
6153
6154 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6155 Block.take());
6156}
6157
6158template<typename Derived>
6159StmtResult
6160TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6161 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6162 if(FilterExpr.isInvalid()) return StmtError();
6163
6164 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6165 if(Block.isInvalid()) return StmtError();
6166
6167 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6168 FilterExpr.take(),
6169 Block.take());
6170}
6171
6172template<typename Derived>
6173StmtResult
6174TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6175 if(isa<SEHFinallyStmt>(Handler))
6176 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6177 else
6178 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6179}
6180
Douglas Gregor43959a92009-08-20 07:17:43 +00006181//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006182// Expression transformation
6183//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006184template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006185ExprResult
John McCall454feb92009-12-08 09:21:05 +00006186TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006187 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006188}
Mike Stump1eb44332009-09-09 15:08:12 +00006189
6190template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006191ExprResult
John McCall454feb92009-12-08 09:21:05 +00006192TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006193 NestedNameSpecifierLoc QualifierLoc;
6194 if (E->getQualifierLoc()) {
6195 QualifierLoc
6196 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6197 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006198 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006199 }
John McCalldbd872f2009-12-08 09:08:17 +00006200
6201 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006202 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6203 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006204 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006205 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006206
John McCallec8045d2010-08-17 21:27:17 +00006207 DeclarationNameInfo NameInfo = E->getNameInfo();
6208 if (NameInfo.getName()) {
6209 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6210 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006211 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006212 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006213
6214 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006215 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006216 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006217 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006218 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006219
6220 // Mark it referenced in the new context regardless.
6221 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006222 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006223
John McCall3fa5cae2010-10-26 07:05:15 +00006224 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006225 }
John McCalldbd872f2009-12-08 09:08:17 +00006226
6227 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006228 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006229 TemplateArgs = &TransArgs;
6230 TransArgs.setLAngleLoc(E->getLAngleLoc());
6231 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006232 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6233 E->getNumTemplateArgs(),
6234 TransArgs))
6235 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006236 }
6237
Chad Rosier4a9d7952012-08-08 18:46:20 +00006238 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006239 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006240}
Mike Stump1eb44332009-09-09 15:08:12 +00006241
Douglas Gregorb98b1992009-08-11 05:31:07 +00006242template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006243ExprResult
John McCall454feb92009-12-08 09:21:05 +00006244TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006245 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006246}
Mike Stump1eb44332009-09-09 15:08:12 +00006247
Douglas Gregorb98b1992009-08-11 05:31:07 +00006248template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006249ExprResult
John McCall454feb92009-12-08 09:21:05 +00006250TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006251 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006252}
Mike Stump1eb44332009-09-09 15:08:12 +00006253
Douglas Gregorb98b1992009-08-11 05:31:07 +00006254template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006255ExprResult
John McCall454feb92009-12-08 09:21:05 +00006256TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006257 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006258}
Mike Stump1eb44332009-09-09 15:08:12 +00006259
Douglas Gregorb98b1992009-08-11 05:31:07 +00006260template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006261ExprResult
John McCall454feb92009-12-08 09:21:05 +00006262TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006263 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006264}
Mike Stump1eb44332009-09-09 15:08:12 +00006265
Douglas Gregorb98b1992009-08-11 05:31:07 +00006266template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006267ExprResult
John McCall454feb92009-12-08 09:21:05 +00006268TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006269 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006270}
6271
6272template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006273ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006274TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006275 if (FunctionDecl *FD = E->getDirectCallee())
6276 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006277 return SemaRef.MaybeBindToTemporary(E);
6278}
6279
6280template<typename Derived>
6281ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006282TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6283 ExprResult ControllingExpr =
6284 getDerived().TransformExpr(E->getControllingExpr());
6285 if (ControllingExpr.isInvalid())
6286 return ExprError();
6287
Chris Lattner686775d2011-07-20 06:58:45 +00006288 SmallVector<Expr *, 4> AssocExprs;
6289 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006290 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6291 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6292 if (TS) {
6293 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6294 if (!AssocType)
6295 return ExprError();
6296 AssocTypes.push_back(AssocType);
6297 } else {
6298 AssocTypes.push_back(0);
6299 }
6300
6301 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6302 if (AssocExpr.isInvalid())
6303 return ExprError();
6304 AssocExprs.push_back(AssocExpr.release());
6305 }
6306
6307 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6308 E->getDefaultLoc(),
6309 E->getRParenLoc(),
6310 ControllingExpr.release(),
Dmitri Gribenko80613222013-05-10 13:06:58 +00006311 AssocTypes,
6312 AssocExprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00006313}
6314
6315template<typename Derived>
6316ExprResult
John McCall454feb92009-12-08 09:21:05 +00006317TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006318 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006319 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006320 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006321
Douglas Gregorb98b1992009-08-11 05:31:07 +00006322 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006323 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006324
John McCall9ae2f072010-08-23 23:25:46 +00006325 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006326 E->getRParen());
6327}
6328
Richard Smithefeeccf2012-10-21 03:28:35 +00006329/// \brief The operand of a unary address-of operator has special rules: it's
6330/// allowed to refer to a non-static member of a class even if there's no 'this'
6331/// object available.
6332template<typename Derived>
6333ExprResult
6334TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6335 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6336 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6337 else
6338 return getDerived().TransformExpr(E);
6339}
6340
Mike Stump1eb44332009-09-09 15:08:12 +00006341template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006342ExprResult
John McCall454feb92009-12-08 09:21:05 +00006343TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smith82b00012013-05-21 23:29:46 +00006344 ExprResult SubExpr;
6345 if (E->getOpcode() == UO_AddrOf)
6346 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6347 else
6348 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006349 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006350 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006351
Douglas Gregorb98b1992009-08-11 05:31:07 +00006352 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006353 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006354
Douglas Gregorb98b1992009-08-11 05:31:07 +00006355 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6356 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006357 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006358}
Mike Stump1eb44332009-09-09 15:08:12 +00006359
Douglas Gregorb98b1992009-08-11 05:31:07 +00006360template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006361ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006362TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6363 // Transform the type.
6364 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6365 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006366 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006367
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006368 // Transform all of the components into components similar to what the
6369 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006370 // FIXME: It would be slightly more efficient in the non-dependent case to
6371 // just map FieldDecls, rather than requiring the rebuilder to look for
6372 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006373 // template code that we don't care.
6374 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006375 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006376 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006377 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006378 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6379 const Node &ON = E->getComponent(I);
6380 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006381 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006382 Comp.LocStart = ON.getSourceRange().getBegin();
6383 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006384 switch (ON.getKind()) {
6385 case Node::Array: {
6386 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006387 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006388 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006389 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006390
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006391 ExprChanged = ExprChanged || Index.get() != FromIndex;
6392 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006393 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006394 break;
6395 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006396
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006397 case Node::Field:
6398 case Node::Identifier:
6399 Comp.isBrackets = false;
6400 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006401 if (!Comp.U.IdentInfo)
6402 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006403
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006404 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006405
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006406 case Node::Base:
6407 // Will be recomputed during the rebuild.
6408 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006409 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006410
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006411 Components.push_back(Comp);
6412 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006413
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006414 // If nothing changed, retain the existing expression.
6415 if (!getDerived().AlwaysRebuild() &&
6416 Type == E->getTypeSourceInfo() &&
6417 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006418 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006419
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006420 // Build a new offsetof expression.
6421 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6422 Components.data(), Components.size(),
6423 E->getRParenLoc());
6424}
6425
6426template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006427ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006428TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6429 assert(getDerived().AlreadyTransformed(E->getType()) &&
6430 "opaque value expression requires transformation");
6431 return SemaRef.Owned(E);
6432}
6433
6434template<typename Derived>
6435ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006436TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006437 // Rebuild the syntactic form. The original syntactic form has
6438 // opaque-value expressions in it, so strip those away and rebuild
6439 // the result. This is a really awful way of doing this, but the
6440 // better solution (rebuilding the semantic expressions and
6441 // rebinding OVEs as necessary) doesn't work; we'd need
6442 // TreeTransform to not strip away implicit conversions.
6443 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6444 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006445 if (result.isInvalid()) return ExprError();
6446
6447 // If that gives us a pseudo-object result back, the pseudo-object
6448 // expression must have been an lvalue-to-rvalue conversion which we
6449 // should reapply.
6450 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6451 result = SemaRef.checkPseudoObjectRValue(result.take());
6452
6453 return result;
6454}
6455
6456template<typename Derived>
6457ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006458TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6459 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006460 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006461 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006462
John McCalla93c9342009-12-07 02:54:59 +00006463 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006464 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006465 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006466
John McCall5ab75172009-11-04 07:28:41 +00006467 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006468 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006469
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006470 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6471 E->getKind(),
6472 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006473 }
Mike Stump1eb44332009-09-09 15:08:12 +00006474
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006475 // C++0x [expr.sizeof]p1:
6476 // The operand is either an expression, which is an unevaluated operand
6477 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006478 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6479 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006480
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006481 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6482 if (SubExpr.isInvalid())
6483 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006484
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006485 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6486 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006487
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006488 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6489 E->getOperatorLoc(),
6490 E->getKind(),
6491 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006492}
Mike Stump1eb44332009-09-09 15:08:12 +00006493
Douglas Gregorb98b1992009-08-11 05:31:07 +00006494template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006495ExprResult
John McCall454feb92009-12-08 09:21:05 +00006496TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006497 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006498 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006499 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006500
John McCall60d7b3a2010-08-24 06:29:42 +00006501 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006502 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006503 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006504
6505
Douglas Gregorb98b1992009-08-11 05:31:07 +00006506 if (!getDerived().AlwaysRebuild() &&
6507 LHS.get() == E->getLHS() &&
6508 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006509 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006510
John McCall9ae2f072010-08-23 23:25:46 +00006511 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006512 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006513 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006514 E->getRBracketLoc());
6515}
Mike Stump1eb44332009-09-09 15:08:12 +00006516
6517template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006518ExprResult
John McCall454feb92009-12-08 09:21:05 +00006519TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006520 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006521 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006522 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006523 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006524
6525 // Transform arguments.
6526 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006527 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006528 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006529 &ArgChanged))
6530 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006531
Douglas Gregorb98b1992009-08-11 05:31:07 +00006532 if (!getDerived().AlwaysRebuild() &&
6533 Callee.get() == E->getCallee() &&
6534 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006535 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006536
Douglas Gregorb98b1992009-08-11 05:31:07 +00006537 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006538 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006539 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006540 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006541 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006542 E->getRParenLoc());
6543}
Mike Stump1eb44332009-09-09 15:08:12 +00006544
6545template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006546ExprResult
John McCall454feb92009-12-08 09:21:05 +00006547TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006548 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006549 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006550 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006551
Douglas Gregor40d96a62011-02-28 21:54:11 +00006552 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006553 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006554 QualifierLoc
6555 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006556
Douglas Gregor40d96a62011-02-28 21:54:11 +00006557 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006558 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006559 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006560 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006561
Eli Friedmanf595cc42009-12-04 06:40:45 +00006562 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006563 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6564 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006565 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006566 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006567
John McCall6bb80172010-03-30 21:47:33 +00006568 NamedDecl *FoundDecl = E->getFoundDecl();
6569 if (FoundDecl == E->getMemberDecl()) {
6570 FoundDecl = Member;
6571 } else {
6572 FoundDecl = cast_or_null<NamedDecl>(
6573 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6574 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006575 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006576 }
6577
Douglas Gregorb98b1992009-08-11 05:31:07 +00006578 if (!getDerived().AlwaysRebuild() &&
6579 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006580 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006581 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006582 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006583 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006584
Anders Carlsson1f240322009-12-22 05:24:09 +00006585 // Mark it referenced in the new context regardless.
6586 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006587 SemaRef.MarkMemberReferenced(E);
6588
John McCall3fa5cae2010-10-26 07:05:15 +00006589 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006590 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006591
John McCalld5532b62009-11-23 01:53:49 +00006592 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006593 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006594 TransArgs.setLAngleLoc(E->getLAngleLoc());
6595 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006596 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6597 E->getNumTemplateArgs(),
6598 TransArgs))
6599 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006600 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006601
Douglas Gregorb98b1992009-08-11 05:31:07 +00006602 // FIXME: Bogus source location for the operator
6603 SourceLocation FakeOperatorLoc
6604 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6605
John McCallc2233c52010-01-15 08:34:02 +00006606 // FIXME: to do this check properly, we will need to preserve the
6607 // first-qualifier-in-scope here, just in case we had a dependent
6608 // base (and therefore couldn't do the check) and a
6609 // nested-name-qualifier (and therefore could do the lookup).
6610 NamedDecl *FirstQualifierInScope = 0;
6611
John McCall9ae2f072010-08-23 23:25:46 +00006612 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006613 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006614 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006615 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006616 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006617 Member,
John McCall6bb80172010-03-30 21:47:33 +00006618 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006619 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006620 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006621 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006622}
Mike Stump1eb44332009-09-09 15:08:12 +00006623
Douglas Gregorb98b1992009-08-11 05:31:07 +00006624template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006625ExprResult
John McCall454feb92009-12-08 09:21:05 +00006626TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006627 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006628 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006629 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006630
John McCall60d7b3a2010-08-24 06:29:42 +00006631 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006632 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006633 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006634
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635 if (!getDerived().AlwaysRebuild() &&
6636 LHS.get() == E->getLHS() &&
6637 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006638 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006639
Lang Hamesbe9af122012-10-02 04:45:10 +00006640 Sema::FPContractStateRAII FPContractState(getSema());
6641 getSema().FPFeatures.fp_contract = E->isFPContractable();
6642
Douglas Gregorb98b1992009-08-11 05:31:07 +00006643 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006644 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006645}
6646
Mike Stump1eb44332009-09-09 15:08:12 +00006647template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006648ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006649TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006650 CompoundAssignOperator *E) {
6651 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006652}
Mike Stump1eb44332009-09-09 15:08:12 +00006653
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006655ExprResult TreeTransform<Derived>::
6656TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6657 // Just rebuild the common and RHS expressions and see whether we
6658 // get any changes.
6659
6660 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6661 if (commonExpr.isInvalid())
6662 return ExprError();
6663
6664 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6665 if (rhs.isInvalid())
6666 return ExprError();
6667
6668 if (!getDerived().AlwaysRebuild() &&
6669 commonExpr.get() == e->getCommon() &&
6670 rhs.get() == e->getFalseExpr())
6671 return SemaRef.Owned(e);
6672
6673 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6674 e->getQuestionLoc(),
6675 0,
6676 e->getColonLoc(),
6677 rhs.get());
6678}
6679
6680template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006681ExprResult
John McCall454feb92009-12-08 09:21:05 +00006682TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006683 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006684 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006685 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006686
John McCall60d7b3a2010-08-24 06:29:42 +00006687 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006688 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006689 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006690
John McCall60d7b3a2010-08-24 06:29:42 +00006691 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006693 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006694
Douglas Gregorb98b1992009-08-11 05:31:07 +00006695 if (!getDerived().AlwaysRebuild() &&
6696 Cond.get() == E->getCond() &&
6697 LHS.get() == E->getLHS() &&
6698 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006699 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006700
John McCall9ae2f072010-08-23 23:25:46 +00006701 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006702 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006703 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006704 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006705 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006706}
Mike Stump1eb44332009-09-09 15:08:12 +00006707
6708template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006709ExprResult
John McCall454feb92009-12-08 09:21:05 +00006710TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006711 // Implicit casts are eliminated during transformation, since they
6712 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006713 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006714}
Mike Stump1eb44332009-09-09 15:08:12 +00006715
Douglas Gregorb98b1992009-08-11 05:31:07 +00006716template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006717ExprResult
John McCall454feb92009-12-08 09:21:05 +00006718TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006719 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6720 if (!Type)
6721 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006722
John McCall60d7b3a2010-08-24 06:29:42 +00006723 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006724 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006725 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006726 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006727
Douglas Gregorb98b1992009-08-11 05:31:07 +00006728 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006729 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006730 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006731 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006732
John McCall9d125032010-01-15 18:39:57 +00006733 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006734 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006735 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006736 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006737}
Mike Stump1eb44332009-09-09 15:08:12 +00006738
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006740ExprResult
John McCall454feb92009-12-08 09:21:05 +00006741TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006742 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6743 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6744 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006745 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006746
John McCall60d7b3a2010-08-24 06:29:42 +00006747 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006748 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006749 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006750
Douglas Gregorb98b1992009-08-11 05:31:07 +00006751 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006752 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006753 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006754 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006755
John McCall1d7d8d62010-01-19 22:33:45 +00006756 // Note: the expression type doesn't necessarily match the
6757 // type-as-written, but that's okay, because it should always be
6758 // derivable from the initializer.
6759
John McCall42f56b52010-01-18 19:35:47 +00006760 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006761 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006762 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006763}
Mike Stump1eb44332009-09-09 15:08:12 +00006764
Douglas Gregorb98b1992009-08-11 05:31:07 +00006765template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006766ExprResult
John McCall454feb92009-12-08 09:21:05 +00006767TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006768 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006769 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006770 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006771
Douglas Gregorb98b1992009-08-11 05:31:07 +00006772 if (!getDerived().AlwaysRebuild() &&
6773 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006774 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006775
Douglas Gregorb98b1992009-08-11 05:31:07 +00006776 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006777 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006778 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006779 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006780 E->getAccessorLoc(),
6781 E->getAccessor());
6782}
Mike Stump1eb44332009-09-09 15:08:12 +00006783
Douglas Gregorb98b1992009-08-11 05:31:07 +00006784template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006785ExprResult
John McCall454feb92009-12-08 09:21:05 +00006786TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006787 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006788
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006789 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006790 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006791 Inits, &InitChanged))
6792 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006793
Douglas Gregorb98b1992009-08-11 05:31:07 +00006794 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006795 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006796
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006797 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006798 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006799}
Mike Stump1eb44332009-09-09 15:08:12 +00006800
Douglas Gregorb98b1992009-08-11 05:31:07 +00006801template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006802ExprResult
John McCall454feb92009-12-08 09:21:05 +00006803TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006804 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006805
Douglas Gregor43959a92009-08-20 07:17:43 +00006806 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006807 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006808 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006809 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006810
Douglas Gregor43959a92009-08-20 07:17:43 +00006811 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006812 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006813 bool ExprChanged = false;
6814 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6815 DEnd = E->designators_end();
6816 D != DEnd; ++D) {
6817 if (D->isFieldDesignator()) {
6818 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6819 D->getDotLoc(),
6820 D->getFieldLoc()));
6821 continue;
6822 }
Mike Stump1eb44332009-09-09 15:08:12 +00006823
Douglas Gregorb98b1992009-08-11 05:31:07 +00006824 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006825 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006826 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006827 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006828
6829 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006830 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006831
Douglas Gregorb98b1992009-08-11 05:31:07 +00006832 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6833 ArrayExprs.push_back(Index.release());
6834 continue;
6835 }
Mike Stump1eb44332009-09-09 15:08:12 +00006836
Douglas Gregorb98b1992009-08-11 05:31:07 +00006837 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006838 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006839 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6840 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006841 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006842
John McCall60d7b3a2010-08-24 06:29:42 +00006843 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006844 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006845 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006846
6847 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006848 End.get(),
6849 D->getLBracketLoc(),
6850 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006851
Douglas Gregorb98b1992009-08-11 05:31:07 +00006852 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6853 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006854
Douglas Gregorb98b1992009-08-11 05:31:07 +00006855 ArrayExprs.push_back(Start.release());
6856 ArrayExprs.push_back(End.release());
6857 }
Mike Stump1eb44332009-09-09 15:08:12 +00006858
Douglas Gregorb98b1992009-08-11 05:31:07 +00006859 if (!getDerived().AlwaysRebuild() &&
6860 Init.get() == E->getInit() &&
6861 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006862 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006863
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006864 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006865 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006866 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006867}
Mike Stump1eb44332009-09-09 15:08:12 +00006868
Douglas Gregorb98b1992009-08-11 05:31:07 +00006869template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006870ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006871TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006872 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006873 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006874
Douglas Gregor5557b252009-10-28 00:29:27 +00006875 // FIXME: Will we ever have proper type location here? Will we actually
6876 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006877 QualType T = getDerived().TransformType(E->getType());
6878 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006879 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006880
Douglas Gregorb98b1992009-08-11 05:31:07 +00006881 if (!getDerived().AlwaysRebuild() &&
6882 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006883 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006884
Douglas Gregorb98b1992009-08-11 05:31:07 +00006885 return getDerived().RebuildImplicitValueInitExpr(T);
6886}
Mike Stump1eb44332009-09-09 15:08:12 +00006887
Douglas Gregorb98b1992009-08-11 05:31:07 +00006888template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006889ExprResult
John McCall454feb92009-12-08 09:21:05 +00006890TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006891 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6892 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006893 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006894
John McCall60d7b3a2010-08-24 06:29:42 +00006895 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006896 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006897 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006898
Douglas Gregorb98b1992009-08-11 05:31:07 +00006899 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006900 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006901 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006902 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006903
John McCall9ae2f072010-08-23 23:25:46 +00006904 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006905 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006906}
6907
6908template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006909ExprResult
John McCall454feb92009-12-08 09:21:05 +00006910TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006911 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006912 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006913 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6914 &ArgumentChanged))
6915 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006916
Douglas Gregorb98b1992009-08-11 05:31:07 +00006917 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006918 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006919 E->getRParenLoc());
6920}
Mike Stump1eb44332009-09-09 15:08:12 +00006921
Douglas Gregorb98b1992009-08-11 05:31:07 +00006922/// \brief Transform an address-of-label expression.
6923///
6924/// By default, the transformation of an address-of-label expression always
6925/// rebuilds the expression, so that the label identifier can be resolved to
6926/// the corresponding label statement by semantic analysis.
6927template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006928ExprResult
John McCall454feb92009-12-08 09:21:05 +00006929TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006930 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6931 E->getLabel());
6932 if (!LD)
6933 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006934
Douglas Gregorb98b1992009-08-11 05:31:07 +00006935 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006936 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006937}
Mike Stump1eb44332009-09-09 15:08:12 +00006938
6939template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006940ExprResult
John McCall454feb92009-12-08 09:21:05 +00006941TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006942 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006943 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006944 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006945 if (SubStmt.isInvalid()) {
6946 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006947 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006948 }
Mike Stump1eb44332009-09-09 15:08:12 +00006949
Douglas Gregorb98b1992009-08-11 05:31:07 +00006950 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006951 SubStmt.get() == E->getSubStmt()) {
6952 // Calling this an 'error' is unintuitive, but it does the right thing.
6953 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006954 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006955 }
Mike Stump1eb44332009-09-09 15:08:12 +00006956
6957 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006958 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006959 E->getRParenLoc());
6960}
Mike Stump1eb44332009-09-09 15:08:12 +00006961
Douglas Gregorb98b1992009-08-11 05:31:07 +00006962template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006963ExprResult
John McCall454feb92009-12-08 09:21:05 +00006964TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006965 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006966 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006967 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006968
John McCall60d7b3a2010-08-24 06:29:42 +00006969 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006970 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006971 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006972
John McCall60d7b3a2010-08-24 06:29:42 +00006973 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006974 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006975 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006976
Douglas Gregorb98b1992009-08-11 05:31:07 +00006977 if (!getDerived().AlwaysRebuild() &&
6978 Cond.get() == E->getCond() &&
6979 LHS.get() == E->getLHS() &&
6980 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006981 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006982
Douglas Gregorb98b1992009-08-11 05:31:07 +00006983 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006984 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006985 E->getRParenLoc());
6986}
Mike Stump1eb44332009-09-09 15:08:12 +00006987
Douglas Gregorb98b1992009-08-11 05:31:07 +00006988template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006989ExprResult
John McCall454feb92009-12-08 09:21:05 +00006990TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006991 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006992}
6993
6994template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006995ExprResult
John McCall454feb92009-12-08 09:21:05 +00006996TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006997 switch (E->getOperator()) {
6998 case OO_New:
6999 case OO_Delete:
7000 case OO_Array_New:
7001 case OO_Array_Delete:
7002 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00007003
Douglas Gregor668d6d92009-12-13 20:44:55 +00007004 case OO_Call: {
7005 // This is a call to an object's operator().
7006 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7007
7008 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00007009 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00007010 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007011 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007012
7013 // FIXME: Poor location information
7014 SourceLocation FakeLParenLoc
7015 = SemaRef.PP.getLocForEndOfToken(
7016 static_cast<Expr *>(Object.get())->getLocEnd());
7017
7018 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007019 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007020 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007021 Args))
7022 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007023
John McCall9ae2f072010-08-23 23:25:46 +00007024 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007025 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00007026 E->getLocEnd());
7027 }
7028
7029#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7030 case OO_##Name:
7031#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7032#include "clang/Basic/OperatorKinds.def"
7033 case OO_Subscript:
7034 // Handled below.
7035 break;
7036
7037 case OO_Conditional:
7038 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007039
7040 case OO_None:
7041 case NUM_OVERLOADED_OPERATORS:
7042 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007043 }
7044
John McCall60d7b3a2010-08-24 06:29:42 +00007045 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007046 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007047 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007048
Richard Smithefeeccf2012-10-21 03:28:35 +00007049 ExprResult First;
7050 if (E->getOperator() == OO_Amp)
7051 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7052 else
7053 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007054 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007055 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007056
John McCall60d7b3a2010-08-24 06:29:42 +00007057 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007058 if (E->getNumArgs() == 2) {
7059 Second = getDerived().TransformExpr(E->getArg(1));
7060 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007061 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007062 }
Mike Stump1eb44332009-09-09 15:08:12 +00007063
Douglas Gregorb98b1992009-08-11 05:31:07 +00007064 if (!getDerived().AlwaysRebuild() &&
7065 Callee.get() == E->getCallee() &&
7066 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007067 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007068 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007069
Lang Hamesbe9af122012-10-02 04:45:10 +00007070 Sema::FPContractStateRAII FPContractState(getSema());
7071 getSema().FPFeatures.fp_contract = E->isFPContractable();
7072
Douglas Gregorb98b1992009-08-11 05:31:07 +00007073 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7074 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007075 Callee.get(),
7076 First.get(),
7077 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007078}
Mike Stump1eb44332009-09-09 15:08:12 +00007079
Douglas Gregorb98b1992009-08-11 05:31:07 +00007080template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007081ExprResult
John McCall454feb92009-12-08 09:21:05 +00007082TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7083 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007084}
Mike Stump1eb44332009-09-09 15:08:12 +00007085
Douglas Gregorb98b1992009-08-11 05:31:07 +00007086template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007087ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007088TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7089 // Transform the callee.
7090 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7091 if (Callee.isInvalid())
7092 return ExprError();
7093
7094 // Transform exec config.
7095 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7096 if (EC.isInvalid())
7097 return ExprError();
7098
7099 // Transform arguments.
7100 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007101 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007102 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007103 &ArgChanged))
7104 return ExprError();
7105
7106 if (!getDerived().AlwaysRebuild() &&
7107 Callee.get() == E->getCallee() &&
7108 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007109 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007110
7111 // FIXME: Wrong source location information for the '('.
7112 SourceLocation FakeLParenLoc
7113 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7114 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007115 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007116 E->getRParenLoc(), EC.get());
7117}
7118
7119template<typename Derived>
7120ExprResult
John McCall454feb92009-12-08 09:21:05 +00007121TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007122 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7123 if (!Type)
7124 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007125
John McCall60d7b3a2010-08-24 06:29:42 +00007126 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007127 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007128 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007129 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007130
Douglas Gregorb98b1992009-08-11 05:31:07 +00007131 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007132 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007133 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007134 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007135 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007136 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007137 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007138 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007139 E->getAngleBrackets().getEnd(),
7140 // FIXME. this should be '(' location
7141 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007142 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007143 E->getRParenLoc());
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
John McCall454feb92009-12-08 09:21:05 +00007148TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7149 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007150}
Mike Stump1eb44332009-09-09 15:08:12 +00007151
7152template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007153ExprResult
John McCall454feb92009-12-08 09:21:05 +00007154TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7155 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007156}
7157
Douglas Gregorb98b1992009-08-11 05:31:07 +00007158template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007159ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007160TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007161 CXXReinterpretCastExpr *E) {
7162 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007163}
Mike Stump1eb44332009-09-09 15:08:12 +00007164
Douglas Gregorb98b1992009-08-11 05:31:07 +00007165template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007166ExprResult
John McCall454feb92009-12-08 09:21:05 +00007167TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7168 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007169}
Mike Stump1eb44332009-09-09 15:08:12 +00007170
Douglas Gregorb98b1992009-08-11 05:31:07 +00007171template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007172ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007173TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007174 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007175 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7176 if (!Type)
7177 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007178
John McCall60d7b3a2010-08-24 06:29:42 +00007179 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007180 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007181 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007182 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007183
Douglas Gregorb98b1992009-08-11 05:31:07 +00007184 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007185 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007186 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007187 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007188
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007189 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007190 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007191 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007192 E->getRParenLoc());
7193}
Mike Stump1eb44332009-09-09 15:08:12 +00007194
Douglas Gregorb98b1992009-08-11 05:31:07 +00007195template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007196ExprResult
John McCall454feb92009-12-08 09:21:05 +00007197TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007198 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007199 TypeSourceInfo *TInfo
7200 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7201 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007202 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007203
Douglas Gregorb98b1992009-08-11 05:31:07 +00007204 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007205 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007206 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007207
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007208 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7209 E->getLocStart(),
7210 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007211 E->getLocEnd());
7212 }
Mike Stump1eb44332009-09-09 15:08:12 +00007213
Eli Friedmanef331b72012-01-20 01:26:23 +00007214 // We don't know whether the subexpression is potentially evaluated until
7215 // after we perform semantic analysis. We speculatively assume it is
7216 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007217 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007218 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7219 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007220
John McCall60d7b3a2010-08-24 06:29:42 +00007221 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007222 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007223 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007224
Douglas Gregorb98b1992009-08-11 05:31:07 +00007225 if (!getDerived().AlwaysRebuild() &&
7226 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007227 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007228
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007229 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7230 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007231 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007232 E->getLocEnd());
7233}
7234
7235template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007236ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007237TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7238 if (E->isTypeOperand()) {
7239 TypeSourceInfo *TInfo
7240 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7241 if (!TInfo)
7242 return ExprError();
7243
7244 if (!getDerived().AlwaysRebuild() &&
7245 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007246 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007247
Douglas Gregor3c52a212011-03-06 17:40:41 +00007248 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007249 E->getLocStart(),
7250 TInfo,
7251 E->getLocEnd());
7252 }
7253
Francois Pichet01b7c302010-09-08 12:20:18 +00007254 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7255
7256 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7257 if (SubExpr.isInvalid())
7258 return ExprError();
7259
7260 if (!getDerived().AlwaysRebuild() &&
7261 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007262 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007263
7264 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7265 E->getLocStart(),
7266 SubExpr.get(),
7267 E->getLocEnd());
7268}
7269
7270template<typename Derived>
7271ExprResult
John McCall454feb92009-12-08 09:21:05 +00007272TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007273 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007274}
Mike Stump1eb44332009-09-09 15:08:12 +00007275
Douglas Gregorb98b1992009-08-11 05:31:07 +00007276template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007277ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007278TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007279 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007280 return SemaRef.Owned(E);
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>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithcafeb942013-06-07 02:33:37 +00007286 QualType T = getSema().getCurrentThisType();
Mike Stump1eb44332009-09-09 15:08:12 +00007287
Douglas Gregorec79d872012-02-24 17:41:38 +00007288 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7289 // Make sure that we capture 'this'.
7290 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007291 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007292 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007293
Douglas Gregor828a1972010-01-07 23:12:05 +00007294 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007295}
Mike Stump1eb44332009-09-09 15:08:12 +00007296
Douglas Gregorb98b1992009-08-11 05:31:07 +00007297template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007298ExprResult
John McCall454feb92009-12-08 09:21:05 +00007299TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007300 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007301 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007302 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007303
Douglas Gregorb98b1992009-08-11 05:31:07 +00007304 if (!getDerived().AlwaysRebuild() &&
7305 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007306 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007307
Douglas Gregorbca01b42011-07-06 22:04:06 +00007308 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7309 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007310}
Mike Stump1eb44332009-09-09 15:08:12 +00007311
Douglas Gregorb98b1992009-08-11 05:31:07 +00007312template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007313ExprResult
John McCall454feb92009-12-08 09:21:05 +00007314TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007315 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007316 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7317 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007318 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007319 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007320
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007321 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007322 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007323 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007324
Douglas Gregor036aed12009-12-23 23:03:06 +00007325 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007326}
Mike Stump1eb44332009-09-09 15:08:12 +00007327
Douglas Gregorb98b1992009-08-11 05:31:07 +00007328template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007329ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007330TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7331 FieldDecl *Field
7332 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7333 E->getField()));
7334 if (!Field)
7335 return ExprError();
7336
7337 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7338 return SemaRef.Owned(E);
7339
7340 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7341}
7342
7343template<typename Derived>
7344ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007345TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7346 CXXScalarValueInitExpr *E) {
7347 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7348 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007349 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007350
Douglas Gregorb98b1992009-08-11 05:31:07 +00007351 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007352 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007353 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007354
Chad Rosier4a9d7952012-08-08 18:46:20 +00007355 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007356 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007357 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007358}
Mike Stump1eb44332009-09-09 15:08:12 +00007359
Douglas Gregorb98b1992009-08-11 05:31:07 +00007360template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007361ExprResult
John McCall454feb92009-12-08 09:21:05 +00007362TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007363 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007364 TypeSourceInfo *AllocTypeInfo
7365 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7366 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007367 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007368
Douglas Gregorb98b1992009-08-11 05:31:07 +00007369 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007370 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007371 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007372 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007373
Douglas Gregorb98b1992009-08-11 05:31:07 +00007374 // Transform the placement arguments (if any).
7375 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007376 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007377 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007378 E->getNumPlacementArgs(), true,
7379 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007380 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007381
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007382 // Transform the initializer (if any).
7383 Expr *OldInit = E->getInitializer();
7384 ExprResult NewInit;
7385 if (OldInit)
7386 NewInit = getDerived().TransformExpr(OldInit);
7387 if (NewInit.isInvalid())
7388 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007389
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007390 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007391 FunctionDecl *OperatorNew = 0;
7392 if (E->getOperatorNew()) {
7393 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007394 getDerived().TransformDecl(E->getLocStart(),
7395 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007396 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007397 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007398 }
7399
7400 FunctionDecl *OperatorDelete = 0;
7401 if (E->getOperatorDelete()) {
7402 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007403 getDerived().TransformDecl(E->getLocStart(),
7404 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007405 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007406 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007407 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007408
Douglas Gregorb98b1992009-08-11 05:31:07 +00007409 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007410 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007411 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007412 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007413 OperatorNew == E->getOperatorNew() &&
7414 OperatorDelete == E->getOperatorDelete() &&
7415 !ArgumentChanged) {
7416 // Mark any declarations we need as referenced.
7417 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007418 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007419 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007420 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007421 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007422
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007423 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007424 QualType ElementType
7425 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7426 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7427 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7428 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007429 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007430 }
7431 }
7432 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007433
John McCall3fa5cae2010-10-26 07:05:15 +00007434 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007435 }
Mike Stump1eb44332009-09-09 15:08:12 +00007436
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007437 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007438 if (!ArraySize.get()) {
7439 // If no array size was specified, but the new expression was
7440 // instantiated with an array type (e.g., "new T" where T is
7441 // instantiated with "int[4]"), extract the outer bound from the
7442 // array type as our array size. We do this with constant and
7443 // dependently-sized array types.
7444 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7445 if (!ArrayT) {
7446 // Do nothing
7447 } else if (const ConstantArrayType *ConsArrayT
7448 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007449 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007450 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007451 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007452 SemaRef.Context.getSizeType(),
7453 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007454 AllocType = ConsArrayT->getElementType();
7455 } else if (const DependentSizedArrayType *DepArrayT
7456 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7457 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007458 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007459 AllocType = DepArrayT->getElementType();
7460 }
7461 }
7462 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007463
Douglas Gregorb98b1992009-08-11 05:31:07 +00007464 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7465 E->isGlobalNew(),
7466 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007467 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007468 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007469 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007470 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007471 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007472 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007473 E->getDirectInitRange(),
7474 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007475}
Mike Stump1eb44332009-09-09 15:08:12 +00007476
Douglas Gregorb98b1992009-08-11 05:31:07 +00007477template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007478ExprResult
John McCall454feb92009-12-08 09:21:05 +00007479TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007480 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007481 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007482 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007483
Douglas Gregor1af74512010-02-26 00:38:10 +00007484 // Transform the delete operator, if known.
7485 FunctionDecl *OperatorDelete = 0;
7486 if (E->getOperatorDelete()) {
7487 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007488 getDerived().TransformDecl(E->getLocStart(),
7489 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007490 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007491 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007492 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007493
Douglas Gregorb98b1992009-08-11 05:31:07 +00007494 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007495 Operand.get() == E->getArgument() &&
7496 OperatorDelete == E->getOperatorDelete()) {
7497 // Mark any declarations we need as referenced.
7498 // FIXME: instantiation-specific.
7499 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007500 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007501
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007502 if (!E->getArgument()->isTypeDependent()) {
7503 QualType Destroyed = SemaRef.Context.getBaseElementType(
7504 E->getDestroyedType());
7505 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7506 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007507 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007508 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007509 }
7510 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007511
John McCall3fa5cae2010-10-26 07:05:15 +00007512 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007513 }
Mike Stump1eb44332009-09-09 15:08:12 +00007514
Douglas Gregorb98b1992009-08-11 05:31:07 +00007515 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7516 E->isGlobalDelete(),
7517 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007518 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007519}
Mike Stump1eb44332009-09-09 15:08:12 +00007520
Douglas Gregorb98b1992009-08-11 05:31:07 +00007521template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007522ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007523TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007524 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007525 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007526 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007527 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007528
John McCallb3d87482010-08-24 05:47:05 +00007529 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007530 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007531 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007532 E->getOperatorLoc(),
7533 E->isArrow()? tok::arrow : tok::period,
7534 ObjectTypePtr,
7535 MayBePseudoDestructor);
7536 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007537 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007538
John McCallb3d87482010-08-24 05:47:05 +00007539 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007540 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7541 if (QualifierLoc) {
7542 QualifierLoc
7543 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7544 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007545 return ExprError();
7546 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007547 CXXScopeSpec SS;
7548 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007549
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007550 PseudoDestructorTypeStorage Destroyed;
7551 if (E->getDestroyedTypeInfo()) {
7552 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007553 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007554 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007555 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007556 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007557 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007558 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007559 // We aren't likely to be able to resolve the identifier down to a type
7560 // now anyway, so just retain the identifier.
7561 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7562 E->getDestroyedTypeLoc());
7563 } else {
7564 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007565 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007566 *E->getDestroyedTypeIdentifier(),
7567 E->getDestroyedTypeLoc(),
7568 /*Scope=*/0,
7569 SS, ObjectTypePtr,
7570 false);
7571 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007572 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007573
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007574 Destroyed
7575 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7576 E->getDestroyedTypeLoc());
7577 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007578
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007579 TypeSourceInfo *ScopeTypeInfo = 0;
7580 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007581 CXXScopeSpec EmptySS;
7582 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7583 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007584 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007585 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007586 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007587
John McCall9ae2f072010-08-23 23:25:46 +00007588 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007589 E->getOperatorLoc(),
7590 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007591 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007592 ScopeTypeInfo,
7593 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007594 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007595 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007596}
Mike Stump1eb44332009-09-09 15:08:12 +00007597
Douglas Gregora71d8192009-09-04 17:36:40 +00007598template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007599ExprResult
John McCallba135432009-11-21 08:51:07 +00007600TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007601 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007602 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7603 Sema::LookupOrdinaryName);
7604
7605 // Transform all the decls.
7606 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7607 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007608 NamedDecl *InstD = static_cast<NamedDecl*>(
7609 getDerived().TransformDecl(Old->getNameLoc(),
7610 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007611 if (!InstD) {
7612 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7613 // This can happen because of dependent hiding.
7614 if (isa<UsingShadowDecl>(*I))
7615 continue;
7616 else
John McCallf312b1e2010-08-26 23:41:50 +00007617 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007618 }
John McCallf7a1a742009-11-24 19:00:30 +00007619
7620 // Expand using declarations.
7621 if (isa<UsingDecl>(InstD)) {
7622 UsingDecl *UD = cast<UsingDecl>(InstD);
7623 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7624 E = UD->shadow_end(); I != E; ++I)
7625 R.addDecl(*I);
7626 continue;
7627 }
7628
7629 R.addDecl(InstD);
7630 }
7631
7632 // Resolve a kind, but don't do any further analysis. If it's
7633 // ambiguous, the callee needs to deal with it.
7634 R.resolveKind();
7635
7636 // Rebuild the nested-name qualifier, if present.
7637 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007638 if (Old->getQualifierLoc()) {
7639 NestedNameSpecifierLoc QualifierLoc
7640 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7641 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007642 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007643
Douglas Gregor4c9be892011-02-28 20:01:57 +00007644 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007645 }
7646
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007647 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007648 CXXRecordDecl *NamingClass
7649 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7650 Old->getNameLoc(),
7651 Old->getNamingClass()));
7652 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007653 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007654
Douglas Gregor66c45152010-04-27 16:10:10 +00007655 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007656 }
7657
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007658 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7659
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007660 // If we have neither explicit template arguments, nor the template keyword,
7661 // it's a normal declaration name.
7662 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007663 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7664
7665 // If we have template arguments, rebuild them, then rebuild the
7666 // templateid expression.
7667 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007668 if (Old->hasExplicitTemplateArgs() &&
7669 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007670 Old->getNumTemplateArgs(),
7671 TransArgs))
7672 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007673
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007674 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007675 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007676}
Mike Stump1eb44332009-09-09 15:08:12 +00007677
Douglas Gregorb98b1992009-08-11 05:31:07 +00007678template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007679ExprResult
John McCall454feb92009-12-08 09:21:05 +00007680TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007681 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7682 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007683 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007684
Douglas Gregorb98b1992009-08-11 05:31:07 +00007685 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007686 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007687 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007688
Mike Stump1eb44332009-09-09 15:08:12 +00007689 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007690 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007691 T,
7692 E->getLocEnd());
7693}
Mike Stump1eb44332009-09-09 15:08:12 +00007694
Douglas Gregorb98b1992009-08-11 05:31:07 +00007695template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007696ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007697TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7698 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7699 if (!LhsT)
7700 return ExprError();
7701
7702 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7703 if (!RhsT)
7704 return ExprError();
7705
7706 if (!getDerived().AlwaysRebuild() &&
7707 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7708 return SemaRef.Owned(E);
7709
7710 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7711 E->getLocStart(),
7712 LhsT, RhsT,
7713 E->getLocEnd());
7714}
7715
7716template<typename Derived>
7717ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007718TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7719 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007720 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007721 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7722 TypeSourceInfo *From = E->getArg(I);
7723 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007724 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007725 TypeLocBuilder TLB;
7726 TLB.reserve(FromTL.getFullDataSize());
7727 QualType To = getDerived().TransformType(TLB, FromTL);
7728 if (To.isNull())
7729 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007730
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007731 if (To == From->getType())
7732 Args.push_back(From);
7733 else {
7734 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7735 ArgChanged = true;
7736 }
7737 continue;
7738 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007739
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007740 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007741
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007742 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007743 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007744 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7745 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7746 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007747
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007748 // Determine whether the set of unexpanded parameter packs can and should
7749 // be expanded.
7750 bool Expand = true;
7751 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007752 Optional<unsigned> OrigNumExpansions =
7753 ExpansionTL.getTypePtr()->getNumExpansions();
7754 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007755 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7756 PatternTL.getSourceRange(),
7757 Unexpanded,
7758 Expand, RetainExpansion,
7759 NumExpansions))
7760 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007761
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007762 if (!Expand) {
7763 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007764 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007765 // expansion.
7766 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007767
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007768 TypeLocBuilder TLB;
7769 TLB.reserve(From->getTypeLoc().getFullDataSize());
7770
7771 QualType To = getDerived().TransformType(TLB, PatternTL);
7772 if (To.isNull())
7773 return ExprError();
7774
Chad Rosier4a9d7952012-08-08 18:46:20 +00007775 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007776 PatternTL.getSourceRange(),
7777 ExpansionTL.getEllipsisLoc(),
7778 NumExpansions);
7779 if (To.isNull())
7780 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007781
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007782 PackExpansionTypeLoc ToExpansionTL
7783 = TLB.push<PackExpansionTypeLoc>(To);
7784 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7785 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7786 continue;
7787 }
7788
7789 // Expand the pack expansion by substituting for each argument in the
7790 // pack(s).
7791 for (unsigned I = 0; I != *NumExpansions; ++I) {
7792 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7793 TypeLocBuilder TLB;
7794 TLB.reserve(PatternTL.getFullDataSize());
7795 QualType To = getDerived().TransformType(TLB, PatternTL);
7796 if (To.isNull())
7797 return ExprError();
7798
7799 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7800 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007801
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007802 if (!RetainExpansion)
7803 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007804
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007805 // If we're supposed to retain a pack expansion, do so by temporarily
7806 // forgetting the partially-substituted parameter pack.
7807 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7808
7809 TypeLocBuilder TLB;
7810 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007811
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007812 QualType To = getDerived().TransformType(TLB, PatternTL);
7813 if (To.isNull())
7814 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007815
7816 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007817 PatternTL.getSourceRange(),
7818 ExpansionTL.getEllipsisLoc(),
7819 NumExpansions);
7820 if (To.isNull())
7821 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007822
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007823 PackExpansionTypeLoc ToExpansionTL
7824 = TLB.push<PackExpansionTypeLoc>(To);
7825 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7826 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7827 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007828
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007829 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7830 return SemaRef.Owned(E);
7831
7832 return getDerived().RebuildTypeTrait(E->getTrait(),
7833 E->getLocStart(),
7834 Args,
7835 E->getLocEnd());
7836}
7837
7838template<typename Derived>
7839ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007840TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7841 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7842 if (!T)
7843 return ExprError();
7844
7845 if (!getDerived().AlwaysRebuild() &&
7846 T == E->getQueriedTypeSourceInfo())
7847 return SemaRef.Owned(E);
7848
7849 ExprResult SubExpr;
7850 {
7851 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7852 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7853 if (SubExpr.isInvalid())
7854 return ExprError();
7855
7856 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7857 return SemaRef.Owned(E);
7858 }
7859
7860 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7861 E->getLocStart(),
7862 T,
7863 SubExpr.get(),
7864 E->getLocEnd());
7865}
7866
7867template<typename Derived>
7868ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007869TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7870 ExprResult SubExpr;
7871 {
7872 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7873 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7874 if (SubExpr.isInvalid())
7875 return ExprError();
7876
7877 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7878 return SemaRef.Owned(E);
7879 }
7880
7881 return getDerived().RebuildExpressionTrait(
7882 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7883}
7884
7885template<typename Derived>
7886ExprResult
John McCall865d4472009-11-19 22:55:06 +00007887TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007888 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00007889 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
7890}
7891
7892template<typename Derived>
7893ExprResult
7894TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7895 DependentScopeDeclRefExpr *E,
7896 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007897 NestedNameSpecifierLoc QualifierLoc
7898 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7899 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007900 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007901 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007902
John McCall43fed0d2010-11-12 08:19:04 +00007903 // TODO: If this is a conversion-function-id, verify that the
7904 // destination type name (if present) resolves the same way after
7905 // instantiation as it did in the local scope.
7906
Abramo Bagnara25777432010-08-11 22:01:17 +00007907 DeclarationNameInfo NameInfo
7908 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7909 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007910 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007911
John McCallf7a1a742009-11-24 19:00:30 +00007912 if (!E->hasExplicitTemplateArgs()) {
7913 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007914 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007915 // Note: it is sufficient to compare the Name component of NameInfo:
7916 // if name has not changed, DNLoc has not changed either.
7917 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007918 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007919
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007920 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007921 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007922 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007923 /*TemplateArgs*/ 0,
7924 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007925 }
John McCalld5532b62009-11-23 01:53:49 +00007926
7927 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007928 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7929 E->getNumTemplateArgs(),
7930 TransArgs))
7931 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007932
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007933 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007934 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007935 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007936 &TransArgs,
7937 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007938}
7939
7940template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007941ExprResult
John McCall454feb92009-12-08 09:21:05 +00007942TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00007943 // CXXConstructExprs other than for list-initialization and
7944 // CXXTemporaryObjectExpr are always implicit, so when we have
7945 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00007946 if ((E->getNumArgs() == 1 ||
7947 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00007948 (!getDerived().DropCallArgument(E->getArg(0))) &&
7949 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00007950 return getDerived().TransformExpr(E->getArg(0));
7951
Douglas Gregorb98b1992009-08-11 05:31:07 +00007952 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7953
7954 QualType T = getDerived().TransformType(E->getType());
7955 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007956 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007957
7958 CXXConstructorDecl *Constructor
7959 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007960 getDerived().TransformDecl(E->getLocStart(),
7961 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007962 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007963 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007964
Douglas Gregorb98b1992009-08-11 05:31:07 +00007965 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007966 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007967 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007968 &ArgumentChanged))
7969 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007970
Douglas Gregorb98b1992009-08-11 05:31:07 +00007971 if (!getDerived().AlwaysRebuild() &&
7972 T == E->getType() &&
7973 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007974 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007975 // Mark the constructor as referenced.
7976 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007977 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007978 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007979 }
Mike Stump1eb44332009-09-09 15:08:12 +00007980
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007981 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7982 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007983 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007984 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00007985 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007986 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007987 E->getConstructionKind(),
7988 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007989}
Mike Stump1eb44332009-09-09 15:08:12 +00007990
Douglas Gregorb98b1992009-08-11 05:31:07 +00007991/// \brief Transform a C++ temporary-binding expression.
7992///
Douglas Gregor51326552009-12-24 18:51:59 +00007993/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7994/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007995template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007996ExprResult
John McCall454feb92009-12-08 09:21:05 +00007997TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007998 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007999}
Mike Stump1eb44332009-09-09 15:08:12 +00008000
John McCall4765fa02010-12-06 08:20:24 +00008001/// \brief Transform a C++ expression that contains cleanups that should
8002/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008003///
John McCall4765fa02010-12-06 08:20:24 +00008004/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00008005/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008006template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008007ExprResult
John McCall4765fa02010-12-06 08:20:24 +00008008TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008009 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008010}
Mike Stump1eb44332009-09-09 15:08:12 +00008011
Douglas Gregorb98b1992009-08-11 05:31:07 +00008012template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008013ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008014TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00008015 CXXTemporaryObjectExpr *E) {
8016 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8017 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008018 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008019
Douglas Gregorb98b1992009-08-11 05:31:07 +00008020 CXXConstructorDecl *Constructor
8021 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008022 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008023 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008024 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008025 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008026
Douglas Gregorb98b1992009-08-11 05:31:07 +00008027 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008028 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00008029 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008030 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008031 &ArgumentChanged))
8032 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008033
Douglas Gregorb98b1992009-08-11 05:31:07 +00008034 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008035 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008036 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00008037 !ArgumentChanged) {
8038 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008039 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008040 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00008041 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008042
Richard Smithc83c2302012-12-19 01:39:02 +00008043 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00008044 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8045 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008046 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008047 E->getLocEnd());
8048}
Mike Stump1eb44332009-09-09 15:08:12 +00008049
Douglas Gregorb98b1992009-08-11 05:31:07 +00008050template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008051ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008052TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00008053 // Transform the type of the lambda parameters and start the definition of
8054 // the lambda itself.
8055 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00008056 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00008057 if (!MethodTy)
8058 return ExprError();
8059
Eli Friedman8da8a662012-09-19 01:18:11 +00008060 // Create the local class that will describe the lambda.
8061 CXXRecordDecl *Class
8062 = getSema().createLambdaClosureType(E->getIntroducerRange(),
8063 MethodTy,
8064 /*KnownDependent=*/false);
8065 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8066
Douglas Gregorc6889e72012-02-14 22:28:59 +00008067 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008068 SmallVector<QualType, 4> ParamTypes;
8069 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00008070 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
8071 E->getCallOperator()->param_begin(),
8072 E->getCallOperator()->param_size(),
8073 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00008074 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00008075
Douglas Gregordfca6f52012-02-13 22:00:16 +00008076 // Build the call operator.
8077 CXXMethodDecl *CallOperator
8078 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008079 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008080 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008081 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008082 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00008083
Richard Smith612409e2012-07-25 03:56:55 +00008084 return getDerived().TransformLambdaScope(E, CallOperator);
8085}
8086
8087template<typename Derived>
8088ExprResult
8089TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8090 CXXMethodDecl *CallOperator) {
Richard Smith0d8e9642013-05-16 06:20:58 +00008091 bool Invalid = false;
8092
8093 // Transform any init-capture expressions before entering the scope of the
8094 // lambda.
8095 llvm::SmallVector<ExprResult, 8> InitCaptureExprs;
8096 InitCaptureExprs.resize(E->explicit_capture_end() -
8097 E->explicit_capture_begin());
8098 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8099 CEnd = E->capture_end();
8100 C != CEnd; ++C) {
8101 if (!C->isInitCapture())
8102 continue;
8103 InitCaptureExprs[C - E->capture_begin()] =
8104 getDerived().TransformExpr(E->getInitCaptureInit(C));
8105 }
8106
Douglas Gregord5387e82012-02-14 00:00:48 +00008107 // Introduce the context of the call operator.
8108 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8109
Douglas Gregordfca6f52012-02-13 22:00:16 +00008110 // Enter the scope of the lambda.
8111 sema::LambdaScopeInfo *LSI
8112 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
8113 E->getCaptureDefault(),
8114 E->hasExplicitParameters(),
8115 E->hasExplicitResultType(),
8116 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008117
Douglas Gregordfca6f52012-02-13 22:00:16 +00008118 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00008119 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008120 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008121 CEnd = E->capture_end();
8122 C != CEnd; ++C) {
8123 // When we hit the first implicit capture, tell Sema that we've finished
8124 // the list of explicit captures.
8125 if (!FinishedExplicitCaptures && C->isImplicit()) {
8126 getSema().finishLambdaExplicitCaptures(LSI);
8127 FinishedExplicitCaptures = true;
8128 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008129
Douglas Gregordfca6f52012-02-13 22:00:16 +00008130 // Capturing 'this' is trivial.
8131 if (C->capturesThis()) {
8132 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8133 continue;
8134 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008135
Richard Smith0d8e9642013-05-16 06:20:58 +00008136 // Rebuild init-captures, including the implied field declaration.
8137 if (C->isInitCapture()) {
8138 ExprResult Init = InitCaptureExprs[C - E->capture_begin()];
8139 if (Init.isInvalid()) {
8140 Invalid = true;
8141 continue;
8142 }
8143 FieldDecl *OldFD = C->getInitCaptureField();
8144 FieldDecl *NewFD = getSema().checkInitCapture(
8145 C->getLocation(), OldFD->getType()->isReferenceType(),
8146 OldFD->getIdentifier(), Init.take());
8147 if (!NewFD)
8148 Invalid = true;
8149 else
8150 getDerived().transformedLocalDecl(OldFD, NewFD);
8151 continue;
8152 }
8153
8154 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8155
Douglas Gregora7365242012-02-14 19:27:52 +00008156 // Determine the capture kind for Sema.
8157 Sema::TryCaptureKind Kind
8158 = C->isImplicit()? Sema::TryCapture_Implicit
8159 : C->getCaptureKind() == LCK_ByCopy
8160 ? Sema::TryCapture_ExplicitByVal
8161 : Sema::TryCapture_ExplicitByRef;
8162 SourceLocation EllipsisLoc;
8163 if (C->isPackExpansion()) {
8164 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8165 bool ShouldExpand = false;
8166 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008167 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008168 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8169 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008170 Unexpanded,
8171 ShouldExpand, RetainExpansion,
Richard Smith0d8e9642013-05-16 06:20:58 +00008172 NumExpansions)) {
8173 Invalid = true;
8174 continue;
8175 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008176
Douglas Gregora7365242012-02-14 19:27:52 +00008177 if (ShouldExpand) {
8178 // The transform has determined that we should perform an expansion;
8179 // transform and capture each of the arguments.
8180 // expansion of the pattern. Do so.
8181 VarDecl *Pack = C->getCapturedVar();
8182 for (unsigned I = 0; I != *NumExpansions; ++I) {
8183 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8184 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008185 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008186 Pack));
8187 if (!CapturedVar) {
8188 Invalid = true;
8189 continue;
8190 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008191
Douglas Gregora7365242012-02-14 19:27:52 +00008192 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008193 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8194 }
Douglas Gregora7365242012-02-14 19:27:52 +00008195 continue;
8196 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008197
Douglas Gregora7365242012-02-14 19:27:52 +00008198 EllipsisLoc = C->getEllipsisLoc();
8199 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008200
Douglas Gregordfca6f52012-02-13 22:00:16 +00008201 // Transform the captured variable.
8202 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008203 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008204 C->getCapturedVar()));
8205 if (!CapturedVar) {
8206 Invalid = true;
8207 continue;
8208 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008209
Douglas Gregordfca6f52012-02-13 22:00:16 +00008210 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008211 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008212 }
8213 if (!FinishedExplicitCaptures)
8214 getSema().finishLambdaExplicitCaptures(LSI);
8215
Douglas Gregordfca6f52012-02-13 22:00:16 +00008216
8217 // Enter a new evaluation context to insulate the lambda from any
8218 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008219 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008220
8221 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008222 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008223 /*IsInstantiation=*/true);
8224 return ExprError();
8225 }
8226
8227 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008228 StmtResult Body = getDerived().TransformStmt(E->getBody());
8229 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008230 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008231 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008232 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008233 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008234
Chad Rosier4a9d7952012-08-08 18:46:20 +00008235 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008236 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008237}
8238
8239template<typename Derived>
8240ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008241TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008242 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008243 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8244 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008245 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008246
Douglas Gregorb98b1992009-08-11 05:31:07 +00008247 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008248 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008249 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008250 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008251 &ArgumentChanged))
8252 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008253
Douglas Gregorb98b1992009-08-11 05:31:07 +00008254 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008255 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008256 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008257 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008258
Douglas Gregorb98b1992009-08-11 05:31:07 +00008259 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008260 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008261 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008262 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008263 E->getRParenLoc());
8264}
Mike Stump1eb44332009-09-09 15:08:12 +00008265
Douglas Gregorb98b1992009-08-11 05:31:07 +00008266template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008267ExprResult
John McCall865d4472009-11-19 22:55:06 +00008268TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008269 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008270 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008271 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008272 Expr *OldBase;
8273 QualType BaseType;
8274 QualType ObjectType;
8275 if (!E->isImplicitAccess()) {
8276 OldBase = E->getBase();
8277 Base = getDerived().TransformExpr(OldBase);
8278 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008279 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008280
John McCallaa81e162009-12-01 22:10:20 +00008281 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008282 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008283 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008284 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008285 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008286 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008287 ObjectTy,
8288 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008289 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008290 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008291
John McCallb3d87482010-08-24 05:47:05 +00008292 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008293 BaseType = ((Expr*) Base.get())->getType();
8294 } else {
8295 OldBase = 0;
8296 BaseType = getDerived().TransformType(E->getBaseType());
8297 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8298 }
Mike Stump1eb44332009-09-09 15:08:12 +00008299
Douglas Gregor6cd21982009-10-20 05:58:46 +00008300 // Transform the first part of the nested-name-specifier that qualifies
8301 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008302 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008303 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008304 E->getFirstQualifierFoundInScope(),
8305 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008306
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008307 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008308 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008309 QualifierLoc
8310 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8311 ObjectType,
8312 FirstQualifierInScope);
8313 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008314 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008315 }
Mike Stump1eb44332009-09-09 15:08:12 +00008316
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008317 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8318
John McCall43fed0d2010-11-12 08:19:04 +00008319 // TODO: If this is a conversion-function-id, verify that the
8320 // destination type name (if present) resolves the same way after
8321 // instantiation as it did in the local scope.
8322
Abramo Bagnara25777432010-08-11 22:01:17 +00008323 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008324 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008325 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008326 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008327
John McCallaa81e162009-12-01 22:10:20 +00008328 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008329 // This is a reference to a member without an explicitly-specified
8330 // template argument list. Optimize for this common case.
8331 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008332 Base.get() == OldBase &&
8333 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008334 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008335 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008336 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008337 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008338
John McCall9ae2f072010-08-23 23:25:46 +00008339 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008340 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008341 E->isArrow(),
8342 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008343 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008344 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008345 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008346 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008347 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008348 }
8349
John McCalld5532b62009-11-23 01:53:49 +00008350 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008351 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8352 E->getNumTemplateArgs(),
8353 TransArgs))
8354 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008355
John McCall9ae2f072010-08-23 23:25:46 +00008356 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008357 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008358 E->isArrow(),
8359 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008360 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008361 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008362 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008363 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008364 &TransArgs);
8365}
8366
8367template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008368ExprResult
John McCall454feb92009-12-08 09:21:05 +00008369TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008370 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008371 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008372 QualType BaseType;
8373 if (!Old->isImplicitAccess()) {
8374 Base = getDerived().TransformExpr(Old->getBase());
8375 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008376 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008377 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8378 Old->isArrow());
8379 if (Base.isInvalid())
8380 return ExprError();
8381 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008382 } else {
8383 BaseType = getDerived().TransformType(Old->getBaseType());
8384 }
John McCall129e2df2009-11-30 22:42:35 +00008385
Douglas Gregor4c9be892011-02-28 20:01:57 +00008386 NestedNameSpecifierLoc QualifierLoc;
8387 if (Old->getQualifierLoc()) {
8388 QualifierLoc
8389 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8390 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008391 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008392 }
8393
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008394 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8395
Abramo Bagnara25777432010-08-11 22:01:17 +00008396 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008397 Sema::LookupOrdinaryName);
8398
8399 // Transform all the decls.
8400 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8401 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008402 NamedDecl *InstD = static_cast<NamedDecl*>(
8403 getDerived().TransformDecl(Old->getMemberLoc(),
8404 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008405 if (!InstD) {
8406 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8407 // This can happen because of dependent hiding.
8408 if (isa<UsingShadowDecl>(*I))
8409 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008410 else {
8411 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008412 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008413 }
John McCall9f54ad42009-12-10 09:41:52 +00008414 }
John McCall129e2df2009-11-30 22:42:35 +00008415
8416 // Expand using declarations.
8417 if (isa<UsingDecl>(InstD)) {
8418 UsingDecl *UD = cast<UsingDecl>(InstD);
8419 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8420 E = UD->shadow_end(); I != E; ++I)
8421 R.addDecl(*I);
8422 continue;
8423 }
8424
8425 R.addDecl(InstD);
8426 }
8427
8428 R.resolveKind();
8429
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008430 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008431 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008432 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008433 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008434 Old->getMemberLoc(),
8435 Old->getNamingClass()));
8436 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008437 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008438
Douglas Gregor66c45152010-04-27 16:10:10 +00008439 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008440 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008441
John McCall129e2df2009-11-30 22:42:35 +00008442 TemplateArgumentListInfo TransArgs;
8443 if (Old->hasExplicitTemplateArgs()) {
8444 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8445 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008446 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8447 Old->getNumTemplateArgs(),
8448 TransArgs))
8449 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008450 }
John McCallc2233c52010-01-15 08:34:02 +00008451
8452 // FIXME: to do this check properly, we will need to preserve the
8453 // first-qualifier-in-scope here, just in case we had a dependent
8454 // base (and therefore couldn't do the check) and a
8455 // nested-name-qualifier (and therefore could do the lookup).
8456 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008457
John McCall9ae2f072010-08-23 23:25:46 +00008458 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008459 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008460 Old->getOperatorLoc(),
8461 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008462 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008463 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008464 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008465 R,
8466 (Old->hasExplicitTemplateArgs()
8467 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008468}
8469
8470template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008471ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008472TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008473 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008474 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8475 if (SubExpr.isInvalid())
8476 return ExprError();
8477
8478 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008479 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008480
8481 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8482}
8483
8484template<typename Derived>
8485ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008486TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008487 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8488 if (Pattern.isInvalid())
8489 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008490
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008491 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8492 return SemaRef.Owned(E);
8493
Douglas Gregor67fd1252011-01-14 21:20:45 +00008494 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8495 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008496}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008497
8498template<typename Derived>
8499ExprResult
8500TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8501 // If E is not value-dependent, then nothing will change when we transform it.
8502 // Note: This is an instantiation-centric view.
8503 if (!E->isValueDependent())
8504 return SemaRef.Owned(E);
8505
8506 // Note: None of the implementations of TryExpandParameterPacks can ever
8507 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008508 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008509 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8510 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008511 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008512 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008513 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008514 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008515 ShouldExpand, RetainExpansion,
8516 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008517 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008518
Douglas Gregor089e8932011-10-10 18:59:29 +00008519 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008520 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008521
Douglas Gregor089e8932011-10-10 18:59:29 +00008522 NamedDecl *Pack = E->getPack();
8523 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008524 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008525 Pack));
8526 if (!Pack)
8527 return ExprError();
8528 }
8529
Chad Rosier4a9d7952012-08-08 18:46:20 +00008530
Douglas Gregoree8aff02011-01-04 17:33:58 +00008531 // We now know the length of the parameter pack, so build a new expression
8532 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008533 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8534 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008535 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008536}
8537
Douglas Gregorbe230c32011-01-03 17:17:50 +00008538template<typename Derived>
8539ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008540TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8541 SubstNonTypeTemplateParmPackExpr *E) {
8542 // Default behavior is to do nothing with this transformation.
8543 return SemaRef.Owned(E);
8544}
8545
8546template<typename Derived>
8547ExprResult
John McCall91a57552011-07-15 05:09:51 +00008548TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8549 SubstNonTypeTemplateParmExpr *E) {
8550 // Default behavior is to do nothing with this transformation.
8551 return SemaRef.Owned(E);
8552}
8553
8554template<typename Derived>
8555ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008556TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8557 // Default behavior is to do nothing with this transformation.
8558 return SemaRef.Owned(E);
8559}
8560
8561template<typename Derived>
8562ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008563TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8564 MaterializeTemporaryExpr *E) {
8565 return getDerived().TransformExpr(E->GetTemporaryExpr());
8566}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008567
Douglas Gregor03e80032011-06-21 17:03:29 +00008568template<typename Derived>
8569ExprResult
Richard Smith7c3e6152013-06-12 22:31:48 +00008570TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8571 CXXStdInitializerListExpr *E) {
8572 return getDerived().TransformExpr(E->getSubExpr());
8573}
8574
8575template<typename Derived>
8576ExprResult
John McCall454feb92009-12-08 09:21:05 +00008577TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008578 return SemaRef.MaybeBindToTemporary(E);
8579}
8580
8581template<typename Derived>
8582ExprResult
8583TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008584 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008585}
8586
8587template<typename Derived>
8588ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008589TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8590 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8591 if (SubExpr.isInvalid())
8592 return ExprError();
8593
8594 if (!getDerived().AlwaysRebuild() &&
8595 SubExpr.get() == E->getSubExpr())
8596 return SemaRef.Owned(E);
8597
8598 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008599}
8600
8601template<typename Derived>
8602ExprResult
8603TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8604 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008605 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008606 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008607 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008608 /*IsCall=*/false, Elements, &ArgChanged))
8609 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008610
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008611 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8612 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008613
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008614 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8615 Elements.data(),
8616 Elements.size());
8617}
8618
8619template<typename Derived>
8620ExprResult
8621TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008622 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008623 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008624 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008625 bool ArgChanged = false;
8626 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8627 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008628
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008629 if (OrigElement.isPackExpansion()) {
8630 // This key/value element is a pack expansion.
8631 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8632 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8633 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8634 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8635
8636 // Determine whether the set of unexpanded parameter packs can
8637 // and should be expanded.
8638 bool Expand = true;
8639 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008640 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8641 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008642 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8643 OrigElement.Value->getLocEnd());
8644 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8645 PatternRange,
8646 Unexpanded,
8647 Expand, RetainExpansion,
8648 NumExpansions))
8649 return ExprError();
8650
8651 if (!Expand) {
8652 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008653 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008654 // expansion.
8655 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8656 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8657 if (Key.isInvalid())
8658 return ExprError();
8659
8660 if (Key.get() != OrigElement.Key)
8661 ArgChanged = true;
8662
8663 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8664 if (Value.isInvalid())
8665 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008666
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008667 if (Value.get() != OrigElement.Value)
8668 ArgChanged = true;
8669
Chad Rosier4a9d7952012-08-08 18:46:20 +00008670 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008671 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8672 };
8673 Elements.push_back(Expansion);
8674 continue;
8675 }
8676
8677 // Record right away that the argument was changed. This needs
8678 // to happen even if the array expands to nothing.
8679 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008680
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008681 // The transform has determined that we should perform an elementwise
8682 // expansion of the pattern. Do so.
8683 for (unsigned I = 0; I != *NumExpansions; ++I) {
8684 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8685 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8686 if (Key.isInvalid())
8687 return ExprError();
8688
8689 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8690 if (Value.isInvalid())
8691 return ExprError();
8692
Chad Rosier4a9d7952012-08-08 18:46:20 +00008693 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008694 Key.get(), Value.get(), SourceLocation(), NumExpansions
8695 };
8696
8697 // If any unexpanded parameter packs remain, we still have a
8698 // pack expansion.
8699 if (Key.get()->containsUnexpandedParameterPack() ||
8700 Value.get()->containsUnexpandedParameterPack())
8701 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008702
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008703 Elements.push_back(Element);
8704 }
8705
8706 // We've finished with this pack expansion.
8707 continue;
8708 }
8709
8710 // Transform and check key.
8711 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8712 if (Key.isInvalid())
8713 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008714
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008715 if (Key.get() != OrigElement.Key)
8716 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008717
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008718 // Transform and check value.
8719 ExprResult Value
8720 = getDerived().TransformExpr(OrigElement.Value);
8721 if (Value.isInvalid())
8722 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008723
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008724 if (Value.get() != OrigElement.Value)
8725 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008726
8727 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008728 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008729 };
8730 Elements.push_back(Element);
8731 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008732
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008733 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8734 return SemaRef.MaybeBindToTemporary(E);
8735
8736 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8737 Elements.data(),
8738 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008739}
8740
Mike Stump1eb44332009-09-09 15:08:12 +00008741template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008742ExprResult
John McCall454feb92009-12-08 09:21:05 +00008743TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008744 TypeSourceInfo *EncodedTypeInfo
8745 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8746 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008747 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008748
Douglas Gregorb98b1992009-08-11 05:31:07 +00008749 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008750 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008751 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008752
8753 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008754 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008755 E->getRParenLoc());
8756}
Mike Stump1eb44332009-09-09 15:08:12 +00008757
Douglas Gregorb98b1992009-08-11 05:31:07 +00008758template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008759ExprResult TreeTransform<Derived>::
8760TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00008761 // This is a kind of implicit conversion, and it needs to get dropped
8762 // and recomputed for the same general reasons that ImplicitCastExprs
8763 // do, as well a more specific one: this expression is only valid when
8764 // it appears *immediately* as an argument expression.
8765 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00008766}
8767
8768template<typename Derived>
8769ExprResult TreeTransform<Derived>::
8770TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008771 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008772 = getDerived().TransformType(E->getTypeInfoAsWritten());
8773 if (!TSInfo)
8774 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008775
John McCallf85e1932011-06-15 23:02:42 +00008776 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008777 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008778 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008779
John McCallf85e1932011-06-15 23:02:42 +00008780 if (!getDerived().AlwaysRebuild() &&
8781 TSInfo == E->getTypeInfoAsWritten() &&
8782 Result.get() == E->getSubExpr())
8783 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008784
John McCallf85e1932011-06-15 23:02:42 +00008785 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008786 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008787 Result.get());
8788}
8789
8790template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008791ExprResult
John McCall454feb92009-12-08 09:21:05 +00008792TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008793 // Transform arguments.
8794 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008795 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008796 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008797 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008798 &ArgChanged))
8799 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008800
Douglas Gregor92e986e2010-04-22 16:44:27 +00008801 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8802 // Class message: transform the receiver type.
8803 TypeSourceInfo *ReceiverTypeInfo
8804 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8805 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008806 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008807
Douglas Gregor92e986e2010-04-22 16:44:27 +00008808 // If nothing changed, just retain the existing message send.
8809 if (!getDerived().AlwaysRebuild() &&
8810 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008811 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008812
8813 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008814 SmallVector<SourceLocation, 16> SelLocs;
8815 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008816 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8817 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008818 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008819 E->getMethodDecl(),
8820 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008821 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008822 E->getRightLoc());
8823 }
8824
8825 // Instance message: transform the receiver
8826 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8827 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008828 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008829 = getDerived().TransformExpr(E->getInstanceReceiver());
8830 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008831 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008832
8833 // If nothing changed, just retain the existing message send.
8834 if (!getDerived().AlwaysRebuild() &&
8835 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008836 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008837
Douglas Gregor92e986e2010-04-22 16:44:27 +00008838 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008839 SmallVector<SourceLocation, 16> SelLocs;
8840 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008841 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008842 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008843 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008844 E->getMethodDecl(),
8845 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008846 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008847 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008848}
8849
Mike Stump1eb44332009-09-09 15:08:12 +00008850template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008851ExprResult
John McCall454feb92009-12-08 09:21:05 +00008852TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008853 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008854}
8855
Mike Stump1eb44332009-09-09 15:08:12 +00008856template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008857ExprResult
John McCall454feb92009-12-08 09:21:05 +00008858TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008859 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008860}
8861
Mike Stump1eb44332009-09-09 15:08:12 +00008862template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008863ExprResult
John McCall454feb92009-12-08 09:21:05 +00008864TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008865 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008866 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008867 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008868 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008869
8870 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008871
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008872 // If nothing changed, just retain the existing expression.
8873 if (!getDerived().AlwaysRebuild() &&
8874 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008875 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008876
John McCall9ae2f072010-08-23 23:25:46 +00008877 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008878 E->getLocation(),
8879 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008880}
8881
Mike Stump1eb44332009-09-09 15:08:12 +00008882template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008883ExprResult
John McCall454feb92009-12-08 09:21:05 +00008884TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008885 // 'super' and types never change. Property never changes. Just
8886 // retain the existing expression.
8887 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008888 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008889
Douglas Gregore3303542010-04-26 20:47:02 +00008890 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008891 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008892 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008893 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008894
Douglas Gregore3303542010-04-26 20:47:02 +00008895 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008896
Douglas Gregore3303542010-04-26 20:47:02 +00008897 // If nothing changed, just retain the existing expression.
8898 if (!getDerived().AlwaysRebuild() &&
8899 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008900 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008901
John McCall12f78a62010-12-02 01:19:52 +00008902 if (E->isExplicitProperty())
8903 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8904 E->getExplicitProperty(),
8905 E->getLocation());
8906
8907 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008908 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008909 E->getImplicitPropertyGetter(),
8910 E->getImplicitPropertySetter(),
8911 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008912}
8913
Mike Stump1eb44332009-09-09 15:08:12 +00008914template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008915ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008916TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8917 // Transform the base expression.
8918 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8919 if (Base.isInvalid())
8920 return ExprError();
8921
8922 // Transform the key expression.
8923 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8924 if (Key.isInvalid())
8925 return ExprError();
8926
8927 // If nothing changed, just retain the existing expression.
8928 if (!getDerived().AlwaysRebuild() &&
8929 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8930 return SemaRef.Owned(E);
8931
Chad Rosier4a9d7952012-08-08 18:46:20 +00008932 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008933 Base.get(), Key.get(),
8934 E->getAtIndexMethodDecl(),
8935 E->setAtIndexMethodDecl());
8936}
8937
8938template<typename Derived>
8939ExprResult
John McCall454feb92009-12-08 09:21:05 +00008940TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008941 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008942 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008943 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008944 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008945
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008946 // If nothing changed, just retain the existing expression.
8947 if (!getDerived().AlwaysRebuild() &&
8948 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008949 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008950
John McCall9ae2f072010-08-23 23:25:46 +00008951 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00008952 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008953 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008954}
8955
Mike Stump1eb44332009-09-09 15:08:12 +00008956template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008957ExprResult
John McCall454feb92009-12-08 09:21:05 +00008958TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008959 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008960 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008961 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008962 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008963 SubExprs, &ArgumentChanged))
8964 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008965
Douglas Gregorb98b1992009-08-11 05:31:07 +00008966 if (!getDerived().AlwaysRebuild() &&
8967 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008968 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008969
Douglas Gregorb98b1992009-08-11 05:31:07 +00008970 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008971 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008972 E->getRParenLoc());
8973}
8974
Mike Stump1eb44332009-09-09 15:08:12 +00008975template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008976ExprResult
John McCall454feb92009-12-08 09:21:05 +00008977TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008978 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008979
John McCallc6ac9c32011-02-04 18:33:18 +00008980 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8981 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8982
8983 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008984 blockScope->TheDecl->setBlockMissingReturnType(
8985 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008986
Chris Lattner686775d2011-07-20 06:58:45 +00008987 SmallVector<ParmVarDecl*, 4> params;
8988 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008989
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008990 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008991 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8992 oldBlock->param_begin(),
8993 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008994 0, paramTypes, &params)) {
8995 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008996 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008997 }
John McCallc6ac9c32011-02-04 18:33:18 +00008998
Jordan Rose09189892013-03-08 22:25:36 +00008999 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00009000 QualType exprResultType =
9001 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00009002
Jordan Rosebea522f2013-03-08 21:51:21 +00009003 QualType functionType =
9004 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009005 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00009006 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00009007
9008 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00009009 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00009010 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00009011
9012 if (!oldBlock->blockMissingReturnType()) {
9013 blockScope->HasImplicitReturnType = false;
9014 blockScope->ReturnType = exprResultType;
9015 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009016
John McCall711c52b2011-01-05 12:14:39 +00009017 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00009018 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009019 if (body.isInvalid()) {
9020 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00009021 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009022 }
John McCall711c52b2011-01-05 12:14:39 +00009023
John McCallc6ac9c32011-02-04 18:33:18 +00009024#ifndef NDEBUG
9025 // In builds with assertions, make sure that we captured everything we
9026 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00009027 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9028 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9029 e = oldBlock->capture_end(); i != e; ++i) {
9030 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00009031
Douglas Gregorfc921372011-05-20 15:32:55 +00009032 // Ignore parameter packs.
9033 if (isa<ParmVarDecl>(oldCapture) &&
9034 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9035 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00009036
Douglas Gregorfc921372011-05-20 15:32:55 +00009037 VarDecl *newCapture =
9038 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9039 oldCapture));
9040 assert(blockScope->CaptureMap.count(newCapture));
9041 }
Douglas Gregorec79d872012-02-24 17:41:38 +00009042 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00009043 }
9044#endif
9045
9046 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9047 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009048}
9049
Mike Stump1eb44332009-09-09 15:08:12 +00009050template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009051ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009052TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00009053 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009054}
Eli Friedman276b0612011-10-11 02:20:01 +00009055
9056template<typename Derived>
9057ExprResult
9058TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009059 QualType RetTy = getDerived().TransformType(E->getType());
9060 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009061 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009062 SubExprs.reserve(E->getNumSubExprs());
9063 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9064 SubExprs, &ArgumentChanged))
9065 return ExprError();
9066
9067 if (!getDerived().AlwaysRebuild() &&
9068 !ArgumentChanged)
9069 return SemaRef.Owned(E);
9070
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009071 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009072 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00009073}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009074
Douglas Gregorb98b1992009-08-11 05:31:07 +00009075//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00009076// Type reconstruction
9077//===----------------------------------------------------------------------===//
9078
Mike Stump1eb44332009-09-09 15:08:12 +00009079template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009080QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9081 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009082 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009083 getDerived().getBaseEntity());
9084}
9085
Mike Stump1eb44332009-09-09 15:08:12 +00009086template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009087QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9088 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009089 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009090 getDerived().getBaseEntity());
9091}
9092
Mike Stump1eb44332009-09-09 15:08:12 +00009093template<typename Derived>
9094QualType
John McCall85737a72009-10-30 00:06:24 +00009095TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9096 bool WrittenAsLValue,
9097 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009098 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009099 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009100}
9101
9102template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009103QualType
John McCall85737a72009-10-30 00:06:24 +00009104TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9105 QualType ClassType,
9106 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009107 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009108 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009109}
9110
9111template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009112QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009113TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9114 ArrayType::ArraySizeModifier SizeMod,
9115 const llvm::APInt *Size,
9116 Expr *SizeExpr,
9117 unsigned IndexTypeQuals,
9118 SourceRange BracketsRange) {
9119 if (SizeExpr || !Size)
9120 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9121 IndexTypeQuals, BracketsRange,
9122 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009123
9124 QualType Types[] = {
9125 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9126 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9127 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009128 };
Craig Topperb9602322013-07-15 03:38:40 +00009129 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009130 QualType SizeType;
9131 for (unsigned I = 0; I != NumTypes; ++I)
9132 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9133 SizeType = Types[I];
9134 break;
9135 }
Mike Stump1eb44332009-09-09 15:08:12 +00009136
Eli Friedman01f276d2012-01-25 23:20:27 +00009137 // Note that we can return a VariableArrayType here in the case where
9138 // the element type was a dependent VariableArrayType.
9139 IntegerLiteral *ArraySize
9140 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9141 /*FIXME*/BracketsRange.getBegin());
9142 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009143 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009144 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009145}
Mike Stump1eb44332009-09-09 15:08:12 +00009146
Douglas Gregor577f75a2009-08-04 16:50:30 +00009147template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009148QualType
9149TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009150 ArrayType::ArraySizeModifier SizeMod,
9151 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009152 unsigned IndexTypeQuals,
9153 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009154 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009155 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009156}
9157
9158template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009159QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009160TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009161 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009162 unsigned IndexTypeQuals,
9163 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009164 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009165 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009166}
Mike Stump1eb44332009-09-09 15:08:12 +00009167
Douglas Gregor577f75a2009-08-04 16:50:30 +00009168template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009169QualType
9170TreeTransform<Derived>::RebuildVariableArrayType(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>
Mike Stump1eb44332009-09-09 15:08:12 +00009181QualType
9182TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009183 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009184 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009185 unsigned IndexTypeQuals,
9186 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009187 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009188 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009189 IndexTypeQuals, BracketsRange);
9190}
9191
9192template<typename Derived>
9193QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009194 unsigned NumElements,
9195 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009196 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009197 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
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>
9201QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9202 unsigned NumElements,
9203 SourceLocation AttributeLoc) {
9204 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9205 NumElements, true);
9206 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009207 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9208 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009209 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009210}
Mike Stump1eb44332009-09-09 15:08:12 +00009211
Douglas Gregor577f75a2009-08-04 16:50:30 +00009212template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009213QualType
9214TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009215 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009216 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009217 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009218}
Mike Stump1eb44332009-09-09 15:08:12 +00009219
Douglas Gregor577f75a2009-08-04 16:50:30 +00009220template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009221QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9222 QualType T,
9223 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009224 const FunctionProtoType::ExtProtoInfo &EPI) {
9225 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009226 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009227 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009228 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009229}
Mike Stump1eb44332009-09-09 15:08:12 +00009230
Douglas Gregor577f75a2009-08-04 16:50:30 +00009231template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009232QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9233 return SemaRef.Context.getFunctionNoProtoType(T);
9234}
9235
9236template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009237QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9238 assert(D && "no decl found");
9239 if (D->isInvalidDecl()) return QualType();
9240
Douglas Gregor92e986e2010-04-22 16:44:27 +00009241 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009242 TypeDecl *Ty;
9243 if (isa<UsingDecl>(D)) {
9244 UsingDecl *Using = cast<UsingDecl>(D);
9245 assert(Using->isTypeName() &&
9246 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9247
9248 // A valid resolved using typename decl points to exactly one type decl.
9249 assert(++Using->shadow_begin() == Using->shadow_end());
9250 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009251
John McCalled976492009-12-04 22:46:56 +00009252 } else {
9253 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9254 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9255 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9256 }
9257
9258 return SemaRef.Context.getTypeDeclType(Ty);
9259}
9260
9261template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009262QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9263 SourceLocation Loc) {
9264 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009265}
9266
9267template<typename Derived>
9268QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9269 return SemaRef.Context.getTypeOfType(Underlying);
9270}
9271
9272template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009273QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9274 SourceLocation Loc) {
9275 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009276}
9277
9278template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009279QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9280 UnaryTransformType::UTTKind UKind,
9281 SourceLocation Loc) {
9282 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9283}
9284
9285template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009286QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009287 TemplateName Template,
9288 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009289 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009290 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009291}
Mike Stump1eb44332009-09-09 15:08:12 +00009292
Douglas Gregordcee1a12009-08-06 05:28:30 +00009293template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009294QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9295 SourceLocation KWLoc) {
9296 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9297}
9298
9299template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009300TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009301TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009302 bool TemplateKW,
9303 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009304 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009305 Template);
9306}
9307
9308template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009309TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009310TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9311 const IdentifierInfo &Name,
9312 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009313 QualType ObjectType,
9314 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009315 UnqualifiedId TemplateName;
9316 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009317 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009318 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009319 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009320 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009321 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009322 /*EnteringContext=*/false,
9323 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009324 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009325}
Mike Stump1eb44332009-09-09 15:08:12 +00009326
Douglas Gregorb98b1992009-08-11 05:31:07 +00009327template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009328TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009329TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009330 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009331 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009332 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009333 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009334 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009335 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009336 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009337 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009338 Sema::TemplateTy Template;
9339 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009340 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009341 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009342 /*EnteringContext=*/false,
9343 Template);
9344 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009345}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009346
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009347template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009348ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009349TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9350 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009351 Expr *OrigCallee,
9352 Expr *First,
9353 Expr *Second) {
9354 Expr *Callee = OrigCallee->IgnoreParenCasts();
9355 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009356
Douglas Gregorb98b1992009-08-11 05:31:07 +00009357 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009358 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009359 if (!First->getType()->isOverloadableType() &&
9360 !Second->getType()->isOverloadableType())
9361 return getSema().CreateBuiltinArraySubscriptExpr(First,
9362 Callee->getLocStart(),
9363 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009364 } else if (Op == OO_Arrow) {
9365 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009366 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9367 } else if (Second == 0 || isPostIncDec) {
9368 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009369 // The argument is not of overloadable type, so try to create a
9370 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009371 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009372 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009373
John McCall9ae2f072010-08-23 23:25:46 +00009374 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009375 }
9376 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009377 if (!First->getType()->isOverloadableType() &&
9378 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009379 // Neither of the arguments is an overloadable type, so try to
9380 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009381 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009382 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009383 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009384 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009385 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009386
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009387 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009388 }
9389 }
Mike Stump1eb44332009-09-09 15:08:12 +00009390
9391 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009392 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009393 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009394
John McCall9ae2f072010-08-23 23:25:46 +00009395 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009396 assert(ULE->requiresADL());
9397
9398 // FIXME: Do we have to check
9399 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009400 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009401 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009402 // If we've resolved this to a particular non-member function, just call
9403 // that function. If we resolved it to a member function,
9404 // CreateOverloaded* will find that function for us.
9405 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9406 if (!isa<CXXMethodDecl>(ND))
9407 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009408 }
Mike Stump1eb44332009-09-09 15:08:12 +00009409
Douglas Gregorb98b1992009-08-11 05:31:07 +00009410 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009411 Expr *Args[2] = { First, Second };
9412 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009413
Douglas Gregorb98b1992009-08-11 05:31:07 +00009414 // Create the overloaded operator invocation for unary operators.
9415 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009416 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009417 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009418 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009419 }
Mike Stump1eb44332009-09-09 15:08:12 +00009420
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009421 if (Op == OO_Subscript) {
9422 SourceLocation LBrace;
9423 SourceLocation RBrace;
9424
9425 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9426 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9427 LBrace = SourceLocation::getFromRawEncoding(
9428 NameLoc.CXXOperatorName.BeginOpNameLoc);
9429 RBrace = SourceLocation::getFromRawEncoding(
9430 NameLoc.CXXOperatorName.EndOpNameLoc);
9431 } else {
9432 LBrace = Callee->getLocStart();
9433 RBrace = OpLoc;
9434 }
9435
9436 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9437 First, Second);
9438 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009439
Douglas Gregorb98b1992009-08-11 05:31:07 +00009440 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009441 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009442 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009443 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9444 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009445 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009446
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009447 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009448}
Mike Stump1eb44332009-09-09 15:08:12 +00009449
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009450template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009451ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009452TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009453 SourceLocation OperatorLoc,
9454 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009455 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009456 TypeSourceInfo *ScopeType,
9457 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009458 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009459 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009460 QualType BaseType = Base->getType();
9461 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009462 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009463 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009464 !BaseType->getAs<PointerType>()->getPointeeType()
9465 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009466 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009467 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009468 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009469 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009470 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009471 /*FIXME?*/true);
9472 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009473
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009474 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009475 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9476 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9477 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9478 NameInfo.setNamedTypeInfo(DestroyedType);
9479
Richard Smith6314db92012-05-15 06:15:11 +00009480 // The scope type is now known to be a valid nested name specifier
9481 // component. Tack it on to the end of the nested name specifier.
9482 if (ScopeType)
9483 SS.Extend(SemaRef.Context, SourceLocation(),
9484 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009485
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009486 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009487 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009488 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009489 SS, TemplateKWLoc,
9490 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009491 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009492 /*TemplateArgs*/ 0);
9493}
9494
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009495template<typename Derived>
9496StmtResult
9497TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan9fd6b8f2013-05-04 03:59:06 +00009498 SourceLocation Loc = S->getLocStart();
9499 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9500 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9501 S->getCapturedRegionKind(), NumParams);
9502 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9503
9504 if (Body.isInvalid()) {
9505 getSema().ActOnCapturedRegionError();
9506 return StmtError();
9507 }
9508
9509 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009510}
9511
Douglas Gregor577f75a2009-08-04 16:50:30 +00009512} // end namespace clang
9513
9514#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H