blob: 8d66acbaf2efe0ef5cda5e4737f8b9d2a77e510a [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,
David Blaikiea71f9d02011-09-22 02:34:54 +0000250 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000251 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000252 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000253 llvm::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
Douglas Gregoraa165f82011-01-03 19:04:46 +0000326 /// \brief Transform the given list of expressions.
327 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000328 /// This routine transforms a list of expressions by invoking
329 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregoraa165f82011-01-03 19:04:46 +0000330 /// support for variadic templates by expanding any pack expansions (if the
331 /// derived class permits such expansion) along the way. When pack expansions
332 /// are present, the number of outputs may not equal the number of inputs.
333 ///
334 /// \param Inputs The set of expressions to be transformed.
335 ///
336 /// \param NumInputs The number of expressions in \c Inputs.
337 ///
338 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier4a9d7952012-08-08 18:46:20 +0000339 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregoraa165f82011-01-03 19:04:46 +0000340 /// be.
341 ///
342 /// \param Outputs The transformed input expressions will be added to this
343 /// vector.
344 ///
345 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
346 /// due to transformation.
347 ///
348 /// \returns true if an error occurred, false otherwise.
349 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000350 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000351 bool *ArgChanged = 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000352
Douglas Gregor577f75a2009-08-04 16:50:30 +0000353 /// \brief Transform the given declaration, which is referenced from a type
354 /// or expression.
355 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000356 /// By default, acts as the identity function on declarations, unless the
357 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000358 /// may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000359 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregordfca6f52012-02-13 22:00:16 +0000360 llvm::DenseMap<Decl *, Decl *>::iterator Known
361 = TransformedLocalDecls.find(D);
362 if (Known != TransformedLocalDecls.end())
363 return Known->second;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000364
365 return D;
Douglas Gregordfca6f52012-02-13 22:00:16 +0000366 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000367
Chad Rosier4a9d7952012-08-08 18:46:20 +0000368 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregordfca6f52012-02-13 22:00:16 +0000369 /// place them on the new declaration.
370 ///
371 /// By default, this operation does nothing. Subclasses may override this
372 /// behavior to transform attributes.
373 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000374
Douglas Gregordfca6f52012-02-13 22:00:16 +0000375 /// \brief Note that a local declaration has been transformed by this
376 /// transformer.
377 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000378 /// Local declarations are typically transformed via a call to
Douglas Gregordfca6f52012-02-13 22:00:16 +0000379 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
380 /// the transformer itself has to transform the declarations. This routine
381 /// can be overridden by a subclass that keeps track of such mappings.
382 void transformedLocalDecl(Decl *Old, Decl *New) {
383 TransformedLocalDecls[Old] = New;
384 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000385
Douglas Gregor43959a92009-08-20 07:17:43 +0000386 /// \brief Transform the definition of the given declaration.
387 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000388 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000389 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000390 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
391 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000392 }
Mike Stump1eb44332009-09-09 15:08:12 +0000393
Douglas Gregor6cd21982009-10-20 05:58:46 +0000394 /// \brief Transform the given declaration, which was the first part of a
395 /// nested-name-specifier in a member access expression.
396 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000397 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000398 /// identifier in a nested-name-specifier of a member access expression, e.g.,
399 /// the \c T in \c x->T::member
400 ///
401 /// By default, invokes TransformDecl() to transform the declaration.
402 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000403 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
404 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000405 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000406
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000407 /// \brief Transform the given nested-name-specifier with source-location
408 /// information.
409 ///
410 /// By default, transforms all of the types and declarations within the
411 /// nested-name-specifier. Subclasses may override this function to provide
412 /// alternate behavior.
413 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
414 NestedNameSpecifierLoc NNS,
415 QualType ObjectType = QualType(),
416 NamedDecl *FirstQualifierInScope = 0);
417
Douglas Gregor81499bb2009-09-03 22:13:48 +0000418 /// \brief Transform the given declaration name.
419 ///
420 /// By default, transforms the types of conversion function, constructor,
421 /// and destructor names and then (if needed) rebuilds the declaration name.
422 /// Identifiers and selectors are returned unmodified. Sublcasses may
423 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000424 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000425 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000426
Douglas Gregor577f75a2009-08-04 16:50:30 +0000427 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000428 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000429 /// \param SS The nested-name-specifier that qualifies the template
430 /// name. This nested-name-specifier must already have been transformed.
431 ///
432 /// \param Name The template name to transform.
433 ///
434 /// \param NameLoc The source location of the template name.
435 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000436 /// \param ObjectType If we're translating a template name within a member
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000437 /// access expression, this is the type of the object whose member template
438 /// is being referenced.
439 ///
440 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
441 /// also refers to a name within the current (lexical) scope, this is the
442 /// declaration it refers to.
443 ///
444 /// By default, transforms the template name by transforming the declarations
445 /// and nested-name-specifiers that occur within the template name.
446 /// Subclasses may override this function to provide alternate behavior.
447 TemplateName TransformTemplateName(CXXScopeSpec &SS,
448 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000449 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000450 QualType ObjectType = QualType(),
451 NamedDecl *FirstQualifierInScope = 0);
452
Douglas Gregor577f75a2009-08-04 16:50:30 +0000453 /// \brief Transform the given template argument.
454 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000455 /// By default, this operation transforms the type, expression, or
456 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000457 /// new template argument from the transformed result. Subclasses may
458 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000459 ///
460 /// Returns true if there was an error.
461 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
462 TemplateArgumentLoc &Output);
463
Douglas Gregorfcc12532010-12-20 17:31:10 +0000464 /// \brief Transform the given set of template arguments.
465 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000466 /// By default, this operation transforms all of the template arguments
Douglas Gregorfcc12532010-12-20 17:31:10 +0000467 /// in the input set using \c TransformTemplateArgument(), and appends
468 /// the transformed arguments to the output list.
469 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000470 /// Note that this overload of \c TransformTemplateArguments() is merely
471 /// a convenience function. Subclasses that wish to override this behavior
472 /// should override the iterator-based member template version.
473 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000474 /// \param Inputs The set of template arguments to be transformed.
475 ///
476 /// \param NumInputs The number of template arguments in \p Inputs.
477 ///
478 /// \param Outputs The set of transformed template arguments output by this
479 /// routine.
480 ///
481 /// Returns true if an error occurred.
482 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
483 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000484 TemplateArgumentListInfo &Outputs) {
485 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
486 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000487
488 /// \brief Transform the given set of template arguments.
489 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000490 /// By default, this operation transforms all of the template arguments
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000491 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier4a9d7952012-08-08 18:46:20 +0000492 /// the transformed arguments to the output list.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000493 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000494 /// \param First An iterator to the first template argument.
495 ///
496 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000497 ///
498 /// \param Outputs The set of transformed template arguments output by this
499 /// routine.
500 ///
501 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000502 template<typename InputIterator>
503 bool TransformTemplateArguments(InputIterator First,
504 InputIterator Last,
505 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000506
John McCall833ca992009-10-29 08:12:44 +0000507 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
508 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
509 TemplateArgumentLoc &ArgLoc);
510
John McCalla93c9342009-12-07 02:54:59 +0000511 /// \brief Fakes up a TypeSourceInfo for a type.
512 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
513 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000514 getDerived().getBaseLocation());
515 }
Mike Stump1eb44332009-09-09 15:08:12 +0000516
John McCalla2becad2009-10-21 00:40:46 +0000517#define ABSTRACT_TYPELOC(CLASS, PARENT)
518#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000519 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000520#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000521
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000522 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
523 FunctionProtoTypeLoc TL,
524 CXXRecordDecl *ThisContext,
525 unsigned ThisTypeQuals);
526
John Wiegley28bbe4b2011-04-28 01:08:34 +0000527 StmtResult
528 TransformSEHHandler(Stmt *Handler);
529
Chad Rosier4a9d7952012-08-08 18:46:20 +0000530 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000531 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
532 TemplateSpecializationTypeLoc TL,
533 TemplateName Template);
534
Chad Rosier4a9d7952012-08-08 18:46:20 +0000535 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000536 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
537 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000538 TemplateName Template,
539 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000540
Chad Rosier4a9d7952012-08-08 18:46:20 +0000541 QualType
Douglas Gregora88f09f2011-02-28 17:23:35 +0000542 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000543 DependentTemplateSpecializationTypeLoc TL,
544 NestedNameSpecifierLoc QualifierLoc);
545
John McCall21ef0fa2010-03-11 09:03:00 +0000546 /// \brief Transforms the parameters of a function type into the
547 /// given vectors.
548 ///
549 /// The result vectors should be kept in sync; null entries in the
550 /// variables vector are acceptable.
551 ///
552 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000553 bool TransformFunctionTypeParams(SourceLocation Loc,
554 ParmVarDecl **Params, unsigned NumParams,
555 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000556 SmallVectorImpl<QualType> &PTypes,
557 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000558
559 /// \brief Transforms a single function-type parameter. Return null
560 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000561 ///
562 /// \param indexAdjustment - A number to add to the parameter's
563 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000564 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000565 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000566 llvm::Optional<unsigned> NumExpansions,
567 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000568
John McCall43fed0d2010-11-12 08:19:04 +0000569 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000570
John McCall60d7b3a2010-08-24 06:29:42 +0000571 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
572 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000573
Richard Smith612409e2012-07-25 03:56:55 +0000574 /// \brief Transform the captures and body of a lambda expression.
575 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
576
Richard Smithefeeccf2012-10-21 03:28:35 +0000577 ExprResult TransformAddressOfOperand(Expr *E);
578 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
579 bool IsAddressOfOperand);
580
Douglas Gregor43959a92009-08-20 07:17:43 +0000581#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000582 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000583#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000584 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000585#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000586#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000587
Douglas Gregor577f75a2009-08-04 16:50:30 +0000588 /// \brief Build a new pointer type given its pointee type.
589 ///
590 /// By default, performs semantic analysis when building the pointer type.
591 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000592 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000593
594 /// \brief Build a new block pointer type given its pointee type.
595 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000596 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000597 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000598 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000599
John McCall85737a72009-10-30 00:06:24 +0000600 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000601 ///
John McCall85737a72009-10-30 00:06:24 +0000602 /// By default, performs semantic analysis when building the
603 /// reference type. Subclasses may override this routine to provide
604 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000605 ///
John McCall85737a72009-10-30 00:06:24 +0000606 /// \param LValue whether the type was written with an lvalue sigil
607 /// or an rvalue sigil.
608 QualType RebuildReferenceType(QualType ReferentType,
609 bool LValue,
610 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000611
Douglas Gregor577f75a2009-08-04 16:50:30 +0000612 /// \brief Build a new member pointer type given the pointee type and the
613 /// class type it refers into.
614 ///
615 /// By default, performs semantic analysis when building the member pointer
616 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000617 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
618 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000619
Douglas Gregor577f75a2009-08-04 16:50:30 +0000620 /// \brief Build a new array type given the element type, size
621 /// modifier, size of the array (if known), size expression, and index type
622 /// qualifiers.
623 ///
624 /// By default, performs semantic analysis when building the array type.
625 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000626 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000627 QualType RebuildArrayType(QualType ElementType,
628 ArrayType::ArraySizeModifier SizeMod,
629 const llvm::APInt *Size,
630 Expr *SizeExpr,
631 unsigned IndexTypeQuals,
632 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000633
Douglas Gregor577f75a2009-08-04 16:50:30 +0000634 /// \brief Build a new constant array type given the element type, size
635 /// modifier, (known) size of the array, and index type qualifiers.
636 ///
637 /// By default, performs semantic analysis when building the array type.
638 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000639 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000640 ArrayType::ArraySizeModifier SizeMod,
641 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000642 unsigned IndexTypeQuals,
643 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000644
Douglas Gregor577f75a2009-08-04 16:50:30 +0000645 /// \brief Build a new incomplete array type given the element type, size
646 /// modifier, and index type qualifiers.
647 ///
648 /// By default, performs semantic analysis when building the array type.
649 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000650 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000651 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000652 unsigned IndexTypeQuals,
653 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000654
Mike Stump1eb44332009-09-09 15:08:12 +0000655 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000656 /// size modifier, size expression, and index type qualifiers.
657 ///
658 /// By default, performs semantic analysis when building the array type.
659 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000660 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000661 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000662 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663 unsigned IndexTypeQuals,
664 SourceRange BracketsRange);
665
Mike Stump1eb44332009-09-09 15:08:12 +0000666 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000667 /// size modifier, size expression, and index type qualifiers.
668 ///
669 /// By default, performs semantic analysis when building the array type.
670 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000671 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000672 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000673 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000674 unsigned IndexTypeQuals,
675 SourceRange BracketsRange);
676
677 /// \brief Build a new vector type given the element type and
678 /// number of elements.
679 ///
680 /// By default, performs semantic analysis when building the vector type.
681 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000682 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000683 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000684
Douglas Gregor577f75a2009-08-04 16:50:30 +0000685 /// \brief Build a new extended vector type given the element type and
686 /// number of elements.
687 ///
688 /// By default, performs semantic analysis when building the vector type.
689 /// Subclasses may override this routine to provide different behavior.
690 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
691 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000692
693 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000694 /// given the element type and number of elements.
695 ///
696 /// By default, performs semantic analysis when building the vector type.
697 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000698 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000699 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000700 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000701
Douglas Gregor577f75a2009-08-04 16:50:30 +0000702 /// \brief Build a new function type.
703 ///
704 /// By default, performs semantic analysis when building the function type.
705 /// Subclasses may override this routine to provide different behavior.
706 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000707 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000708 unsigned NumParamTypes,
Richard Smitheefb3d52012-02-10 09:58:53 +0000709 bool Variadic, bool HasTrailingReturn,
710 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000711 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000712 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000713
John McCalla2becad2009-10-21 00:40:46 +0000714 /// \brief Build a new unprototyped function type.
715 QualType RebuildFunctionNoProtoType(QualType ResultType);
716
John McCalled976492009-12-04 22:46:56 +0000717 /// \brief Rebuild an unresolved typename type, given the decl that
718 /// the UnresolvedUsingTypenameDecl was transformed to.
719 QualType RebuildUnresolvedUsingType(Decl *D);
720
Douglas Gregor577f75a2009-08-04 16:50:30 +0000721 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000722 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000723 return SemaRef.Context.getTypeDeclType(Typedef);
724 }
725
726 /// \brief Build a new class/struct/union type.
727 QualType RebuildRecordType(RecordDecl *Record) {
728 return SemaRef.Context.getTypeDeclType(Record);
729 }
730
731 /// \brief Build a new Enum type.
732 QualType RebuildEnumType(EnumDecl *Enum) {
733 return SemaRef.Context.getTypeDeclType(Enum);
734 }
John McCall7da24312009-09-05 00:15:47 +0000735
Mike Stump1eb44332009-09-09 15:08:12 +0000736 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000737 ///
738 /// By default, performs semantic analysis when building the typeof type.
739 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000740 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000741
Mike Stump1eb44332009-09-09 15:08:12 +0000742 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000743 ///
744 /// By default, builds a new TypeOfType with the given underlying type.
745 QualType RebuildTypeOfType(QualType Underlying);
746
Sean Huntca63c202011-05-24 22:41:36 +0000747 /// \brief Build a new unary transform type.
748 QualType RebuildUnaryTransformType(QualType BaseType,
749 UnaryTransformType::UTTKind UKind,
750 SourceLocation Loc);
751
Mike Stump1eb44332009-09-09 15:08:12 +0000752 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000753 ///
754 /// By default, performs semantic analysis when building the decltype type.
755 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000756 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000757
Richard Smith34b41d92011-02-20 03:19:35 +0000758 /// \brief Build a new C++0x auto type.
759 ///
760 /// By default, builds a new AutoType with the given deduced type.
761 QualType RebuildAutoType(QualType Deduced) {
762 return SemaRef.Context.getAutoType(Deduced);
763 }
764
Douglas Gregor577f75a2009-08-04 16:50:30 +0000765 /// \brief Build a new template specialization type.
766 ///
767 /// By default, performs semantic analysis when building the template
768 /// specialization type. Subclasses may override this routine to provide
769 /// different behavior.
770 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000771 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000772 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000773
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000774 /// \brief Build a new parenthesized type.
775 ///
776 /// By default, builds a new ParenType type from the inner type.
777 /// Subclasses may override this routine to provide different behavior.
778 QualType RebuildParenType(QualType InnerType) {
779 return SemaRef.Context.getParenType(InnerType);
780 }
781
Douglas Gregor577f75a2009-08-04 16:50:30 +0000782 /// \brief Build a new qualified name type.
783 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000784 /// By default, builds a new ElaboratedType type from the keyword,
785 /// the nested-name-specifier and the named type.
786 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000787 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
788 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000789 NestedNameSpecifierLoc QualifierLoc,
790 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000791 return SemaRef.Context.getElaboratedType(Keyword,
792 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000793 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000794 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000795
796 /// \brief Build a new typename type that refers to a template-id.
797 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000798 /// By default, builds a new DependentNameType type from the
799 /// nested-name-specifier and the given type. Subclasses may override
800 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000801 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000802 ElaboratedTypeKeyword Keyword,
803 NestedNameSpecifierLoc QualifierLoc,
804 const IdentifierInfo *Name,
805 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000806 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000807 // Rebuild the template name.
808 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000809 CXXScopeSpec SS;
810 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000811 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000812 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000813
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000814 if (InstName.isNull())
815 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000816
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000817 // If it's still dependent, make a dependent specialization.
818 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000819 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
820 QualifierLoc.getNestedNameSpecifier(),
821 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000822 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000823
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000824 // Otherwise, make an elaborated type wrapping a non-dependent
825 // specialization.
826 QualType T =
827 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
828 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000829
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000830 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
831 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000832
833 return SemaRef.Context.getElaboratedType(Keyword,
834 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000835 T);
836 }
837
Douglas Gregor577f75a2009-08-04 16:50:30 +0000838 /// \brief Build a new typename type that refers to an identifier.
839 ///
840 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000841 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000842 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000843 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000844 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000845 NestedNameSpecifierLoc QualifierLoc,
846 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000847 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000848 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000849 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000850
Douglas Gregor2494dd02011-03-01 01:34:45 +0000851 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000852 // If the name is still dependent, just build a new dependent name type.
853 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000854 return SemaRef.Context.getDependentNameType(Keyword,
855 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000856 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000857 }
858
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000859 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000860 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000861 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000862
863 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
864
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000865 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000866 // into a non-dependent elaborated-type-specifier. Find the tag we're
867 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000868 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000869 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
870 if (!DC)
871 return QualType();
872
John McCall56138762010-05-27 06:40:31 +0000873 if (SemaRef.RequireCompleteDeclContext(SS, DC))
874 return QualType();
875
Douglas Gregor40336422010-03-31 22:19:08 +0000876 TagDecl *Tag = 0;
877 SemaRef.LookupQualifiedName(Result, DC);
878 switch (Result.getResultKind()) {
879 case LookupResult::NotFound:
880 case LookupResult::NotFoundInCurrentInstantiation:
881 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000882
Douglas Gregor40336422010-03-31 22:19:08 +0000883 case LookupResult::Found:
884 Tag = Result.getAsSingle<TagDecl>();
885 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000886
Douglas Gregor40336422010-03-31 22:19:08 +0000887 case LookupResult::FoundOverloaded:
888 case LookupResult::FoundUnresolvedValue:
889 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000890
Douglas Gregor40336422010-03-31 22:19:08 +0000891 case LookupResult::Ambiguous:
892 // Let the LookupResult structure handle ambiguities.
893 return QualType();
894 }
895
896 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000897 // Check where the name exists but isn't a tag type and use that to emit
898 // better diagnostics.
899 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
900 SemaRef.LookupQualifiedName(Result, DC);
901 switch (Result.getResultKind()) {
902 case LookupResult::Found:
903 case LookupResult::FoundOverloaded:
904 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000905 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000906 unsigned Kind = 0;
907 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000908 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
909 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000910 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
911 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
912 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000913 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000914 default:
915 // FIXME: Would be nice to highlight just the source range.
916 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
917 << Kind << Id << DC;
918 break;
919 }
Douglas Gregor40336422010-03-31 22:19:08 +0000920 return QualType();
921 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000922
Richard Trieubbf34c02011-06-10 03:11:26 +0000923 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
924 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000925 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000926 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
927 return QualType();
928 }
929
930 // Build the elaborated-type-specifier type.
931 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000932 return SemaRef.Context.getElaboratedType(Keyword,
933 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000934 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000935 }
Mike Stump1eb44332009-09-09 15:08:12 +0000936
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000937 /// \brief Build a new pack expansion type.
938 ///
939 /// By default, builds a new PackExpansionType type from the given pattern.
940 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000941 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000942 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000943 SourceLocation EllipsisLoc,
944 llvm::Optional<unsigned> NumExpansions) {
945 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
946 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000947 }
948
Eli Friedmanb001de72011-10-06 23:00:33 +0000949 /// \brief Build a new atomic type given its value type.
950 ///
951 /// By default, performs semantic analysis when building the atomic type.
952 /// Subclasses may override this routine to provide different behavior.
953 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
954
Douglas Gregord1067e52009-08-06 06:41:21 +0000955 /// \brief Build a new template name given a nested name specifier, a flag
956 /// indicating whether the "template" keyword was provided, and the template
957 /// that the template name refers to.
958 ///
959 /// By default, builds the new template name directly. Subclasses may override
960 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000961 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000962 bool TemplateKW,
963 TemplateDecl *Template);
964
Douglas Gregord1067e52009-08-06 06:41:21 +0000965 /// \brief Build a new template name given a nested name specifier and the
966 /// name that is referred to as a template.
967 ///
968 /// By default, performs semantic analysis to determine whether the name can
969 /// be resolved to a specific template, then builds the appropriate kind of
970 /// template name. Subclasses may override this routine to provide different
971 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000972 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
973 const IdentifierInfo &Name,
974 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000975 QualType ObjectType,
976 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000977
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000978 /// \brief Build a new template name given a nested name specifier and the
979 /// overloaded operator name that is referred to as a template.
980 ///
981 /// By default, performs semantic analysis to determine whether the name can
982 /// be resolved to a specific template, then builds the appropriate kind of
983 /// template name. Subclasses may override this routine to provide different
984 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000985 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000986 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000987 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000988 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000989
990 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +0000991 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000992 ///
993 /// By default, performs semantic analysis to determine whether the name can
994 /// be resolved to a specific template, then builds the appropriate kind of
995 /// template name. Subclasses may override this routine to provide different
996 /// behavior.
997 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
998 const TemplateArgument &ArgPack) {
999 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1000 }
1001
Douglas Gregor43959a92009-08-20 07:17:43 +00001002 /// \brief Build a new compound statement.
1003 ///
1004 /// By default, performs semantic analysis to build the new statement.
1005 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001006 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001007 MultiStmtArg Statements,
1008 SourceLocation RBraceLoc,
1009 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001010 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001011 IsStmtExpr);
1012 }
1013
1014 /// \brief Build a new case statement.
1015 ///
1016 /// By default, performs semantic analysis to build the new statement.
1017 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001018 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001019 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001020 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001021 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001022 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001023 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001024 ColonLoc);
1025 }
Mike Stump1eb44332009-09-09 15:08:12 +00001026
Douglas Gregor43959a92009-08-20 07:17:43 +00001027 /// \brief Attach the body to a new case statement.
1028 ///
1029 /// By default, performs semantic analysis to build the new statement.
1030 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001031 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001032 getSema().ActOnCaseStmtBody(S, Body);
1033 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001034 }
Mike Stump1eb44332009-09-09 15:08:12 +00001035
Douglas Gregor43959a92009-08-20 07:17:43 +00001036 /// \brief Build a new default statement.
1037 ///
1038 /// By default, performs semantic analysis to build the new statement.
1039 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001040 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001041 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001042 Stmt *SubStmt) {
1043 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001044 /*CurScope=*/0);
1045 }
Mike Stump1eb44332009-09-09 15:08:12 +00001046
Douglas Gregor43959a92009-08-20 07:17:43 +00001047 /// \brief Build a new label statement.
1048 ///
1049 /// By default, performs semantic analysis to build the new statement.
1050 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001051 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1052 SourceLocation ColonLoc, Stmt *SubStmt) {
1053 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001054 }
Mike Stump1eb44332009-09-09 15:08:12 +00001055
Richard Smith534986f2012-04-14 00:33:13 +00001056 /// \brief Build a new label statement.
1057 ///
1058 /// By default, performs semantic analysis to build the new statement.
1059 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001060 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1061 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001062 Stmt *SubStmt) {
1063 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1064 }
1065
Douglas Gregor43959a92009-08-20 07:17:43 +00001066 /// \brief Build a new "if" statement.
1067 ///
1068 /// By default, performs semantic analysis to build the new statement.
1069 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001070 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001071 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001072 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001073 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001074 }
Mike Stump1eb44332009-09-09 15:08:12 +00001075
Douglas Gregor43959a92009-08-20 07:17:43 +00001076 /// \brief Start building a new switch statement.
1077 ///
1078 /// By default, performs semantic analysis to build the new statement.
1079 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001080 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001081 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001082 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001083 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001084 }
Mike Stump1eb44332009-09-09 15:08:12 +00001085
Douglas Gregor43959a92009-08-20 07:17:43 +00001086 /// \brief Attach the body to the switch statement.
1087 ///
1088 /// By default, performs semantic analysis to build the new statement.
1089 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001090 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001091 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001092 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001093 }
1094
1095 /// \brief Build a new while statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001099 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1100 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001101 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001102 }
Mike Stump1eb44332009-09-09 15:08:12 +00001103
Douglas Gregor43959a92009-08-20 07:17:43 +00001104 /// \brief Build a new do-while statement.
1105 ///
1106 /// By default, performs semantic analysis to build the new statement.
1107 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001108 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001109 SourceLocation WhileLoc, SourceLocation LParenLoc,
1110 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001111 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1112 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001113 }
1114
1115 /// \brief Build a new for statement.
1116 ///
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001119 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001120 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001121 VarDecl *CondVar, Sema::FullExprArg Inc,
1122 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001123 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001124 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001125 }
Mike Stump1eb44332009-09-09 15:08:12 +00001126
Douglas Gregor43959a92009-08-20 07:17:43 +00001127 /// \brief Build a new goto statement.
1128 ///
1129 /// By default, performs semantic analysis to build the new statement.
1130 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001131 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1132 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001133 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001134 }
1135
1136 /// \brief Build a new indirect goto statement.
1137 ///
1138 /// By default, performs semantic analysis to build the new statement.
1139 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001140 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001141 SourceLocation StarLoc,
1142 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001143 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001144 }
Mike Stump1eb44332009-09-09 15:08:12 +00001145
Douglas Gregor43959a92009-08-20 07:17:43 +00001146 /// \brief Build a new return statement.
1147 ///
1148 /// By default, performs semantic analysis to build the new statement.
1149 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001150 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001151 return getSema().ActOnReturnStmt(ReturnLoc, Result);
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 declaration statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001158 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001159 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001160 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001161 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1162 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001163 }
Mike Stump1eb44332009-09-09 15:08:12 +00001164
Anders Carlsson703e3942010-01-24 05:50:09 +00001165 /// \brief Build a new inline asm statement.
1166 ///
1167 /// By default, performs semantic analysis to build the new statement.
1168 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001169 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1170 bool IsVolatile, unsigned NumOutputs,
1171 unsigned NumInputs, IdentifierInfo **Names,
1172 MultiExprArg Constraints, MultiExprArg Exprs,
1173 Expr *AsmString, MultiExprArg Clobbers,
1174 SourceLocation RParenLoc) {
1175 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1176 NumInputs, Names, Constraints, Exprs,
1177 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001178 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001179
Chad Rosier8cd64b42012-06-11 20:47:18 +00001180 /// \brief Build a new MS style inline asm statement.
1181 ///
1182 /// By default, performs semantic analysis to build the new statement.
1183 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001184 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
1185 ArrayRef<Token> AsmToks, SourceLocation EndLoc) {
Chad Rosier7bd092b2012-08-15 16:53:30 +00001186 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001187 }
1188
James Dennett699c9042012-06-15 07:13:21 +00001189 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001190 ///
1191 /// By default, performs semantic analysis to build the new statement.
1192 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001193 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001194 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001195 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001196 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001197 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001198 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001199 }
1200
Douglas Gregorbe270a02010-04-26 17:57:08 +00001201 /// \brief Rebuild an Objective-C exception declaration.
1202 ///
1203 /// By default, performs semantic analysis to build the new declaration.
1204 /// Subclasses may override this routine to provide different behavior.
1205 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1206 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001207 return getSema().BuildObjCExceptionDecl(TInfo, T,
1208 ExceptionDecl->getInnerLocStart(),
1209 ExceptionDecl->getLocation(),
1210 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001211 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001212
James Dennett699c9042012-06-15 07:13:21 +00001213 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001214 ///
1215 /// By default, performs semantic analysis to build the new statement.
1216 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001217 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001218 SourceLocation RParenLoc,
1219 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001220 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001221 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001222 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001223 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001224
James Dennett699c9042012-06-15 07:13:21 +00001225 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001226 ///
1227 /// By default, performs semantic analysis to build the new statement.
1228 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001229 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001230 Stmt *Body) {
1231 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001232 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001233
James Dennett699c9042012-06-15 07:13:21 +00001234 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001235 ///
1236 /// By default, performs semantic analysis to build the new statement.
1237 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001238 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001239 Expr *Operand) {
1240 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001241 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001242
James Dennett699c9042012-06-15 07:13:21 +00001243 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001244 ///
1245 /// By default, performs semantic analysis to build the new statement.
1246 /// Subclasses may override this routine to provide different behavior.
1247 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1248 Expr *object) {
1249 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1250 }
1251
James Dennett699c9042012-06-15 07:13:21 +00001252 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001253 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001254 /// By default, performs semantic analysis to build the new statement.
1255 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001256 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001257 Expr *Object, Stmt *Body) {
1258 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001259 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001260
James Dennett699c9042012-06-15 07:13:21 +00001261 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001262 ///
1263 /// By default, performs semantic analysis to build the new statement.
1264 /// Subclasses may override this routine to provide different behavior.
1265 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1266 Stmt *Body) {
1267 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1268 }
John McCall990567c2011-07-27 01:07:15 +00001269
Douglas Gregorc3203e72010-04-22 23:10:45 +00001270 /// \brief Build a new Objective-C fast enumeration statement.
1271 ///
1272 /// By default, performs semantic analysis to build the new statement.
1273 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001274 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001275 Stmt *Element,
1276 Expr *Collection,
1277 SourceLocation RParenLoc,
1278 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001279 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001280 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001281 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001282 RParenLoc);
1283 if (ForEachStmt.isInvalid())
1284 return StmtError();
1285
1286 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001287 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001288
Douglas Gregor43959a92009-08-20 07:17:43 +00001289 /// \brief Build a new C++ exception declaration.
1290 ///
1291 /// By default, performs semantic analysis to build the new decaration.
1292 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001293 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001294 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001295 SourceLocation StartLoc,
1296 SourceLocation IdLoc,
1297 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001298 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1299 StartLoc, IdLoc, Id);
1300 if (Var)
1301 getSema().CurContext->addDecl(Var);
1302 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001303 }
1304
1305 /// \brief Build a new C++ catch statement.
1306 ///
1307 /// By default, performs semantic analysis to build the new statement.
1308 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001309 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001310 VarDecl *ExceptionDecl,
1311 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001312 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1313 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001314 }
Mike Stump1eb44332009-09-09 15:08:12 +00001315
Douglas Gregor43959a92009-08-20 07:17:43 +00001316 /// \brief Build a new C++ try statement.
1317 ///
1318 /// By default, performs semantic analysis to build the new statement.
1319 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001320 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001321 Stmt *TryBlock,
1322 MultiStmtArg Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001323 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001324 }
Mike Stump1eb44332009-09-09 15:08:12 +00001325
Richard Smithad762fc2011-04-14 22:09:26 +00001326 /// \brief Build a new C++0x range-based for statement.
1327 ///
1328 /// By default, performs semantic analysis to build the new statement.
1329 /// Subclasses may override this routine to provide different behavior.
1330 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1331 SourceLocation ColonLoc,
1332 Stmt *Range, Stmt *BeginEnd,
1333 Expr *Cond, Expr *Inc,
1334 Stmt *LoopVar,
1335 SourceLocation RParenLoc) {
1336 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001337 Cond, Inc, LoopVar, RParenLoc,
1338 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001339 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001340
1341 /// \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.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001345 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001346 bool IsIfExists,
1347 NestedNameSpecifierLoc QualifierLoc,
1348 DeclarationNameInfo NameInfo,
1349 Stmt *Nested) {
1350 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1351 QualifierLoc, NameInfo, Nested);
1352 }
1353
Richard Smithad762fc2011-04-14 22:09:26 +00001354 /// \brief Attach body to a C++0x range-based for statement.
1355 ///
1356 /// By default, performs semantic analysis to finish the new statement.
1357 /// Subclasses may override this routine to provide different behavior.
1358 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1359 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1360 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001361
John Wiegley28bbe4b2011-04-28 01:08:34 +00001362 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1363 SourceLocation TryLoc,
1364 Stmt *TryBlock,
1365 Stmt *Handler) {
1366 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1367 }
1368
1369 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1370 Expr *FilterExpr,
1371 Stmt *Block) {
1372 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1373 }
1374
1375 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1376 Stmt *Block) {
1377 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1378 }
1379
Douglas Gregorb98b1992009-08-11 05:31:07 +00001380 /// \brief Build a new expression that references a declaration.
1381 ///
1382 /// By default, performs semantic analysis to build the new expression.
1383 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001384 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001385 LookupResult &R,
1386 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001387 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1388 }
1389
1390
1391 /// \brief Build a new expression that references a declaration.
1392 ///
1393 /// By default, performs semantic analysis to build the new expression.
1394 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001395 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001396 ValueDecl *VD,
1397 const DeclarationNameInfo &NameInfo,
1398 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001399 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001400 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001401
1402 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001403
1404 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001405 }
Mike Stump1eb44332009-09-09 15:08:12 +00001406
Douglas Gregorb98b1992009-08-11 05:31:07 +00001407 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001408 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 /// By default, performs semantic analysis to build the new expression.
1410 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001411 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001412 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001413 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001414 }
1415
Douglas Gregora71d8192009-09-04 17:36:40 +00001416 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001417 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001418 /// By default, performs semantic analysis to build the new expression.
1419 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001420 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001421 SourceLocation OperatorLoc,
1422 bool isArrow,
1423 CXXScopeSpec &SS,
1424 TypeSourceInfo *ScopeType,
1425 SourceLocation CCLoc,
1426 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001427 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001428
Douglas Gregorb98b1992009-08-11 05:31:07 +00001429 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001430 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001431 /// By default, performs semantic analysis to build the new expression.
1432 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001433 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001434 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001435 Expr *SubExpr) {
1436 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001437 }
Mike Stump1eb44332009-09-09 15:08:12 +00001438
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001439 /// \brief Build a new builtin offsetof expression.
1440 ///
1441 /// 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 RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001444 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001445 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001446 unsigned NumComponents,
1447 SourceLocation RParenLoc) {
1448 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1449 NumComponents, RParenLoc);
1450 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001451
1452 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001453 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001454 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001455 /// By default, performs semantic analysis to build the new expression.
1456 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001457 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1458 SourceLocation OpLoc,
1459 UnaryExprOrTypeTrait ExprKind,
1460 SourceRange R) {
1461 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001462 }
1463
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001464 /// \brief Build a new sizeof, alignof or vec step expression with an
1465 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001466 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001467 /// By default, performs semantic analysis to build the new expression.
1468 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001469 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1470 UnaryExprOrTypeTrait ExprKind,
1471 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001472 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001473 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001474 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001475 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001476
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001477 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001478 }
Mike Stump1eb44332009-09-09 15:08:12 +00001479
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001481 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001482 /// By default, performs semantic analysis to build the new expression.
1483 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001484 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001485 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001486 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001487 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001488 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1489 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 RBracketLoc);
1491 }
1492
1493 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001494 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 /// By default, performs semantic analysis to build the new expression.
1496 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001497 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001499 SourceLocation RParenLoc,
1500 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001501 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001502 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001503 }
1504
1505 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001506 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 /// By default, performs semantic analysis to build the new expression.
1508 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001509 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001510 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001511 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001512 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001513 const DeclarationNameInfo &MemberNameInfo,
1514 ValueDecl *Member,
1515 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001516 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001517 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001518 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1519 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001520 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001521 // We have a reference to an unnamed field. This is always the
1522 // base of an anonymous struct/union member access, i.e. the
1523 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001524 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001525 assert(Member->getType()->isRecordType() &&
1526 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001527
Richard Smith9138b4e2011-10-26 19:06:56 +00001528 BaseResult =
1529 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001530 QualifierLoc.getNestedNameSpecifier(),
1531 FoundDecl, Member);
1532 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001533 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001534 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001535 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001536 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001537 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001538 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001539 cast<FieldDecl>(Member)->getType(),
1540 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001541 return getSema().Owned(ME);
1542 }
Mike Stump1eb44332009-09-09 15:08:12 +00001543
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001544 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001545 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001546
John Wiegley429bb272011-04-08 18:41:53 +00001547 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001548 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001549
John McCall6bb80172010-03-30 21:47:33 +00001550 // FIXME: this involves duplicating earlier analysis in a lot of
1551 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001552 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001553 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001554 R.resolveKind();
1555
John McCall9ae2f072010-08-23 23:25:46 +00001556 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001557 SS, TemplateKWLoc,
1558 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001559 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001560 }
Mike Stump1eb44332009-09-09 15:08:12 +00001561
Douglas Gregorb98b1992009-08-11 05:31:07 +00001562 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001563 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001564 /// By default, performs semantic analysis to build the new expression.
1565 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001566 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001567 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001568 Expr *LHS, Expr *RHS) {
1569 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001570 }
1571
1572 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001573 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001574 /// By default, performs semantic analysis to build the new expression.
1575 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001576 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001577 SourceLocation QuestionLoc,
1578 Expr *LHS,
1579 SourceLocation ColonLoc,
1580 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001581 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1582 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001583 }
1584
Douglas Gregorb98b1992009-08-11 05:31:07 +00001585 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001586 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001587 /// By default, performs semantic analysis to build the new expression.
1588 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001589 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001590 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001591 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001592 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001593 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001594 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 }
Mike Stump1eb44332009-09-09 15:08:12 +00001596
Douglas Gregorb98b1992009-08-11 05:31:07 +00001597 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001598 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 /// By default, performs semantic analysis to build the new expression.
1600 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001601 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001602 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001604 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001605 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001606 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001607 }
Mike Stump1eb44332009-09-09 15:08:12 +00001608
Douglas Gregorb98b1992009-08-11 05:31:07 +00001609 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001610 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001611 /// By default, performs semantic analysis to build the new expression.
1612 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001613 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 SourceLocation OpLoc,
1615 SourceLocation AccessorLoc,
1616 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001617
John McCall129e2df2009-11-30 22:42:35 +00001618 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001619 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001620 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001621 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001622 SS, SourceLocation(),
1623 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001624 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001625 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001626 }
Mike Stump1eb44332009-09-09 15:08:12 +00001627
Douglas Gregorb98b1992009-08-11 05:31:07 +00001628 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001629 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001630 /// By default, performs semantic analysis to build the new expression.
1631 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001632 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001633 MultiExprArg Inits,
1634 SourceLocation RBraceLoc,
1635 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001636 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001637 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001638 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001639 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001640
Douglas Gregore48319a2009-11-09 17:16:50 +00001641 // Patch in the result type we were given, which may have been computed
1642 // when the initial InitListExpr was built.
1643 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1644 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001645 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 }
Mike Stump1eb44332009-09-09 15:08:12 +00001647
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001649 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001650 /// By default, performs semantic analysis to build the new expression.
1651 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001652 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 MultiExprArg ArrayExprs,
1654 SourceLocation EqualOrColonLoc,
1655 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001656 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001657 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001659 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001660 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001661 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001662
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001663 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 }
Mike Stump1eb44332009-09-09 15:08:12 +00001665
Douglas Gregorb98b1992009-08-11 05:31:07 +00001666 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001667 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 /// By default, builds the implicit value initialization without performing
1669 /// any semantic analysis. Subclasses may override this routine to provide
1670 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001671 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001672 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1673 }
Mike Stump1eb44332009-09-09 15:08:12 +00001674
Douglas Gregorb98b1992009-08-11 05:31:07 +00001675 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001676 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001677 /// By default, performs semantic analysis to build the new expression.
1678 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001679 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001680 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001681 SourceLocation RParenLoc) {
1682 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001683 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001684 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001685 }
1686
1687 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001688 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001689 /// By default, performs semantic analysis to build the new expression.
1690 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001691 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001692 MultiExprArg SubExprs,
1693 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001694 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001695 }
Mike Stump1eb44332009-09-09 15:08:12 +00001696
Douglas Gregorb98b1992009-08-11 05:31:07 +00001697 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001698 ///
1699 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 /// rather than attempting to map the label statement itself.
1701 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001702 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001703 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001704 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001705 }
Mike Stump1eb44332009-09-09 15:08:12 +00001706
Douglas Gregorb98b1992009-08-11 05:31:07 +00001707 /// \brief Build a new GNU statement 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 RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001712 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001714 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001715 }
Mike Stump1eb44332009-09-09 15:08:12 +00001716
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717 /// \brief Build a new __builtin_choose_expr expression.
1718 ///
1719 /// By default, performs semantic analysis to build the new expression.
1720 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001721 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001722 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001723 SourceLocation RParenLoc) {
1724 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001725 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001726 RParenLoc);
1727 }
Mike Stump1eb44332009-09-09 15:08:12 +00001728
Peter Collingbournef111d932011-04-15 00:35:48 +00001729 /// \brief Build a new generic selection expression.
1730 ///
1731 /// By default, performs semantic analysis to build the new expression.
1732 /// Subclasses may override this routine to provide different behavior.
1733 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1734 SourceLocation DefaultLoc,
1735 SourceLocation RParenLoc,
1736 Expr *ControllingExpr,
1737 TypeSourceInfo **Types,
1738 Expr **Exprs,
1739 unsigned NumAssocs) {
1740 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1741 ControllingExpr, Types, Exprs,
1742 NumAssocs);
1743 }
1744
Douglas Gregorb98b1992009-08-11 05:31:07 +00001745 /// \brief Build a new overloaded operator call expression.
1746 ///
1747 /// By default, performs semantic analysis to build the new expression.
1748 /// The semantic analysis provides the behavior of template instantiation,
1749 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001750 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001751 /// argument-dependent lookup, etc. Subclasses may override this routine to
1752 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001753 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001754 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001755 Expr *Callee,
1756 Expr *First,
1757 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001758
1759 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001760 /// reinterpret_cast.
1761 ///
1762 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001763 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001764 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001765 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001766 Stmt::StmtClass Class,
1767 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001768 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001769 SourceLocation RAngleLoc,
1770 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001771 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001772 SourceLocation RParenLoc) {
1773 switch (Class) {
1774 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001775 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001776 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001777 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001778
1779 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001780 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001781 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001782 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001783
Douglas Gregorb98b1992009-08-11 05:31:07 +00001784 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001785 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001786 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001787 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001788 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001789
Douglas Gregorb98b1992009-08-11 05:31:07 +00001790 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001791 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001792 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001793 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001794
Douglas Gregorb98b1992009-08-11 05:31:07 +00001795 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001796 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001798 }
Mike Stump1eb44332009-09-09 15:08:12 +00001799
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800 /// \brief Build a new C++ static_cast expression.
1801 ///
1802 /// By default, performs semantic analysis to build the new expression.
1803 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001804 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001805 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001806 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001807 SourceLocation RAngleLoc,
1808 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001809 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001810 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001811 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001812 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001813 SourceRange(LAngleLoc, RAngleLoc),
1814 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001815 }
1816
1817 /// \brief Build a new C++ dynamic_cast expression.
1818 ///
1819 /// By default, performs semantic analysis to build the new expression.
1820 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001821 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001822 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001823 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001824 SourceLocation RAngleLoc,
1825 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001826 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001827 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001828 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001829 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001830 SourceRange(LAngleLoc, RAngleLoc),
1831 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001832 }
1833
1834 /// \brief Build a new C++ reinterpret_cast expression.
1835 ///
1836 /// By default, performs semantic analysis to build the new expression.
1837 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001838 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001839 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001840 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001841 SourceLocation RAngleLoc,
1842 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001843 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001844 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001845 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001846 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001847 SourceRange(LAngleLoc, RAngleLoc),
1848 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001849 }
1850
1851 /// \brief Build a new C++ const_cast expression.
1852 ///
1853 /// By default, performs semantic analysis to build the new expression.
1854 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001855 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001856 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001857 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001858 SourceLocation RAngleLoc,
1859 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001860 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001861 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001862 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001863 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001864 SourceRange(LAngleLoc, RAngleLoc),
1865 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001866 }
Mike Stump1eb44332009-09-09 15:08:12 +00001867
Douglas Gregorb98b1992009-08-11 05:31:07 +00001868 /// \brief Build a new C++ functional-style cast expression.
1869 ///
1870 /// By default, performs semantic analysis to build the new expression.
1871 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001872 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1873 SourceLocation LParenLoc,
1874 Expr *Sub,
1875 SourceLocation RParenLoc) {
1876 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001877 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001878 RParenLoc);
1879 }
Mike Stump1eb44332009-09-09 15:08:12 +00001880
Douglas Gregorb98b1992009-08-11 05:31:07 +00001881 /// \brief Build a new C++ typeid(type) 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 RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001886 SourceLocation TypeidLoc,
1887 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001888 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001889 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001890 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001891 }
Mike Stump1eb44332009-09-09 15:08:12 +00001892
Francois Pichet01b7c302010-09-08 12:20:18 +00001893
Douglas Gregorb98b1992009-08-11 05:31:07 +00001894 /// \brief Build a new C++ typeid(expr) expression.
1895 ///
1896 /// By default, performs semantic analysis to build the new expression.
1897 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001898 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001899 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001900 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001901 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001902 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001903 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001904 }
1905
Francois Pichet01b7c302010-09-08 12:20:18 +00001906 /// \brief Build a new C++ __uuidof(type) expression.
1907 ///
1908 /// By default, performs semantic analysis to build the new expression.
1909 /// Subclasses may override this routine to provide different behavior.
1910 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1911 SourceLocation TypeidLoc,
1912 TypeSourceInfo *Operand,
1913 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001914 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001915 RParenLoc);
1916 }
1917
1918 /// \brief Build a new C++ __uuidof(expr) expression.
1919 ///
1920 /// By default, performs semantic analysis to build the new expression.
1921 /// Subclasses may override this routine to provide different behavior.
1922 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1923 SourceLocation TypeidLoc,
1924 Expr *Operand,
1925 SourceLocation RParenLoc) {
1926 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1927 RParenLoc);
1928 }
1929
Douglas Gregorb98b1992009-08-11 05:31:07 +00001930 /// \brief Build a new C++ "this" expression.
1931 ///
1932 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001933 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001934 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001935 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001936 QualType ThisType,
1937 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001938 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001939 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001940 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1941 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001942 }
1943
1944 /// \brief Build a new C++ throw expression.
1945 ///
1946 /// By default, performs semantic analysis to build the new expression.
1947 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001948 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1949 bool IsThrownVariableInScope) {
1950 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001951 }
1952
1953 /// \brief Build a new C++ default-argument expression.
1954 ///
1955 /// By default, builds a new default-argument expression, which does not
1956 /// require any semantic analysis. Subclasses may override this routine to
1957 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001958 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001959 ParmVarDecl *Param) {
1960 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1961 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001962 }
1963
1964 /// \brief Build a new C++ zero-initialization expression.
1965 ///
1966 /// By default, performs semantic analysis to build the new expression.
1967 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001968 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1969 SourceLocation LParenLoc,
1970 SourceLocation RParenLoc) {
1971 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Benjamin Kramer5354e772012-08-23 23:38:35 +00001972 MultiExprArg(), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001973 }
Mike Stump1eb44332009-09-09 15:08:12 +00001974
Douglas Gregorb98b1992009-08-11 05:31:07 +00001975 /// \brief Build a new C++ "new" expression.
1976 ///
1977 /// By default, performs semantic analysis to build the new expression.
1978 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001979 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001980 bool UseGlobal,
1981 SourceLocation PlacementLParen,
1982 MultiExprArg PlacementArgs,
1983 SourceLocation PlacementRParen,
1984 SourceRange TypeIdParens,
1985 QualType AllocatedType,
1986 TypeSourceInfo *AllocatedTypeInfo,
1987 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001988 SourceRange DirectInitRange,
1989 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001990 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001991 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001992 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001993 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001994 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001995 AllocatedType,
1996 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001997 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001998 DirectInitRange,
1999 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002000 }
Mike Stump1eb44332009-09-09 15:08:12 +00002001
Douglas Gregorb98b1992009-08-11 05:31:07 +00002002 /// \brief Build a new C++ "delete" expression.
2003 ///
2004 /// By default, performs semantic analysis to build the new expression.
2005 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002006 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002007 bool IsGlobalDelete,
2008 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002009 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002010 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002011 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002012 }
Mike Stump1eb44332009-09-09 15:08:12 +00002013
Douglas Gregorb98b1992009-08-11 05:31:07 +00002014 /// \brief Build a new unary type trait expression.
2015 ///
2016 /// By default, performs semantic analysis to build the new expression.
2017 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002018 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002019 SourceLocation StartLoc,
2020 TypeSourceInfo *T,
2021 SourceLocation RParenLoc) {
2022 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002023 }
2024
Francois Pichet6ad6f282010-12-07 00:08:36 +00002025 /// \brief Build a new binary type trait expression.
2026 ///
2027 /// By default, performs semantic analysis to build the new expression.
2028 /// Subclasses may override this routine to provide different behavior.
2029 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2030 SourceLocation StartLoc,
2031 TypeSourceInfo *LhsT,
2032 TypeSourceInfo *RhsT,
2033 SourceLocation RParenLoc) {
2034 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2035 }
2036
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002037 /// \brief Build a new type trait expression.
2038 ///
2039 /// By default, performs semantic analysis to build the new expression.
2040 /// Subclasses may override this routine to provide different behavior.
2041 ExprResult RebuildTypeTrait(TypeTrait Trait,
2042 SourceLocation StartLoc,
2043 ArrayRef<TypeSourceInfo *> Args,
2044 SourceLocation RParenLoc) {
2045 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2046 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002047
John Wiegley21ff2e52011-04-28 00:16:57 +00002048 /// \brief Build a new array type trait expression.
2049 ///
2050 /// By default, performs semantic analysis to build the new expression.
2051 /// Subclasses may override this routine to provide different behavior.
2052 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2053 SourceLocation StartLoc,
2054 TypeSourceInfo *TSInfo,
2055 Expr *DimExpr,
2056 SourceLocation RParenLoc) {
2057 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2058 }
2059
John Wiegley55262202011-04-25 06:54:41 +00002060 /// \brief Build a new expression trait expression.
2061 ///
2062 /// By default, performs semantic analysis to build the new expression.
2063 /// Subclasses may override this routine to provide different behavior.
2064 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2065 SourceLocation StartLoc,
2066 Expr *Queried,
2067 SourceLocation RParenLoc) {
2068 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2069 }
2070
Mike Stump1eb44332009-09-09 15:08:12 +00002071 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002072 /// expression.
2073 ///
2074 /// By default, performs semantic analysis to build the new expression.
2075 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002076 ExprResult RebuildDependentScopeDeclRefExpr(
2077 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002078 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002079 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002080 const TemplateArgumentListInfo *TemplateArgs,
2081 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002082 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002083 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002084
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002085 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002086 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002087 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002088
Richard Smithefeeccf2012-10-21 03:28:35 +00002089 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2090 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002091 }
2092
2093 /// \brief Build a new template-id expression.
2094 ///
2095 /// By default, performs semantic analysis to build the new expression.
2096 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002097 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002098 SourceLocation TemplateKWLoc,
2099 LookupResult &R,
2100 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002101 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002102 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2103 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002104 }
2105
2106 /// \brief Build a new object-construction expression.
2107 ///
2108 /// By default, performs semantic analysis to build the new expression.
2109 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002110 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002111 SourceLocation Loc,
2112 CXXConstructorDecl *Constructor,
2113 bool IsElidable,
2114 MultiExprArg Args,
2115 bool HadMultipleCandidates,
2116 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002117 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002118 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002119 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002120 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002121 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002122 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002123
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002124 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002125 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002126 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002127 RequiresZeroInit, ConstructKind,
2128 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002129 }
2130
2131 /// \brief Build a new object-construction expression.
2132 ///
2133 /// By default, performs semantic analysis to build the new expression.
2134 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002135 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2136 SourceLocation LParenLoc,
2137 MultiExprArg Args,
2138 SourceLocation RParenLoc) {
2139 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002140 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002141 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002142 RParenLoc);
2143 }
2144
2145 /// \brief Build a new object-construction expression.
2146 ///
2147 /// By default, performs semantic analysis to build the new expression.
2148 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002149 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2150 SourceLocation LParenLoc,
2151 MultiExprArg Args,
2152 SourceLocation RParenLoc) {
2153 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002154 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002155 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002156 RParenLoc);
2157 }
Mike Stump1eb44332009-09-09 15:08:12 +00002158
Douglas Gregorb98b1992009-08-11 05:31:07 +00002159 /// \brief Build a new member reference expression.
2160 ///
2161 /// By default, performs semantic analysis to build the new expression.
2162 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002163 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002164 QualType BaseType,
2165 bool IsArrow,
2166 SourceLocation OperatorLoc,
2167 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002168 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002169 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002170 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002171 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002172 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002173 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002174
John McCall9ae2f072010-08-23 23:25:46 +00002175 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002176 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002177 SS, TemplateKWLoc,
2178 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002179 MemberNameInfo,
2180 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002181 }
2182
John McCall129e2df2009-11-30 22:42:35 +00002183 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002184 ///
2185 /// By default, performs semantic analysis to build the new expression.
2186 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002187 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2188 SourceLocation OperatorLoc,
2189 bool IsArrow,
2190 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002191 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002192 NamedDecl *FirstQualifierInScope,
2193 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002194 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002195 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002196 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002197
John McCall9ae2f072010-08-23 23:25:46 +00002198 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002199 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002200 SS, TemplateKWLoc,
2201 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002202 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002203 }
Mike Stump1eb44332009-09-09 15:08:12 +00002204
Sebastian Redl2e156222010-09-10 20:55:43 +00002205 /// \brief Build a new noexcept expression.
2206 ///
2207 /// By default, performs semantic analysis to build the new expression.
2208 /// Subclasses may override this routine to provide different behavior.
2209 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2210 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2211 }
2212
Douglas Gregoree8aff02011-01-04 17:33:58 +00002213 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002214 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2215 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002216 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002217 llvm::Optional<unsigned> Length) {
2218 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002219 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2220 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002221 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002222
2223 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2224 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002225 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002226 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002227
Patrick Beardeb382ec2012-04-19 00:25:12 +00002228 /// \brief Build a new Objective-C boxed expression.
2229 ///
2230 /// By default, performs semantic analysis to build the new expression.
2231 /// Subclasses may override this routine to provide different behavior.
2232 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2233 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2234 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002235
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002236 /// \brief Build a new Objective-C array literal.
2237 ///
2238 /// By default, performs semantic analysis to build the new expression.
2239 /// Subclasses may override this routine to provide different behavior.
2240 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2241 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002242 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002243 MultiExprArg(Elements, NumElements));
2244 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002245
2246 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002247 Expr *Base, Expr *Key,
2248 ObjCMethodDecl *getterMethod,
2249 ObjCMethodDecl *setterMethod) {
2250 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2251 getterMethod, setterMethod);
2252 }
2253
2254 /// \brief Build a new Objective-C dictionary literal.
2255 ///
2256 /// By default, performs semantic analysis to build the new expression.
2257 /// Subclasses may override this routine to provide different behavior.
2258 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2259 ObjCDictionaryElement *Elements,
2260 unsigned NumElements) {
2261 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2262 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002263
James Dennett699c9042012-06-15 07:13:21 +00002264 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002265 ///
2266 /// By default, performs semantic analysis to build the new expression.
2267 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002268 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002269 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002270 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002271 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002272 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002273 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002274
Douglas Gregor92e986e2010-04-22 16:44:27 +00002275 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002276 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002277 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002278 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002279 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002280 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002281 MultiExprArg Args,
2282 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002283 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2284 ReceiverTypeInfo->getType(),
2285 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002286 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002287 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002288 }
2289
2290 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002291 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002292 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002293 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002294 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002295 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002296 MultiExprArg Args,
2297 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002298 return SemaRef.BuildInstanceMessage(Receiver,
2299 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002300 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002301 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002302 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002303 }
2304
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002305 /// \brief Build a new Objective-C ivar reference expression.
2306 ///
2307 /// By default, performs semantic analysis to build the new expression.
2308 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002309 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002310 SourceLocation IvarLoc,
2311 bool IsArrow, bool IsFreeIvar) {
2312 // FIXME: We lose track of the IsFreeIvar bit.
2313 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002314 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002315 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2316 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002317 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002318 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002319 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002320 false);
John Wiegley429bb272011-04-08 18:41:53 +00002321 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002322 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002323
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002324 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002325 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002326
John Wiegley429bb272011-04-08 18:41:53 +00002327 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002328 /*FIXME:*/IvarLoc, IsArrow,
2329 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002330 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002331 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002332 /*TemplateArgs=*/0);
2333 }
Douglas Gregore3303542010-04-26 20:47:02 +00002334
2335 /// \brief Build a new Objective-C property reference expression.
2336 ///
2337 /// By default, performs semantic analysis to build the new expression.
2338 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002339 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002340 ObjCPropertyDecl *Property,
2341 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002342 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002343 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002344 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2345 Sema::LookupMemberName);
2346 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002347 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002348 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002349 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002350 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002351 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002352
Douglas Gregore3303542010-04-26 20:47:02 +00002353 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002354 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002355
John Wiegley429bb272011-04-08 18:41:53 +00002356 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002357 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002358 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002359 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002360 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002361 /*TemplateArgs=*/0);
2362 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002363
John McCall12f78a62010-12-02 01:19:52 +00002364 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002365 ///
2366 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002367 /// Subclasses may override this routine to provide different behavior.
2368 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2369 ObjCMethodDecl *Getter,
2370 ObjCMethodDecl *Setter,
2371 SourceLocation PropertyLoc) {
2372 // Since these expressions can only be value-dependent, we do not
2373 // need to perform semantic analysis again.
2374 return Owned(
2375 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2376 VK_LValue, OK_ObjCProperty,
2377 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002378 }
2379
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002380 /// \brief Build a new Objective-C "isa" expression.
2381 ///
2382 /// By default, performs semantic analysis to build the new expression.
2383 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002384 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002385 bool IsArrow) {
2386 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002387 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002388 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2389 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002390 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002391 /*FIME:*/IsaLoc,
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 Gregorf9b9eab2010-04-26 20:11:03 +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(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002400 /*FIXME:*/IsaLoc, IsArrow,
2401 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002402 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002403 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002404 /*TemplateArgs=*/0);
2405 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002406
Douglas Gregorb98b1992009-08-11 05:31:07 +00002407 /// \brief Build a new shuffle vector expression.
2408 ///
2409 /// By default, performs semantic analysis to build the new expression.
2410 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002411 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002412 MultiExprArg SubExprs,
2413 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002414 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002415 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002416 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2417 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2418 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002419 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002420
Douglas Gregorb98b1992009-08-11 05:31:07 +00002421 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002422 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002423 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2424 SemaRef.Context.BuiltinFnTy,
2425 VK_RValue, BuiltinLoc);
2426 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2427 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2428 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002429
2430 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002431 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002432 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002433 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002434 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002435 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002436
Douglas Gregorb98b1992009-08-11 05:31:07 +00002437 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002438 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002439 }
John McCall43fed0d2010-11-12 08:19:04 +00002440
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002441 /// \brief Build a new template argument pack expansion.
2442 ///
2443 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002444 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002445 /// different behavior.
2446 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002447 SourceLocation EllipsisLoc,
2448 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002449 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002450 case TemplateArgument::Expression: {
2451 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002452 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2453 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002454 if (Result.isInvalid())
2455 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002456
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002457 return TemplateArgumentLoc(Result.get(), Result.get());
2458 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002459
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002460 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002461 return TemplateArgumentLoc(TemplateArgument(
2462 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002463 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002464 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002465 Pattern.getTemplateNameLoc(),
2466 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002467
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002468 case TemplateArgument::Null:
2469 case TemplateArgument::Integral:
2470 case TemplateArgument::Declaration:
2471 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002472 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002473 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002474 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002475
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002476 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002477 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002478 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002479 EllipsisLoc,
2480 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002481 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2482 Expansion);
2483 break;
2484 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002485
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002486 return TemplateArgumentLoc();
2487 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002488
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002489 /// \brief Build a new expression pack expansion.
2490 ///
2491 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002492 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002493 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002494 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2495 llvm::Optional<unsigned> NumExpansions) {
2496 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002497 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002498
2499 /// \brief Build a new atomic operation expression.
2500 ///
2501 /// By default, performs semantic analysis to build the new expression.
2502 /// Subclasses may override this routine to provide different behavior.
2503 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2504 MultiExprArg SubExprs,
2505 QualType RetTy,
2506 AtomicExpr::AtomicOp Op,
2507 SourceLocation RParenLoc) {
2508 // Just create the expression; there is not any interesting semantic
2509 // analysis here because we can't actually build an AtomicExpr until
2510 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002511 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002512 RParenLoc);
2513 }
2514
John McCall43fed0d2010-11-12 08:19:04 +00002515private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002516 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2517 QualType ObjectType,
2518 NamedDecl *FirstQualifierInScope,
2519 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002520
2521 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2522 QualType ObjectType,
2523 NamedDecl *FirstQualifierInScope,
2524 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002525};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002526
Douglas Gregor43959a92009-08-20 07:17:43 +00002527template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002528StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002529 if (!S)
2530 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002531
Douglas Gregor43959a92009-08-20 07:17:43 +00002532 switch (S->getStmtClass()) {
2533 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002534
Douglas Gregor43959a92009-08-20 07:17:43 +00002535 // Transform individual statement nodes
2536#define STMT(Node, Parent) \
2537 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002538#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002539#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002540#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002541
Douglas Gregor43959a92009-08-20 07:17:43 +00002542 // Transform expressions by calling TransformExpr.
2543#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002544#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002545#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002546#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002547 {
John McCall60d7b3a2010-08-24 06:29:42 +00002548 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002549 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002550 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002551
John McCall9ae2f072010-08-23 23:25:46 +00002552 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002553 }
Mike Stump1eb44332009-09-09 15:08:12 +00002554 }
2555
John McCall3fa5cae2010-10-26 07:05:15 +00002556 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002557}
Mike Stump1eb44332009-09-09 15:08:12 +00002558
2559
Douglas Gregor670444e2009-08-04 22:27:00 +00002560template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002561ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002562 if (!E)
2563 return SemaRef.Owned(E);
2564
2565 switch (E->getStmtClass()) {
2566 case Stmt::NoStmtClass: break;
2567#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002568#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002569#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002570 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002571#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002572 }
2573
John McCall3fa5cae2010-10-26 07:05:15 +00002574 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002575}
2576
2577template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002578bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2579 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002580 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002581 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002582 bool *ArgChanged) {
2583 for (unsigned I = 0; I != NumInputs; ++I) {
2584 // If requested, drop call arguments that need to be dropped.
2585 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2586 if (ArgChanged)
2587 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002588
Douglas Gregoraa165f82011-01-03 19:04:46 +00002589 break;
2590 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002591
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002592 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2593 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002594
Chris Lattner686775d2011-07-20 06:58:45 +00002595 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002596 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2597 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002598
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002599 // Determine whether the set of unexpanded parameter packs can and should
2600 // be expanded.
2601 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002602 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002603 llvm::Optional<unsigned> OrigNumExpansions
2604 = Expansion->getNumExpansions();
2605 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002606 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2607 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002608 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002609 Expand, RetainExpansion,
2610 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002611 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002612
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002613 if (!Expand) {
2614 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002615 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002616 // expansion.
2617 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2618 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2619 if (OutPattern.isInvalid())
2620 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002621
2622 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002623 Expansion->getEllipsisLoc(),
2624 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002625 if (Out.isInvalid())
2626 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002627
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002628 if (ArgChanged)
2629 *ArgChanged = true;
2630 Outputs.push_back(Out.get());
2631 continue;
2632 }
John McCallc8fc90a2011-07-06 07:30:07 +00002633
2634 // Record right away that the argument was changed. This needs
2635 // to happen even if the array expands to nothing.
2636 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002637
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002638 // The transform has determined that we should perform an elementwise
2639 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002640 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002641 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2642 ExprResult Out = getDerived().TransformExpr(Pattern);
2643 if (Out.isInvalid())
2644 return true;
2645
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002646 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002647 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2648 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002649 if (Out.isInvalid())
2650 return true;
2651 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002652
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002653 Outputs.push_back(Out.get());
2654 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002655
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002656 continue;
2657 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002658
Douglas Gregoraa165f82011-01-03 19:04:46 +00002659 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2660 if (Result.isInvalid())
2661 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002662
Douglas Gregoraa165f82011-01-03 19:04:46 +00002663 if (Result.get() != Inputs[I] && ArgChanged)
2664 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002665
2666 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002667 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002668
Douglas Gregoraa165f82011-01-03 19:04:46 +00002669 return false;
2670}
2671
2672template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002673NestedNameSpecifierLoc
2674TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2675 NestedNameSpecifierLoc NNS,
2676 QualType ObjectType,
2677 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002678 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002679 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002680 Qualifier = Qualifier.getPrefix())
2681 Qualifiers.push_back(Qualifier);
2682
2683 CXXScopeSpec SS;
2684 while (!Qualifiers.empty()) {
2685 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2686 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002687
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002688 switch (QNNS->getKind()) {
2689 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002690 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002691 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002692 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002693 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002694 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002695 FirstQualifierInScope, false))
2696 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002697
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002698 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002699
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002700 case NestedNameSpecifier::Namespace: {
2701 NamespaceDecl *NS
2702 = cast_or_null<NamespaceDecl>(
2703 getDerived().TransformDecl(
2704 Q.getLocalBeginLoc(),
2705 QNNS->getAsNamespace()));
2706 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2707 break;
2708 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002709
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002710 case NestedNameSpecifier::NamespaceAlias: {
2711 NamespaceAliasDecl *Alias
2712 = cast_or_null<NamespaceAliasDecl>(
2713 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2714 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002715 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002716 Q.getLocalEndLoc());
2717 break;
2718 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002719
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002720 case NestedNameSpecifier::Global:
2721 // There is no meaningful transformation that one could perform on the
2722 // global scope.
2723 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2724 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002725
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002726 case NestedNameSpecifier::TypeSpecWithTemplate:
2727 case NestedNameSpecifier::TypeSpec: {
2728 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2729 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002730
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002731 if (!TL)
2732 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002733
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002734 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00002735 (SemaRef.getLangOpts().CPlusPlus0x &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002736 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002737 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002738 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002739 if (TL.getType()->isEnumeralType())
2740 SemaRef.Diag(TL.getBeginLoc(),
2741 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002742 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2743 Q.getLocalEndLoc());
2744 break;
2745 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002746 // If the nested-name-specifier is an invalid type def, don't emit an
2747 // error because a previous error should have already been emitted.
2748 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2749 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002750 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002751 << TL.getType() << SS.getRange();
2752 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002753 return NestedNameSpecifierLoc();
2754 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002755 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002756
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002757 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002758 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002759 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002760 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002761
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002762 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002763 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002764 !getDerived().AlwaysRebuild())
2765 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002766
2767 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002768 // nested-name-specifier, do so.
2769 if (SS.location_size() == NNS.getDataLength() &&
2770 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2771 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2772
2773 // Allocate new nested-name-specifier location information.
2774 return SS.getWithLocInContext(SemaRef.Context);
2775}
2776
2777template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002778DeclarationNameInfo
2779TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002780::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002781 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002782 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002783 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002784
2785 switch (Name.getNameKind()) {
2786 case DeclarationName::Identifier:
2787 case DeclarationName::ObjCZeroArgSelector:
2788 case DeclarationName::ObjCOneArgSelector:
2789 case DeclarationName::ObjCMultiArgSelector:
2790 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002791 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002792 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002793 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002794
Douglas Gregor81499bb2009-09-03 22:13:48 +00002795 case DeclarationName::CXXConstructorName:
2796 case DeclarationName::CXXDestructorName:
2797 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002798 TypeSourceInfo *NewTInfo;
2799 CanQualType NewCanTy;
2800 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002801 NewTInfo = getDerived().TransformType(OldTInfo);
2802 if (!NewTInfo)
2803 return DeclarationNameInfo();
2804 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002805 }
2806 else {
2807 NewTInfo = 0;
2808 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002809 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002810 if (NewT.isNull())
2811 return DeclarationNameInfo();
2812 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2813 }
Mike Stump1eb44332009-09-09 15:08:12 +00002814
Abramo Bagnara25777432010-08-11 22:01:17 +00002815 DeclarationName NewName
2816 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2817 NewCanTy);
2818 DeclarationNameInfo NewNameInfo(NameInfo);
2819 NewNameInfo.setName(NewName);
2820 NewNameInfo.setNamedTypeInfo(NewTInfo);
2821 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002822 }
Mike Stump1eb44332009-09-09 15:08:12 +00002823 }
2824
David Blaikieb219cfc2011-09-23 05:06:16 +00002825 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002826}
2827
2828template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002829TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002830TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2831 TemplateName Name,
2832 SourceLocation NameLoc,
2833 QualType ObjectType,
2834 NamedDecl *FirstQualifierInScope) {
2835 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2836 TemplateDecl *Template = QTN->getTemplateDecl();
2837 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002838
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002839 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002840 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002841 Template));
2842 if (!TransTemplate)
2843 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002844
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002845 if (!getDerived().AlwaysRebuild() &&
2846 SS.getScopeRep() == QTN->getQualifier() &&
2847 TransTemplate == Template)
2848 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002849
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002850 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2851 TransTemplate);
2852 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002853
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002854 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2855 if (SS.getScopeRep()) {
2856 // These apply to the scope specifier, not the template.
2857 ObjectType = QualType();
2858 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002859 }
2860
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002861 if (!getDerived().AlwaysRebuild() &&
2862 SS.getScopeRep() == DTN->getQualifier() &&
2863 ObjectType.isNull())
2864 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002865
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002866 if (DTN->isIdentifier()) {
2867 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002868 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002869 NameLoc,
2870 ObjectType,
2871 FirstQualifierInScope);
2872 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002873
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002874 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2875 ObjectType);
2876 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002877
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002878 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2879 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002880 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002881 Template));
2882 if (!TransTemplate)
2883 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002884
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002885 if (!getDerived().AlwaysRebuild() &&
2886 TransTemplate == Template)
2887 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002888
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002889 return TemplateName(TransTemplate);
2890 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002891
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002892 if (SubstTemplateTemplateParmPackStorage *SubstPack
2893 = Name.getAsSubstTemplateTemplateParmPack()) {
2894 TemplateTemplateParmDecl *TransParam
2895 = cast_or_null<TemplateTemplateParmDecl>(
2896 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2897 if (!TransParam)
2898 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002899
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002900 if (!getDerived().AlwaysRebuild() &&
2901 TransParam == SubstPack->getParameterPack())
2902 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002903
2904 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002905 SubstPack->getArgumentPack());
2906 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002907
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002908 // These should be getting filtered out before they reach the AST.
2909 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002910}
2911
2912template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002913void TreeTransform<Derived>::InventTemplateArgumentLoc(
2914 const TemplateArgument &Arg,
2915 TemplateArgumentLoc &Output) {
2916 SourceLocation Loc = getDerived().getBaseLocation();
2917 switch (Arg.getKind()) {
2918 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002919 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002920 break;
2921
2922 case TemplateArgument::Type:
2923 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002924 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002925
John McCall833ca992009-10-29 08:12:44 +00002926 break;
2927
Douglas Gregor788cd062009-11-11 01:00:40 +00002928 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002929 case TemplateArgument::TemplateExpansion: {
2930 NestedNameSpecifierLocBuilder Builder;
2931 TemplateName Template = Arg.getAsTemplate();
2932 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2933 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2934 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2935 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002936
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002937 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002938 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002939 Builder.getWithLocInContext(SemaRef.Context),
2940 Loc);
2941 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00002942 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002943 Builder.getWithLocInContext(SemaRef.Context),
2944 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002945
Douglas Gregor788cd062009-11-11 01:00:40 +00002946 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002947 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002948
John McCall833ca992009-10-29 08:12:44 +00002949 case TemplateArgument::Expression:
2950 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2951 break;
2952
2953 case TemplateArgument::Declaration:
2954 case TemplateArgument::Integral:
2955 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002956 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00002957 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002958 break;
2959 }
2960}
2961
2962template<typename Derived>
2963bool TreeTransform<Derived>::TransformTemplateArgument(
2964 const TemplateArgumentLoc &Input,
2965 TemplateArgumentLoc &Output) {
2966 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002967 switch (Arg.getKind()) {
2968 case TemplateArgument::Null:
2969 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00002970 case TemplateArgument::Pack:
2971 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002972 case TemplateArgument::NullPtr:
2973 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00002974
Douglas Gregor670444e2009-08-04 22:27:00 +00002975 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002976 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002977 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002978 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002979
2980 DI = getDerived().TransformType(DI);
2981 if (!DI) return true;
2982
2983 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2984 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002985 }
Mike Stump1eb44332009-09-09 15:08:12 +00002986
Douglas Gregor788cd062009-11-11 01:00:40 +00002987 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002988 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2989 if (QualifierLoc) {
2990 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2991 if (!QualifierLoc)
2992 return true;
2993 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002994
Douglas Gregor1d752d72011-03-02 18:46:51 +00002995 CXXScopeSpec SS;
2996 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002997 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00002998 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2999 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003000 if (Template.isNull())
3001 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003002
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003003 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003004 Input.getTemplateNameLoc());
3005 return false;
3006 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003007
3008 case TemplateArgument::TemplateExpansion:
3009 llvm_unreachable("Caller should expand pack expansions");
3010
Douglas Gregor670444e2009-08-04 22:27:00 +00003011 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003012 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003013 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003014 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003015
John McCall833ca992009-10-29 08:12:44 +00003016 Expr *InputExpr = Input.getSourceExpression();
3017 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3018
Chris Lattner223de242011-04-25 20:37:58 +00003019 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003020 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003021 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003022 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003023 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003024 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003025 }
Mike Stump1eb44332009-09-09 15:08:12 +00003026
Douglas Gregor670444e2009-08-04 22:27:00 +00003027 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003028 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003029}
3030
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003031/// \brief Iterator adaptor that invents template argument location information
3032/// for each of the template arguments in its underlying iterator.
3033template<typename Derived, typename InputIterator>
3034class TemplateArgumentLocInventIterator {
3035 TreeTransform<Derived> &Self;
3036 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003037
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003038public:
3039 typedef TemplateArgumentLoc value_type;
3040 typedef TemplateArgumentLoc reference;
3041 typedef typename std::iterator_traits<InputIterator>::difference_type
3042 difference_type;
3043 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003044
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003045 class pointer {
3046 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003047
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003048 public:
3049 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003050
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003051 const TemplateArgumentLoc *operator->() const { return &Arg; }
3052 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003053
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003054 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003055
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003056 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3057 InputIterator Iter)
3058 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003059
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003060 TemplateArgumentLocInventIterator &operator++() {
3061 ++Iter;
3062 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003063 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003064
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003065 TemplateArgumentLocInventIterator operator++(int) {
3066 TemplateArgumentLocInventIterator Old(*this);
3067 ++(*this);
3068 return Old;
3069 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003070
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003071 reference operator*() const {
3072 TemplateArgumentLoc Result;
3073 Self.InventTemplateArgumentLoc(*Iter, Result);
3074 return Result;
3075 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003076
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003077 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003078
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003079 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3080 const TemplateArgumentLocInventIterator &Y) {
3081 return X.Iter == Y.Iter;
3082 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003083
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003084 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3085 const TemplateArgumentLocInventIterator &Y) {
3086 return X.Iter != Y.Iter;
3087 }
3088};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003089
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003090template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003091template<typename InputIterator>
3092bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3093 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003094 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003095 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003096 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003097 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003098
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003099 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3100 // Unpack argument packs, which we translate them into separate
3101 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003102 // FIXME: We could do much better if we could guarantee that the
3103 // TemplateArgumentLocInfo for the pack expansion would be usable for
3104 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003105 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003106 TemplateArgument::pack_iterator>
3107 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003108 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003109 In.getArgument().pack_begin()),
3110 PackLocIterator(*this,
3111 In.getArgument().pack_end()),
3112 Outputs))
3113 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003114
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003115 continue;
3116 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003117
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003118 if (In.getArgument().isPackExpansion()) {
3119 // We have a pack expansion, for which we will be substituting into
3120 // the pattern.
3121 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003122 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003123 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003124 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003125 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003126
Chris Lattner686775d2011-07-20 06:58:45 +00003127 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003128 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3129 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003130
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003131 // Determine whether the set of unexpanded parameter packs can and should
3132 // be expanded.
3133 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003134 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003135 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003136 if (getDerived().TryExpandParameterPacks(Ellipsis,
3137 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003138 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003139 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003140 RetainExpansion,
3141 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003142 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003143
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003144 if (!Expand) {
3145 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003146 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003147 // expansion.
3148 TemplateArgumentLoc OutPattern;
3149 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3150 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3151 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003152
Douglas Gregorcded4f62011-01-14 17:04:44 +00003153 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3154 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003155 if (Out.getArgument().isNull())
3156 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003157
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003158 Outputs.addArgument(Out);
3159 continue;
3160 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003161
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003162 // The transform has determined that we should perform an elementwise
3163 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003164 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003165 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3166
3167 if (getDerived().TransformTemplateArgument(Pattern, Out))
3168 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003169
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003170 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003171 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3172 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003173 if (Out.getArgument().isNull())
3174 return true;
3175 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003176
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003177 Outputs.addArgument(Out);
3178 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003179
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003180 // If we're supposed to retain a pack expansion, do so by temporarily
3181 // forgetting the partially-substituted parameter pack.
3182 if (RetainExpansion) {
3183 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003184
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003185 if (getDerived().TransformTemplateArgument(Pattern, Out))
3186 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003187
Douglas Gregorcded4f62011-01-14 17:04:44 +00003188 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3189 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003190 if (Out.getArgument().isNull())
3191 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003192
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003193 Outputs.addArgument(Out);
3194 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003195
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003196 continue;
3197 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003198
3199 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003200 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003201 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003202
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003203 Outputs.addArgument(Out);
3204 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003205
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003206 return false;
3207
3208}
3209
Douglas Gregor577f75a2009-08-04 16:50:30 +00003210//===----------------------------------------------------------------------===//
3211// Type transformation
3212//===----------------------------------------------------------------------===//
3213
3214template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003215QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003216 if (getDerived().AlreadyTransformed(T))
3217 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003218
John McCalla2becad2009-10-21 00:40:46 +00003219 // Temporary workaround. All of these transformations should
3220 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003221 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3222 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003223
John McCall43fed0d2010-11-12 08:19:04 +00003224 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003225
John McCalla2becad2009-10-21 00:40:46 +00003226 if (!NewDI)
3227 return QualType();
3228
3229 return NewDI->getType();
3230}
3231
3232template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003233TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003234 // Refine the base location to the type's location.
3235 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3236 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003237 if (getDerived().AlreadyTransformed(DI->getType()))
3238 return DI;
3239
3240 TypeLocBuilder TLB;
3241
3242 TypeLoc TL = DI->getTypeLoc();
3243 TLB.reserve(TL.getFullDataSize());
3244
John McCall43fed0d2010-11-12 08:19:04 +00003245 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003246 if (Result.isNull())
3247 return 0;
3248
John McCalla93c9342009-12-07 02:54:59 +00003249 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003250}
3251
3252template<typename Derived>
3253QualType
John McCall43fed0d2010-11-12 08:19:04 +00003254TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003255 switch (T.getTypeLocClass()) {
3256#define ABSTRACT_TYPELOC(CLASS, PARENT)
3257#define TYPELOC(CLASS, PARENT) \
3258 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003259 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003260#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003261 }
Mike Stump1eb44332009-09-09 15:08:12 +00003262
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003263 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003264}
3265
3266/// FIXME: By default, this routine adds type qualifiers only to types
3267/// that can have qualifiers, and silently suppresses those qualifiers
3268/// that are not permitted (e.g., qualifiers on reference or function
3269/// types). This is the right thing for template instantiation, but
3270/// probably not for other clients.
3271template<typename Derived>
3272QualType
3273TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003274 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003275 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003276
John McCall43fed0d2010-11-12 08:19:04 +00003277 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003278 if (Result.isNull())
3279 return QualType();
3280
3281 // Silently suppress qualifiers if the result type can't be qualified.
3282 // FIXME: this is the right thing for template instantiation, but
3283 // probably not for other clients.
3284 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003285 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003286
John McCallf85e1932011-06-15 23:02:42 +00003287 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003288 // resulting type.
3289 if (Quals.hasObjCLifetime()) {
3290 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3291 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003292 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003293 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003294 // A lifetime qualifier applied to a substituted template parameter
3295 // overrides the lifetime qualifier from the template argument.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003296 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003297 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3298 QualType Replacement = SubstTypeParam->getReplacementType();
3299 Qualifiers Qs = Replacement.getQualifiers();
3300 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003301 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003302 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3303 Qs);
3304 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003305 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003306 Replacement);
3307 TLB.TypeWasModifiedSafely(Result);
3308 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003309 // Otherwise, complain about the addition of a qualifier to an
3310 // already-qualified type.
3311 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003312 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003313 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003314
Douglas Gregore559ca12011-06-17 22:11:49 +00003315 Quals.removeObjCLifetime();
3316 }
3317 }
3318 }
John McCall28654742010-06-05 06:41:15 +00003319 if (!Quals.empty()) {
3320 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3321 TLB.push<QualifiedTypeLoc>(Result);
3322 // No location information to preserve.
3323 }
John McCalla2becad2009-10-21 00:40:46 +00003324
3325 return Result;
3326}
3327
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003328template<typename Derived>
3329TypeLoc
3330TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3331 QualType ObjectType,
3332 NamedDecl *UnqualLookup,
3333 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003334 QualType T = TL.getType();
3335 if (getDerived().AlreadyTransformed(T))
3336 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003337
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003338 TypeLocBuilder TLB;
3339 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003340
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003341 if (isa<TemplateSpecializationType>(T)) {
3342 TemplateSpecializationTypeLoc SpecTL
3343 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003344
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003345 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003346 getDerived().TransformTemplateName(SS,
3347 SpecTL.getTypePtr()->getTemplateName(),
3348 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003349 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003350 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003351 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003352
3353 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003354 Template);
3355 } else if (isa<DependentTemplateSpecializationType>(T)) {
3356 DependentTemplateSpecializationTypeLoc SpecTL
3357 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003358
Douglas Gregora88f09f2011-02-28 17:23:35 +00003359 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003360 = getDerived().RebuildTemplateName(SS,
3361 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003362 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003363 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003364 if (Template.isNull())
3365 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003366
3367 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003368 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003369 Template,
3370 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003371 } else {
3372 // Nothing special needs to be done for these.
3373 Result = getDerived().TransformType(TLB, TL);
3374 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003375
3376 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003377 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003378
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003379 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3380}
3381
Douglas Gregorb71d8212011-03-02 18:32:08 +00003382template<typename Derived>
3383TypeSourceInfo *
3384TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3385 QualType ObjectType,
3386 NamedDecl *UnqualLookup,
3387 CXXScopeSpec &SS) {
3388 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003389
Douglas Gregorb71d8212011-03-02 18:32:08 +00003390 QualType T = TSInfo->getType();
3391 if (getDerived().AlreadyTransformed(T))
3392 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003393
Douglas Gregorb71d8212011-03-02 18:32:08 +00003394 TypeLocBuilder TLB;
3395 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003396
Douglas Gregorb71d8212011-03-02 18:32:08 +00003397 TypeLoc TL = TSInfo->getTypeLoc();
3398 if (isa<TemplateSpecializationType>(T)) {
3399 TemplateSpecializationTypeLoc SpecTL
3400 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003401
Douglas Gregorb71d8212011-03-02 18:32:08 +00003402 TemplateName Template
3403 = getDerived().TransformTemplateName(SS,
3404 SpecTL.getTypePtr()->getTemplateName(),
3405 SpecTL.getTemplateNameLoc(),
3406 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003407 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003408 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003409
3410 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003411 Template);
3412 } else if (isa<DependentTemplateSpecializationType>(T)) {
3413 DependentTemplateSpecializationTypeLoc SpecTL
3414 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003415
Douglas Gregorb71d8212011-03-02 18:32:08 +00003416 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003417 = getDerived().RebuildTemplateName(SS,
3418 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003419 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003420 ObjectType, UnqualLookup);
3421 if (Template.isNull())
3422 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003423
3424 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003425 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003426 Template,
3427 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003428 } else {
3429 // Nothing special needs to be done for these.
3430 Result = getDerived().TransformType(TLB, TL);
3431 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003432
3433 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003434 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003435
Douglas Gregorb71d8212011-03-02 18:32:08 +00003436 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3437}
3438
John McCalla2becad2009-10-21 00:40:46 +00003439template <class TyLoc> static inline
3440QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3441 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3442 NewT.setNameLoc(T.getNameLoc());
3443 return T.getType();
3444}
3445
John McCalla2becad2009-10-21 00:40:46 +00003446template<typename Derived>
3447QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003448 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003449 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3450 NewT.setBuiltinLoc(T.getBuiltinLoc());
3451 if (T.needsExtraLocalData())
3452 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3453 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003454}
Mike Stump1eb44332009-09-09 15:08:12 +00003455
Douglas Gregor577f75a2009-08-04 16:50:30 +00003456template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003457QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003458 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003459 // FIXME: recurse?
3460 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003461}
Mike Stump1eb44332009-09-09 15:08:12 +00003462
Douglas Gregor577f75a2009-08-04 16:50:30 +00003463template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003464QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003465 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003466 QualType PointeeType
3467 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003468 if (PointeeType.isNull())
3469 return QualType();
3470
3471 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003472 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003473 // A dependent pointer type 'T *' has is being transformed such
3474 // that an Objective-C class type is being replaced for 'T'. The
3475 // resulting pointer type is an ObjCObjectPointerType, not a
3476 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003477 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003478
John McCallc12c5bb2010-05-15 11:32:37 +00003479 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3480 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003481 return Result;
3482 }
John McCall43fed0d2010-11-12 08:19:04 +00003483
Douglas Gregor92e986e2010-04-22 16:44:27 +00003484 if (getDerived().AlwaysRebuild() ||
3485 PointeeType != TL.getPointeeLoc().getType()) {
3486 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3487 if (Result.isNull())
3488 return QualType();
3489 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003490
John McCallf85e1932011-06-15 23:02:42 +00003491 // Objective-C ARC can add lifetime qualifiers to the type that we're
3492 // pointing to.
3493 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003494
Douglas Gregor92e986e2010-04-22 16:44:27 +00003495 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3496 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003497 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003498}
Mike Stump1eb44332009-09-09 15:08:12 +00003499
3500template<typename Derived>
3501QualType
John McCalla2becad2009-10-21 00:40:46 +00003502TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003503 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003504 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003505 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3506 if (PointeeType.isNull())
3507 return QualType();
3508
3509 QualType Result = TL.getType();
3510 if (getDerived().AlwaysRebuild() ||
3511 PointeeType != TL.getPointeeLoc().getType()) {
3512 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003513 TL.getSigilLoc());
3514 if (Result.isNull())
3515 return QualType();
3516 }
3517
Douglas Gregor39968ad2010-04-22 16:50:51 +00003518 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003519 NewT.setSigilLoc(TL.getSigilLoc());
3520 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003521}
3522
John McCall85737a72009-10-30 00:06:24 +00003523/// Transforms a reference type. Note that somewhat paradoxically we
3524/// don't care whether the type itself is an l-value type or an r-value
3525/// type; we only care if the type was *written* as an l-value type
3526/// or an r-value type.
3527template<typename Derived>
3528QualType
3529TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003530 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003531 const ReferenceType *T = TL.getTypePtr();
3532
3533 // Note that this works with the pointee-as-written.
3534 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3535 if (PointeeType.isNull())
3536 return QualType();
3537
3538 QualType Result = TL.getType();
3539 if (getDerived().AlwaysRebuild() ||
3540 PointeeType != T->getPointeeTypeAsWritten()) {
3541 Result = getDerived().RebuildReferenceType(PointeeType,
3542 T->isSpelledAsLValue(),
3543 TL.getSigilLoc());
3544 if (Result.isNull())
3545 return QualType();
3546 }
3547
John McCallf85e1932011-06-15 23:02:42 +00003548 // Objective-C ARC can add lifetime qualifiers to the type that we're
3549 // referring to.
3550 TLB.TypeWasModifiedSafely(
3551 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3552
John McCall85737a72009-10-30 00:06:24 +00003553 // r-value references can be rebuilt as l-value references.
3554 ReferenceTypeLoc NewTL;
3555 if (isa<LValueReferenceType>(Result))
3556 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3557 else
3558 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3559 NewTL.setSigilLoc(TL.getSigilLoc());
3560
3561 return Result;
3562}
3563
Mike Stump1eb44332009-09-09 15:08:12 +00003564template<typename Derived>
3565QualType
John McCalla2becad2009-10-21 00:40:46 +00003566TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003567 LValueReferenceTypeLoc TL) {
3568 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003569}
3570
Mike Stump1eb44332009-09-09 15:08:12 +00003571template<typename Derived>
3572QualType
John McCalla2becad2009-10-21 00:40:46 +00003573TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003574 RValueReferenceTypeLoc TL) {
3575 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003576}
Mike Stump1eb44332009-09-09 15:08:12 +00003577
Douglas Gregor577f75a2009-08-04 16:50:30 +00003578template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003579QualType
John McCalla2becad2009-10-21 00:40:46 +00003580TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003581 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003582 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003583 if (PointeeType.isNull())
3584 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003585
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003586 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3587 TypeSourceInfo* NewClsTInfo = 0;
3588 if (OldClsTInfo) {
3589 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3590 if (!NewClsTInfo)
3591 return QualType();
3592 }
3593
3594 const MemberPointerType *T = TL.getTypePtr();
3595 QualType OldClsType = QualType(T->getClass(), 0);
3596 QualType NewClsType;
3597 if (NewClsTInfo)
3598 NewClsType = NewClsTInfo->getType();
3599 else {
3600 NewClsType = getDerived().TransformType(OldClsType);
3601 if (NewClsType.isNull())
3602 return QualType();
3603 }
Mike Stump1eb44332009-09-09 15:08:12 +00003604
John McCalla2becad2009-10-21 00:40:46 +00003605 QualType Result = TL.getType();
3606 if (getDerived().AlwaysRebuild() ||
3607 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003608 NewClsType != OldClsType) {
3609 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003610 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003611 if (Result.isNull())
3612 return QualType();
3613 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003614
John McCalla2becad2009-10-21 00:40:46 +00003615 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3616 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003617 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003618
3619 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003620}
3621
Mike Stump1eb44332009-09-09 15:08:12 +00003622template<typename Derived>
3623QualType
John McCalla2becad2009-10-21 00:40:46 +00003624TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003625 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003626 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003627 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003628 if (ElementType.isNull())
3629 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003630
John McCalla2becad2009-10-21 00:40:46 +00003631 QualType Result = TL.getType();
3632 if (getDerived().AlwaysRebuild() ||
3633 ElementType != T->getElementType()) {
3634 Result = getDerived().RebuildConstantArrayType(ElementType,
3635 T->getSizeModifier(),
3636 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003637 T->getIndexTypeCVRQualifiers(),
3638 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003639 if (Result.isNull())
3640 return QualType();
3641 }
Eli Friedman457a3772012-01-25 22:19:07 +00003642
3643 // We might have either a ConstantArrayType or a VariableArrayType now:
3644 // a ConstantArrayType is allowed to have an element type which is a
3645 // VariableArrayType if the type is dependent. Fortunately, all array
3646 // types have the same location layout.
3647 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003648 NewTL.setLBracketLoc(TL.getLBracketLoc());
3649 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003650
John McCalla2becad2009-10-21 00:40:46 +00003651 Expr *Size = TL.getSizeExpr();
3652 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003653 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3654 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003655 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003656 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003657 }
3658 NewTL.setSizeExpr(Size);
3659
3660 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003661}
Mike Stump1eb44332009-09-09 15:08:12 +00003662
Douglas Gregor577f75a2009-08-04 16:50:30 +00003663template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003664QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003665 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003666 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003667 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003668 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003669 if (ElementType.isNull())
3670 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003671
John McCalla2becad2009-10-21 00:40:46 +00003672 QualType Result = TL.getType();
3673 if (getDerived().AlwaysRebuild() ||
3674 ElementType != T->getElementType()) {
3675 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003676 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003677 T->getIndexTypeCVRQualifiers(),
3678 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003679 if (Result.isNull())
3680 return QualType();
3681 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003682
John McCalla2becad2009-10-21 00:40:46 +00003683 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3684 NewTL.setLBracketLoc(TL.getLBracketLoc());
3685 NewTL.setRBracketLoc(TL.getRBracketLoc());
3686 NewTL.setSizeExpr(0);
3687
3688 return Result;
3689}
3690
3691template<typename Derived>
3692QualType
3693TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003694 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003695 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003696 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3697 if (ElementType.isNull())
3698 return QualType();
3699
John McCall60d7b3a2010-08-24 06:29:42 +00003700 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003701 = getDerived().TransformExpr(T->getSizeExpr());
3702 if (SizeResult.isInvalid())
3703 return QualType();
3704
John McCall9ae2f072010-08-23 23:25:46 +00003705 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003706
3707 QualType Result = TL.getType();
3708 if (getDerived().AlwaysRebuild() ||
3709 ElementType != T->getElementType() ||
3710 Size != T->getSizeExpr()) {
3711 Result = getDerived().RebuildVariableArrayType(ElementType,
3712 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003713 Size,
John McCalla2becad2009-10-21 00:40:46 +00003714 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003715 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003716 if (Result.isNull())
3717 return QualType();
3718 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003719
John McCalla2becad2009-10-21 00:40:46 +00003720 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3721 NewTL.setLBracketLoc(TL.getLBracketLoc());
3722 NewTL.setRBracketLoc(TL.getRBracketLoc());
3723 NewTL.setSizeExpr(Size);
3724
3725 return Result;
3726}
3727
3728template<typename Derived>
3729QualType
3730TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003731 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003732 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003733 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3734 if (ElementType.isNull())
3735 return QualType();
3736
Richard Smithf6702a32011-12-20 02:08:33 +00003737 // Array bounds are constant expressions.
3738 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3739 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003740
John McCall3b657512011-01-19 10:06:00 +00003741 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3742 Expr *origSize = TL.getSizeExpr();
3743 if (!origSize) origSize = T->getSizeExpr();
3744
3745 ExprResult sizeResult
3746 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003747 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003748 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003749 return QualType();
3750
John McCall3b657512011-01-19 10:06:00 +00003751 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003752
3753 QualType Result = TL.getType();
3754 if (getDerived().AlwaysRebuild() ||
3755 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003756 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003757 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3758 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003759 size,
John McCalla2becad2009-10-21 00:40:46 +00003760 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003761 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003762 if (Result.isNull())
3763 return QualType();
3764 }
John McCalla2becad2009-10-21 00:40:46 +00003765
3766 // We might have any sort of array type now, but fortunately they
3767 // all have the same location layout.
3768 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3769 NewTL.setLBracketLoc(TL.getLBracketLoc());
3770 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003771 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003772
3773 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003774}
Mike Stump1eb44332009-09-09 15:08:12 +00003775
3776template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003777QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003778 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003779 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003780 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003781
3782 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003783 QualType ElementType = getDerived().TransformType(T->getElementType());
3784 if (ElementType.isNull())
3785 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003786
Richard Smithf6702a32011-12-20 02:08:33 +00003787 // Vector sizes are constant expressions.
3788 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3789 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003790
John McCall60d7b3a2010-08-24 06:29:42 +00003791 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003792 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003793 if (Size.isInvalid())
3794 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003795
John McCalla2becad2009-10-21 00:40:46 +00003796 QualType Result = TL.getType();
3797 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003798 ElementType != T->getElementType() ||
3799 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003800 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003801 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003802 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003803 if (Result.isNull())
3804 return QualType();
3805 }
John McCalla2becad2009-10-21 00:40:46 +00003806
3807 // Result might be dependent or not.
3808 if (isa<DependentSizedExtVectorType>(Result)) {
3809 DependentSizedExtVectorTypeLoc NewTL
3810 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3811 NewTL.setNameLoc(TL.getNameLoc());
3812 } else {
3813 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3814 NewTL.setNameLoc(TL.getNameLoc());
3815 }
3816
3817 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003818}
Mike Stump1eb44332009-09-09 15:08:12 +00003819
3820template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003821QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003822 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003823 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003824 QualType ElementType = getDerived().TransformType(T->getElementType());
3825 if (ElementType.isNull())
3826 return QualType();
3827
John McCalla2becad2009-10-21 00:40:46 +00003828 QualType Result = TL.getType();
3829 if (getDerived().AlwaysRebuild() ||
3830 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003831 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003832 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003833 if (Result.isNull())
3834 return QualType();
3835 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003836
John McCalla2becad2009-10-21 00:40:46 +00003837 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3838 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003839
John McCalla2becad2009-10-21 00:40:46 +00003840 return Result;
3841}
3842
3843template<typename Derived>
3844QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003845 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003846 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003847 QualType ElementType = getDerived().TransformType(T->getElementType());
3848 if (ElementType.isNull())
3849 return QualType();
3850
3851 QualType Result = TL.getType();
3852 if (getDerived().AlwaysRebuild() ||
3853 ElementType != T->getElementType()) {
3854 Result = getDerived().RebuildExtVectorType(ElementType,
3855 T->getNumElements(),
3856 /*FIXME*/ SourceLocation());
3857 if (Result.isNull())
3858 return QualType();
3859 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003860
John McCalla2becad2009-10-21 00:40:46 +00003861 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3862 NewTL.setNameLoc(TL.getNameLoc());
3863
3864 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003865}
Mike Stump1eb44332009-09-09 15:08:12 +00003866
3867template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003868ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003869TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003870 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003871 llvm::Optional<unsigned> NumExpansions,
3872 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003873 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003874 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003875
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003876 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003877 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003878 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003879 TypeLoc OldTL = OldDI->getTypeLoc();
3880 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003881
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003882 TypeLocBuilder TLB;
3883 TypeLoc NewTL = OldDI->getTypeLoc();
3884 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003885
3886 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003887 OldExpansionTL.getPatternLoc());
3888 if (Result.isNull())
3889 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003890
3891 Result = RebuildPackExpansionType(Result,
3892 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003893 OldExpansionTL.getEllipsisLoc(),
3894 NumExpansions);
3895 if (Result.isNull())
3896 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003897
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003898 PackExpansionTypeLoc NewExpansionTL
3899 = TLB.push<PackExpansionTypeLoc>(Result);
3900 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3901 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3902 } else
3903 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003904 if (!NewDI)
3905 return 0;
3906
John McCallfb44de92011-05-01 22:35:37 +00003907 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003908 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003909
3910 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3911 OldParm->getDeclContext(),
3912 OldParm->getInnerLocStart(),
3913 OldParm->getLocation(),
3914 OldParm->getIdentifier(),
3915 NewDI->getType(),
3916 NewDI,
3917 OldParm->getStorageClass(),
3918 OldParm->getStorageClassAsWritten(),
3919 /* DefArg */ NULL);
3920 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3921 OldParm->getFunctionScopeIndex() + indexAdjustment);
3922 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003923}
3924
3925template<typename Derived>
3926bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003927 TransformFunctionTypeParams(SourceLocation Loc,
3928 ParmVarDecl **Params, unsigned NumParams,
3929 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003930 SmallVectorImpl<QualType> &OutParamTypes,
3931 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003932 int indexAdjustment = 0;
3933
Douglas Gregora009b592011-01-07 00:20:55 +00003934 for (unsigned i = 0; i != NumParams; ++i) {
3935 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003936 assert(OldParm->getFunctionScopeIndex() == i);
3937
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003938 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003939 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003940 if (OldParm->isParameterPack()) {
3941 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003942 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003943
Douglas Gregor603cfb42011-01-05 23:12:31 +00003944 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003945 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3946 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3947 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3948 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003949 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3950
Douglas Gregor603cfb42011-01-05 23:12:31 +00003951 // Determine whether we should expand the parameter packs.
3952 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003953 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003954 llvm::Optional<unsigned> OrigNumExpansions
3955 = ExpansionTL.getTypePtr()->getNumExpansions();
3956 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003957 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3958 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00003959 Unexpanded,
3960 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00003961 RetainExpansion,
3962 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003963 return true;
3964 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003965
Douglas Gregor603cfb42011-01-05 23:12:31 +00003966 if (ShouldExpand) {
3967 // Expand the function parameter pack into multiple, separate
3968 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003969 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003970 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003971 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003972 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003973 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003974 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003975 OrigNumExpansions,
3976 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003977 if (!NewParm)
3978 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003979
Douglas Gregora009b592011-01-07 00:20:55 +00003980 OutParamTypes.push_back(NewParm->getType());
3981 if (PVars)
3982 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003983 }
Douglas Gregord3731192011-01-10 07:32:04 +00003984
3985 // If we're supposed to retain a pack expansion, do so by temporarily
3986 // forgetting the partially-substituted parameter pack.
3987 if (RetainExpansion) {
3988 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003989 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003990 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003991 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003992 OrigNumExpansions,
3993 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00003994 if (!NewParm)
3995 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003996
Douglas Gregord3731192011-01-10 07:32:04 +00003997 OutParamTypes.push_back(NewParm->getType());
3998 if (PVars)
3999 PVars->push_back(NewParm);
4000 }
4001
John McCallfb44de92011-05-01 22:35:37 +00004002 // The next parameter should have the same adjustment as the
4003 // last thing we pushed, but we post-incremented indexAdjustment
4004 // on every push. Also, if we push nothing, the adjustment should
4005 // go down by one.
4006 indexAdjustment--;
4007
Douglas Gregor603cfb42011-01-05 23:12:31 +00004008 // We're done with the pack expansion.
4009 continue;
4010 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004011
4012 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004013 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004014 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4015 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004016 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004017 NumExpansions,
4018 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004019 } else {
4020 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004021 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004022 llvm::Optional<unsigned>(),
4023 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004024 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004025
John McCall21ef0fa2010-03-11 09:03:00 +00004026 if (!NewParm)
4027 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004028
Douglas Gregora009b592011-01-07 00:20:55 +00004029 OutParamTypes.push_back(NewParm->getType());
4030 if (PVars)
4031 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004032 continue;
4033 }
John McCall21ef0fa2010-03-11 09:03:00 +00004034
4035 // Deal with the possibility that we don't have a parameter
4036 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004037 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004038 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004039 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004040 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004041 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004042 = dyn_cast<PackExpansionType>(OldType)) {
4043 // We have a function parameter pack that may need to be expanded.
4044 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004045 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004046 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004047
Douglas Gregor603cfb42011-01-05 23:12:31 +00004048 // Determine whether we should expand the parameter packs.
4049 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004050 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004051 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004052 Unexpanded,
4053 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004054 RetainExpansion,
4055 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004056 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004057 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004058
Douglas Gregor603cfb42011-01-05 23:12:31 +00004059 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004060 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004061 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004062 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004063 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4064 QualType NewType = getDerived().TransformType(Pattern);
4065 if (NewType.isNull())
4066 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004067
Douglas Gregora009b592011-01-07 00:20:55 +00004068 OutParamTypes.push_back(NewType);
4069 if (PVars)
4070 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004071 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004072
Douglas Gregor603cfb42011-01-05 23:12:31 +00004073 // We're done with the pack expansion.
4074 continue;
4075 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004076
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004077 // If we're supposed to retain a pack expansion, do so by temporarily
4078 // forgetting the partially-substituted parameter pack.
4079 if (RetainExpansion) {
4080 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4081 QualType NewType = getDerived().TransformType(Pattern);
4082 if (NewType.isNull())
4083 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004084
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004085 OutParamTypes.push_back(NewType);
4086 if (PVars)
4087 PVars->push_back(0);
4088 }
Douglas Gregord3731192011-01-10 07:32:04 +00004089
Chad Rosier4a9d7952012-08-08 18:46:20 +00004090 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004091 // expansion.
4092 OldType = Expansion->getPattern();
4093 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004094 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4095 NewType = getDerived().TransformType(OldType);
4096 } else {
4097 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004098 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004099
Douglas Gregor603cfb42011-01-05 23:12:31 +00004100 if (NewType.isNull())
4101 return true;
4102
4103 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004104 NewType = getSema().Context.getPackExpansionType(NewType,
4105 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004106
Douglas Gregora009b592011-01-07 00:20:55 +00004107 OutParamTypes.push_back(NewType);
4108 if (PVars)
4109 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004110 }
4111
John McCallfb44de92011-05-01 22:35:37 +00004112#ifndef NDEBUG
4113 if (PVars) {
4114 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4115 if (ParmVarDecl *parm = (*PVars)[i])
4116 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004117 }
John McCallfb44de92011-05-01 22:35:37 +00004118#endif
4119
4120 return false;
4121}
John McCall21ef0fa2010-03-11 09:03:00 +00004122
4123template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004124QualType
John McCalla2becad2009-10-21 00:40:46 +00004125TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004126 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004127 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4128}
4129
4130template<typename Derived>
4131QualType
4132TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4133 FunctionProtoTypeLoc TL,
4134 CXXRecordDecl *ThisContext,
4135 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004136 // Transform the parameters and return type.
4137 //
Richard Smithe6975e92012-04-17 00:58:00 +00004138 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004139 // When the function has a trailing return type, we instantiate the
4140 // parameters before the return type, since the return type can then refer
4141 // to the parameters themselves (via decltype, sizeof, etc.).
4142 //
Chris Lattner686775d2011-07-20 06:58:45 +00004143 SmallVector<QualType, 4> ParamTypes;
4144 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004145 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004146
Douglas Gregordab60ad2010-10-01 18:44:50 +00004147 QualType ResultType;
4148
Richard Smith9fbf3272012-08-14 22:51:13 +00004149 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004150 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004151 TL.getParmArray(),
4152 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004153 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004154 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004155 return QualType();
4156
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004157 {
4158 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004159 // If a declaration declares a member function or member function
4160 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004161 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004162 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004163 // declarator.
4164 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004165
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004166 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4167 if (ResultType.isNull())
4168 return QualType();
4169 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004170 }
4171 else {
4172 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4173 if (ResultType.isNull())
4174 return QualType();
4175
Chad Rosier4a9d7952012-08-08 18:46:20 +00004176 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004177 TL.getParmArray(),
4178 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004179 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004180 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004181 return QualType();
4182 }
4183
Richard Smithe6975e92012-04-17 00:58:00 +00004184 // FIXME: Need to transform the exception-specification too.
4185
John McCalla2becad2009-10-21 00:40:46 +00004186 QualType Result = TL.getType();
4187 if (getDerived().AlwaysRebuild() ||
4188 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004189 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004190 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4191 Result = getDerived().RebuildFunctionProtoType(ResultType,
4192 ParamTypes.data(),
4193 ParamTypes.size(),
4194 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004195 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004196 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004197 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004198 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004199 if (Result.isNull())
4200 return QualType();
4201 }
Mike Stump1eb44332009-09-09 15:08:12 +00004202
John McCalla2becad2009-10-21 00:40:46 +00004203 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004204 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004205 NewTL.setLParenLoc(TL.getLParenLoc());
4206 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004207 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004208 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4209 NewTL.setArg(i, ParamDecls[i]);
4210
4211 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004212}
Mike Stump1eb44332009-09-09 15:08:12 +00004213
Douglas Gregor577f75a2009-08-04 16:50:30 +00004214template<typename Derived>
4215QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004216 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004217 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004218 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004219 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4220 if (ResultType.isNull())
4221 return QualType();
4222
4223 QualType Result = TL.getType();
4224 if (getDerived().AlwaysRebuild() ||
4225 ResultType != T->getResultType())
4226 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4227
4228 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004229 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004230 NewTL.setLParenLoc(TL.getLParenLoc());
4231 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004232 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004233
4234 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004235}
Mike Stump1eb44332009-09-09 15:08:12 +00004236
John McCalled976492009-12-04 22:46:56 +00004237template<typename Derived> QualType
4238TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004239 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004240 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004241 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004242 if (!D)
4243 return QualType();
4244
4245 QualType Result = TL.getType();
4246 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4247 Result = getDerived().RebuildUnresolvedUsingType(D);
4248 if (Result.isNull())
4249 return QualType();
4250 }
4251
4252 // We might get an arbitrary type spec type back. We should at
4253 // least always get a type spec type, though.
4254 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4255 NewTL.setNameLoc(TL.getNameLoc());
4256
4257 return Result;
4258}
4259
Douglas Gregor577f75a2009-08-04 16:50:30 +00004260template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004261QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004262 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004263 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004264 TypedefNameDecl *Typedef
4265 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4266 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004267 if (!Typedef)
4268 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004269
John McCalla2becad2009-10-21 00:40:46 +00004270 QualType Result = TL.getType();
4271 if (getDerived().AlwaysRebuild() ||
4272 Typedef != T->getDecl()) {
4273 Result = getDerived().RebuildTypedefType(Typedef);
4274 if (Result.isNull())
4275 return QualType();
4276 }
Mike Stump1eb44332009-09-09 15:08:12 +00004277
John McCalla2becad2009-10-21 00:40:46 +00004278 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4279 NewTL.setNameLoc(TL.getNameLoc());
4280
4281 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004282}
Mike Stump1eb44332009-09-09 15:08:12 +00004283
Douglas Gregor577f75a2009-08-04 16:50:30 +00004284template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004285QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004286 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004287 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004288 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4289 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004290
John McCall60d7b3a2010-08-24 06:29:42 +00004291 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004292 if (E.isInvalid())
4293 return QualType();
4294
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004295 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4296 if (E.isInvalid())
4297 return QualType();
4298
John McCalla2becad2009-10-21 00:40:46 +00004299 QualType Result = TL.getType();
4300 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004301 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004302 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004303 if (Result.isNull())
4304 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004305 }
John McCalla2becad2009-10-21 00:40:46 +00004306 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004307
John McCalla2becad2009-10-21 00:40:46 +00004308 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004309 NewTL.setTypeofLoc(TL.getTypeofLoc());
4310 NewTL.setLParenLoc(TL.getLParenLoc());
4311 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004312
4313 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004314}
Mike Stump1eb44332009-09-09 15:08:12 +00004315
4316template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004317QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004318 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004319 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4320 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4321 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004322 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004323
John McCalla2becad2009-10-21 00:40:46 +00004324 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004325 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4326 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004327 if (Result.isNull())
4328 return QualType();
4329 }
Mike Stump1eb44332009-09-09 15:08:12 +00004330
John McCalla2becad2009-10-21 00:40:46 +00004331 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004332 NewTL.setTypeofLoc(TL.getTypeofLoc());
4333 NewTL.setLParenLoc(TL.getLParenLoc());
4334 NewTL.setRParenLoc(TL.getRParenLoc());
4335 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004336
4337 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004338}
Mike Stump1eb44332009-09-09 15:08:12 +00004339
4340template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004341QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004342 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004343 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004344
Douglas Gregor670444e2009-08-04 22:27:00 +00004345 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004346 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4347 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004348
John McCall60d7b3a2010-08-24 06:29:42 +00004349 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004350 if (E.isInvalid())
4351 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004352
Richard Smith76f3f692012-02-22 02:04:18 +00004353 E = getSema().ActOnDecltypeExpression(E.take());
4354 if (E.isInvalid())
4355 return QualType();
4356
John McCalla2becad2009-10-21 00:40:46 +00004357 QualType Result = TL.getType();
4358 if (getDerived().AlwaysRebuild() ||
4359 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004360 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004361 if (Result.isNull())
4362 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004363 }
John McCalla2becad2009-10-21 00:40:46 +00004364 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004365
John McCalla2becad2009-10-21 00:40:46 +00004366 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4367 NewTL.setNameLoc(TL.getNameLoc());
4368
4369 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004370}
4371
4372template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004373QualType TreeTransform<Derived>::TransformUnaryTransformType(
4374 TypeLocBuilder &TLB,
4375 UnaryTransformTypeLoc TL) {
4376 QualType Result = TL.getType();
4377 if (Result->isDependentType()) {
4378 const UnaryTransformType *T = TL.getTypePtr();
4379 QualType NewBase =
4380 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4381 Result = getDerived().RebuildUnaryTransformType(NewBase,
4382 T->getUTTKind(),
4383 TL.getKWLoc());
4384 if (Result.isNull())
4385 return QualType();
4386 }
4387
4388 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4389 NewTL.setKWLoc(TL.getKWLoc());
4390 NewTL.setParensRange(TL.getParensRange());
4391 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4392 return Result;
4393}
4394
4395template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004396QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4397 AutoTypeLoc TL) {
4398 const AutoType *T = TL.getTypePtr();
4399 QualType OldDeduced = T->getDeducedType();
4400 QualType NewDeduced;
4401 if (!OldDeduced.isNull()) {
4402 NewDeduced = getDerived().TransformType(OldDeduced);
4403 if (NewDeduced.isNull())
4404 return QualType();
4405 }
4406
4407 QualType Result = TL.getType();
4408 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4409 Result = getDerived().RebuildAutoType(NewDeduced);
4410 if (Result.isNull())
4411 return QualType();
4412 }
4413
4414 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4415 NewTL.setNameLoc(TL.getNameLoc());
4416
4417 return Result;
4418}
4419
4420template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004421QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004422 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004423 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004424 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004425 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4426 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004427 if (!Record)
4428 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004429
John McCalla2becad2009-10-21 00:40:46 +00004430 QualType Result = TL.getType();
4431 if (getDerived().AlwaysRebuild() ||
4432 Record != T->getDecl()) {
4433 Result = getDerived().RebuildRecordType(Record);
4434 if (Result.isNull())
4435 return QualType();
4436 }
Mike Stump1eb44332009-09-09 15:08:12 +00004437
John McCalla2becad2009-10-21 00:40:46 +00004438 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4439 NewTL.setNameLoc(TL.getNameLoc());
4440
4441 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004442}
Mike Stump1eb44332009-09-09 15:08:12 +00004443
4444template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004445QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004446 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004447 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004448 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004449 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4450 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004451 if (!Enum)
4452 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004453
John McCalla2becad2009-10-21 00:40:46 +00004454 QualType Result = TL.getType();
4455 if (getDerived().AlwaysRebuild() ||
4456 Enum != T->getDecl()) {
4457 Result = getDerived().RebuildEnumType(Enum);
4458 if (Result.isNull())
4459 return QualType();
4460 }
Mike Stump1eb44332009-09-09 15:08:12 +00004461
John McCalla2becad2009-10-21 00:40:46 +00004462 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4463 NewTL.setNameLoc(TL.getNameLoc());
4464
4465 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004466}
John McCall7da24312009-09-05 00:15:47 +00004467
John McCall3cb0ebd2010-03-10 03:28:59 +00004468template<typename Derived>
4469QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4470 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004471 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004472 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4473 TL.getTypePtr()->getDecl());
4474 if (!D) return QualType();
4475
4476 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4477 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4478 return T;
4479}
4480
Douglas Gregor577f75a2009-08-04 16:50:30 +00004481template<typename Derived>
4482QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004483 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004484 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004485 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004486}
4487
Mike Stump1eb44332009-09-09 15:08:12 +00004488template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004489QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004490 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004491 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004492 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004493
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004494 // Substitute into the replacement type, which itself might involve something
4495 // that needs to be transformed. This only tends to occur with default
4496 // template arguments of template template parameters.
4497 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4498 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4499 if (Replacement.isNull())
4500 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004501
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004502 // Always canonicalize the replacement type.
4503 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4504 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004505 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004506 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004507
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004508 // Propagate type-source information.
4509 SubstTemplateTypeParmTypeLoc NewTL
4510 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4511 NewTL.setNameLoc(TL.getNameLoc());
4512 return Result;
4513
John McCall49a832b2009-10-18 09:09:24 +00004514}
4515
4516template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004517QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4518 TypeLocBuilder &TLB,
4519 SubstTemplateTypeParmPackTypeLoc TL) {
4520 return TransformTypeSpecType(TLB, TL);
4521}
4522
4523template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004524QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004525 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004526 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004527 const TemplateSpecializationType *T = TL.getTypePtr();
4528
Douglas Gregor1d752d72011-03-02 18:46:51 +00004529 // The nested-name-specifier never matters in a TemplateSpecializationType,
4530 // because we can't have a dependent nested-name-specifier anyway.
4531 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004532 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004533 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4534 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004535 if (Template.isNull())
4536 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004537
John McCall43fed0d2010-11-12 08:19:04 +00004538 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4539}
4540
Eli Friedmanb001de72011-10-06 23:00:33 +00004541template<typename Derived>
4542QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4543 AtomicTypeLoc TL) {
4544 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4545 if (ValueType.isNull())
4546 return QualType();
4547
4548 QualType Result = TL.getType();
4549 if (getDerived().AlwaysRebuild() ||
4550 ValueType != TL.getValueLoc().getType()) {
4551 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4552 if (Result.isNull())
4553 return QualType();
4554 }
4555
4556 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4557 NewTL.setKWLoc(TL.getKWLoc());
4558 NewTL.setLParenLoc(TL.getLParenLoc());
4559 NewTL.setRParenLoc(TL.getRParenLoc());
4560
4561 return Result;
4562}
4563
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004564namespace {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004565 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004566 /// container that provides a \c getArgLoc() member function.
4567 ///
4568 /// This iterator is intended to be used with the iterator form of
4569 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4570 template<typename ArgLocContainer>
4571 class TemplateArgumentLocContainerIterator {
4572 ArgLocContainer *Container;
4573 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004574
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004575 public:
4576 typedef TemplateArgumentLoc value_type;
4577 typedef TemplateArgumentLoc reference;
4578 typedef int difference_type;
4579 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004580
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004581 class pointer {
4582 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004583
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004584 public:
4585 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004586
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004587 const TemplateArgumentLoc *operator->() const {
4588 return &Arg;
4589 }
4590 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004591
4592
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004593 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004594
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004595 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4596 unsigned Index)
4597 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004598
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004599 TemplateArgumentLocContainerIterator &operator++() {
4600 ++Index;
4601 return *this;
4602 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004603
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004604 TemplateArgumentLocContainerIterator operator++(int) {
4605 TemplateArgumentLocContainerIterator Old(*this);
4606 ++(*this);
4607 return Old;
4608 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004609
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004610 TemplateArgumentLoc operator*() const {
4611 return Container->getArgLoc(Index);
4612 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004613
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004614 pointer operator->() const {
4615 return pointer(Container->getArgLoc(Index));
4616 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004617
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004618 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004619 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004620 return X.Container == Y.Container && X.Index == Y.Index;
4621 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004622
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004623 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004624 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004625 return !(X == Y);
4626 }
4627 };
4628}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004629
4630
John McCall43fed0d2010-11-12 08:19:04 +00004631template <typename Derived>
4632QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4633 TypeLocBuilder &TLB,
4634 TemplateSpecializationTypeLoc TL,
4635 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004636 TemplateArgumentListInfo NewTemplateArgs;
4637 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4638 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004639 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4640 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004641 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004642 ArgIterator(TL, TL.getNumArgs()),
4643 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004644 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004645
John McCall833ca992009-10-29 08:12:44 +00004646 // FIXME: maybe don't rebuild if all the template arguments are the same.
4647
4648 QualType Result =
4649 getDerived().RebuildTemplateSpecializationType(Template,
4650 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004651 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004652
4653 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004654 // Specializations of template template parameters are represented as
4655 // TemplateSpecializationTypes, and substitution of type alias templates
4656 // within a dependent context can transform them into
4657 // DependentTemplateSpecializationTypes.
4658 if (isa<DependentTemplateSpecializationType>(Result)) {
4659 DependentTemplateSpecializationTypeLoc NewTL
4660 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004661 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004662 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004663 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004664 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004665 NewTL.setLAngleLoc(TL.getLAngleLoc());
4666 NewTL.setRAngleLoc(TL.getRAngleLoc());
4667 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4668 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4669 return Result;
4670 }
4671
John McCall833ca992009-10-29 08:12:44 +00004672 TemplateSpecializationTypeLoc NewTL
4673 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004674 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004675 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4676 NewTL.setLAngleLoc(TL.getLAngleLoc());
4677 NewTL.setRAngleLoc(TL.getRAngleLoc());
4678 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4679 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004680 }
Mike Stump1eb44332009-09-09 15:08:12 +00004681
John McCall833ca992009-10-29 08:12:44 +00004682 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004683}
Mike Stump1eb44332009-09-09 15:08:12 +00004684
Douglas Gregora88f09f2011-02-28 17:23:35 +00004685template <typename Derived>
4686QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4687 TypeLocBuilder &TLB,
4688 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004689 TemplateName Template,
4690 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004691 TemplateArgumentListInfo NewTemplateArgs;
4692 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4693 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4694 typedef TemplateArgumentLocContainerIterator<
4695 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004696 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004697 ArgIterator(TL, TL.getNumArgs()),
4698 NewTemplateArgs))
4699 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004700
Douglas Gregora88f09f2011-02-28 17:23:35 +00004701 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004702
Douglas Gregora88f09f2011-02-28 17:23:35 +00004703 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4704 QualType Result
4705 = getSema().Context.getDependentTemplateSpecializationType(
4706 TL.getTypePtr()->getKeyword(),
4707 DTN->getQualifier(),
4708 DTN->getIdentifier(),
4709 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004710
Douglas Gregora88f09f2011-02-28 17:23:35 +00004711 DependentTemplateSpecializationTypeLoc NewTL
4712 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004713 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004714 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004715 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004716 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004717 NewTL.setLAngleLoc(TL.getLAngleLoc());
4718 NewTL.setRAngleLoc(TL.getRAngleLoc());
4719 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4720 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4721 return Result;
4722 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004723
4724 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004725 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004726 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004727 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004728
Douglas Gregora88f09f2011-02-28 17:23:35 +00004729 if (!Result.isNull()) {
4730 /// FIXME: Wrap this in an elaborated-type-specifier?
4731 TemplateSpecializationTypeLoc NewTL
4732 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004733 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004734 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004735 NewTL.setLAngleLoc(TL.getLAngleLoc());
4736 NewTL.setRAngleLoc(TL.getRAngleLoc());
4737 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4738 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4739 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004740
Douglas Gregora88f09f2011-02-28 17:23:35 +00004741 return Result;
4742}
4743
Mike Stump1eb44332009-09-09 15:08:12 +00004744template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004745QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004746TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004747 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004748 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004749
Douglas Gregor9e876872011-03-01 18:12:44 +00004750 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004751 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004752 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004753 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004754 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4755 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004756 return QualType();
4757 }
Mike Stump1eb44332009-09-09 15:08:12 +00004758
John McCall43fed0d2010-11-12 08:19:04 +00004759 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4760 if (NamedT.isNull())
4761 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004762
Richard Smith3e4c6c42011-05-05 21:57:07 +00004763 // C++0x [dcl.type.elab]p2:
4764 // If the identifier resolves to a typedef-name or the simple-template-id
4765 // resolves to an alias template specialization, the
4766 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004767 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4768 if (const TemplateSpecializationType *TST =
4769 NamedT->getAs<TemplateSpecializationType>()) {
4770 TemplateName Template = TST->getTemplateName();
4771 if (TypeAliasTemplateDecl *TAT =
4772 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4773 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4774 diag::err_tag_reference_non_tag) << 4;
4775 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4776 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004777 }
4778 }
4779
John McCalla2becad2009-10-21 00:40:46 +00004780 QualType Result = TL.getType();
4781 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004782 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004783 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004784 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004785 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004786 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004787 if (Result.isNull())
4788 return QualType();
4789 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004790
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004791 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004792 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004793 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004794 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004795}
Mike Stump1eb44332009-09-09 15:08:12 +00004796
4797template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004798QualType TreeTransform<Derived>::TransformAttributedType(
4799 TypeLocBuilder &TLB,
4800 AttributedTypeLoc TL) {
4801 const AttributedType *oldType = TL.getTypePtr();
4802 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4803 if (modifiedType.isNull())
4804 return QualType();
4805
4806 QualType result = TL.getType();
4807
4808 // FIXME: dependent operand expressions?
4809 if (getDerived().AlwaysRebuild() ||
4810 modifiedType != oldType->getModifiedType()) {
4811 // TODO: this is really lame; we should really be rebuilding the
4812 // equivalent type from first principles.
4813 QualType equivalentType
4814 = getDerived().TransformType(oldType->getEquivalentType());
4815 if (equivalentType.isNull())
4816 return QualType();
4817 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4818 modifiedType,
4819 equivalentType);
4820 }
4821
4822 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4823 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4824 if (TL.hasAttrOperand())
4825 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4826 if (TL.hasAttrExprOperand())
4827 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4828 else if (TL.hasAttrEnumOperand())
4829 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4830
4831 return result;
4832}
4833
4834template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004835QualType
4836TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4837 ParenTypeLoc TL) {
4838 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4839 if (Inner.isNull())
4840 return QualType();
4841
4842 QualType Result = TL.getType();
4843 if (getDerived().AlwaysRebuild() ||
4844 Inner != TL.getInnerLoc().getType()) {
4845 Result = getDerived().RebuildParenType(Inner);
4846 if (Result.isNull())
4847 return QualType();
4848 }
4849
4850 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4851 NewTL.setLParenLoc(TL.getLParenLoc());
4852 NewTL.setRParenLoc(TL.getRParenLoc());
4853 return Result;
4854}
4855
4856template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004857QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004858 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004859 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004860
Douglas Gregor2494dd02011-03-01 01:34:45 +00004861 NestedNameSpecifierLoc QualifierLoc
4862 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4863 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004864 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004865
John McCall33500952010-06-11 00:33:02 +00004866 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004867 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004868 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004869 QualifierLoc,
4870 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004871 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004872 if (Result.isNull())
4873 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004874
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004875 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4876 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004877 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4878
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004879 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004880 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004881 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004882 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004883 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004884 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004885 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004886 NewTL.setNameLoc(TL.getNameLoc());
4887 }
John McCalla2becad2009-10-21 00:40:46 +00004888 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004889}
Mike Stump1eb44332009-09-09 15:08:12 +00004890
Douglas Gregor577f75a2009-08-04 16:50:30 +00004891template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004892QualType TreeTransform<Derived>::
4893 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004894 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004895 NestedNameSpecifierLoc QualifierLoc;
4896 if (TL.getQualifierLoc()) {
4897 QualifierLoc
4898 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4899 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004900 return QualType();
4901 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004902
John McCall43fed0d2010-11-12 08:19:04 +00004903 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004904 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004905}
4906
4907template<typename Derived>
4908QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004909TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4910 DependentTemplateSpecializationTypeLoc TL,
4911 NestedNameSpecifierLoc QualifierLoc) {
4912 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004913
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004914 TemplateArgumentListInfo NewTemplateArgs;
4915 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4916 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004917
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004918 typedef TemplateArgumentLocContainerIterator<
4919 DependentTemplateSpecializationTypeLoc> ArgIterator;
4920 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4921 ArgIterator(TL, TL.getNumArgs()),
4922 NewTemplateArgs))
4923 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004924
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004925 QualType Result
4926 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4927 QualifierLoc,
4928 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004929 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004930 NewTemplateArgs);
4931 if (Result.isNull())
4932 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004933
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004934 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4935 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004936
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004937 // Copy information relevant to the template specialization.
4938 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004939 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004940 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004941 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004942 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4943 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004944 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004945 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004946
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004947 // Copy information relevant to the elaborated type.
4948 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004949 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004950 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004951 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4952 DependentTemplateSpecializationTypeLoc SpecTL
4953 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004954 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004955 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004956 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004957 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004958 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4959 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004960 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004961 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004962 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004963 TemplateSpecializationTypeLoc SpecTL
4964 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004965 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004966 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004967 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4968 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004969 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004970 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004971 }
4972 return Result;
4973}
4974
4975template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004976QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4977 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004978 QualType Pattern
4979 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004980 if (Pattern.isNull())
4981 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004982
4983 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004984 if (getDerived().AlwaysRebuild() ||
4985 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004986 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004987 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004988 TL.getEllipsisLoc(),
4989 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004990 if (Result.isNull())
4991 return QualType();
4992 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004993
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004994 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4995 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4996 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004997}
4998
4999template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005000QualType
5001TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005002 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005003 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005004 TLB.pushFullCopy(TL);
5005 return TL.getType();
5006}
5007
5008template<typename Derived>
5009QualType
5010TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005011 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005012 // ObjCObjectType is never dependent.
5013 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005014 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005015}
Mike Stump1eb44332009-09-09 15:08:12 +00005016
5017template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005018QualType
5019TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005020 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005021 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005022 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005023 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005024}
5025
Douglas Gregor577f75a2009-08-04 16:50:30 +00005026//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005027// Statement transformation
5028//===----------------------------------------------------------------------===//
5029template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005030StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005031TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005032 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005033}
5034
5035template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005036StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005037TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5038 return getDerived().TransformCompoundStmt(S, false);
5039}
5040
5041template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005042StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005043TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005044 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005045 Sema::CompoundScopeRAII CompoundScope(getSema());
5046
John McCall7114cba2010-08-27 19:56:05 +00005047 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005048 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005049 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005050 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5051 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005052 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005053 if (Result.isInvalid()) {
5054 // Immediately fail if this was a DeclStmt, since it's very
5055 // likely that this will cause problems for future statements.
5056 if (isa<DeclStmt>(*B))
5057 return StmtError();
5058
5059 // Otherwise, just keep processing substatements and fail later.
5060 SubStmtInvalid = true;
5061 continue;
5062 }
Mike Stump1eb44332009-09-09 15:08:12 +00005063
Douglas Gregor43959a92009-08-20 07:17:43 +00005064 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5065 Statements.push_back(Result.takeAs<Stmt>());
5066 }
Mike Stump1eb44332009-09-09 15:08:12 +00005067
John McCall7114cba2010-08-27 19:56:05 +00005068 if (SubStmtInvalid)
5069 return StmtError();
5070
Douglas Gregor43959a92009-08-20 07:17:43 +00005071 if (!getDerived().AlwaysRebuild() &&
5072 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005073 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005074
5075 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005076 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005077 S->getRBracLoc(),
5078 IsStmtExpr);
5079}
Mike Stump1eb44332009-09-09 15:08:12 +00005080
Douglas Gregor43959a92009-08-20 07:17:43 +00005081template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005082StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005083TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005084 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005085 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005086 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5087 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005088
Eli Friedman264c1f82009-11-19 03:14:00 +00005089 // Transform the left-hand case value.
5090 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005091 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005092 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005093 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005094
Eli Friedman264c1f82009-11-19 03:14:00 +00005095 // Transform the right-hand case value (for the GNU case-range extension).
5096 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005097 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005098 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005099 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005100 }
Mike Stump1eb44332009-09-09 15:08:12 +00005101
Douglas Gregor43959a92009-08-20 07:17:43 +00005102 // Build the case statement.
5103 // Case statements are always rebuilt so that they will attached to their
5104 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005105 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005106 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005107 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005108 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005109 S->getColonLoc());
5110 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005111 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005112
Douglas Gregor43959a92009-08-20 07:17:43 +00005113 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005114 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005115 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005116 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005117
Douglas Gregor43959a92009-08-20 07:17:43 +00005118 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005119 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005120}
5121
5122template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005123StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005124TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005125 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005126 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005127 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005128 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005129
Douglas Gregor43959a92009-08-20 07:17:43 +00005130 // Default statements are always rebuilt
5131 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005132 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005133}
Mike Stump1eb44332009-09-09 15:08:12 +00005134
Douglas Gregor43959a92009-08-20 07:17:43 +00005135template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005136StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005137TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005138 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005139 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005140 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005141
Chris Lattner57ad3782011-02-17 20:34:02 +00005142 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5143 S->getDecl());
5144 if (!LD)
5145 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005146
5147
Douglas Gregor43959a92009-08-20 07:17:43 +00005148 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005149 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005150 cast<LabelDecl>(LD), SourceLocation(),
5151 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005152}
Mike Stump1eb44332009-09-09 15:08:12 +00005153
Douglas Gregor43959a92009-08-20 07:17:43 +00005154template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005155StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005156TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5157 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5158 if (SubStmt.isInvalid())
5159 return StmtError();
5160
5161 // TODO: transform attributes
5162 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5163 return S;
5164
5165 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5166 S->getAttrs(),
5167 SubStmt.get());
5168}
5169
5170template<typename Derived>
5171StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005172TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005173 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005174 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005175 VarDecl *ConditionVar = 0;
5176 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005177 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005178 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005179 getDerived().TransformDefinition(
5180 S->getConditionVariable()->getLocation(),
5181 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005182 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005183 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005184 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005185 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005186
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005187 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005188 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005189
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005190 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005191 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005192 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005193 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005194 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005195 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005196
John McCall9ae2f072010-08-23 23:25:46 +00005197 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005198 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005199 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005200
John McCall9ae2f072010-08-23 23:25:46 +00005201 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5202 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005203 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005204
Douglas Gregor43959a92009-08-20 07:17:43 +00005205 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005206 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005207 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005208 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005209
Douglas Gregor43959a92009-08-20 07:17:43 +00005210 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005211 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005212 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005213 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005214
Douglas Gregor43959a92009-08-20 07:17:43 +00005215 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005216 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005217 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005218 Then.get() == S->getThen() &&
5219 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005220 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005221
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005222 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005223 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005224 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005225}
5226
5227template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005228StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005229TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005230 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005231 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005232 VarDecl *ConditionVar = 0;
5233 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005234 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005235 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005236 getDerived().TransformDefinition(
5237 S->getConditionVariable()->getLocation(),
5238 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005239 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005240 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005241 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005242 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005243
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005244 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005245 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005246 }
Mike Stump1eb44332009-09-09 15:08:12 +00005247
Douglas Gregor43959a92009-08-20 07:17:43 +00005248 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005249 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005250 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005251 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005252 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005253 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005254
Douglas Gregor43959a92009-08-20 07:17:43 +00005255 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005256 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005257 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005258 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005259
Douglas Gregor43959a92009-08-20 07:17:43 +00005260 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005261 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5262 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005263}
Mike Stump1eb44332009-09-09 15:08:12 +00005264
Douglas Gregor43959a92009-08-20 07:17:43 +00005265template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005266StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005267TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005268 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005269 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005270 VarDecl *ConditionVar = 0;
5271 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005272 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005273 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005274 getDerived().TransformDefinition(
5275 S->getConditionVariable()->getLocation(),
5276 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005277 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005278 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005279 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005280 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005281
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005282 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005283 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005284
5285 if (S->getCond()) {
5286 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005287 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005288 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005289 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005290 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005291 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005292 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005293 }
Mike Stump1eb44332009-09-09 15:08:12 +00005294
John McCall9ae2f072010-08-23 23:25:46 +00005295 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5296 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005297 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005298
Douglas Gregor43959a92009-08-20 07:17:43 +00005299 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005300 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005301 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005302 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005303
Douglas Gregor43959a92009-08-20 07:17:43 +00005304 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005305 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005306 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005307 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005308 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005309
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005310 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005311 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005312}
Mike Stump1eb44332009-09-09 15:08:12 +00005313
Douglas Gregor43959a92009-08-20 07:17:43 +00005314template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005315StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005316TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005317 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005318 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005319 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005320 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005321
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005322 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005323 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005324 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005325 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005326
Douglas Gregor43959a92009-08-20 07:17:43 +00005327 if (!getDerived().AlwaysRebuild() &&
5328 Cond.get() == S->getCond() &&
5329 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005330 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005331
John McCall9ae2f072010-08-23 23:25:46 +00005332 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5333 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005334 S->getRParenLoc());
5335}
Mike Stump1eb44332009-09-09 15:08:12 +00005336
Douglas Gregor43959a92009-08-20 07:17:43 +00005337template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005338StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005339TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005340 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005341 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005342 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005343 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005344
Douglas Gregor43959a92009-08-20 07:17:43 +00005345 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005346 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005347 VarDecl *ConditionVar = 0;
5348 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005349 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005350 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005351 getDerived().TransformDefinition(
5352 S->getConditionVariable()->getLocation(),
5353 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005354 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005355 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005356 } else {
5357 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005358
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005359 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005360 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005361
5362 if (S->getCond()) {
5363 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005364 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005365 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005366 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005367 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005368
John McCall9ae2f072010-08-23 23:25:46 +00005369 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005370 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005371 }
Mike Stump1eb44332009-09-09 15:08:12 +00005372
Chad Rosier4a9d7952012-08-08 18:46:20 +00005373 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005374 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005375 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005376
Douglas Gregor43959a92009-08-20 07:17:43 +00005377 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005378 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005379 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005380 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005381
John McCall9ae2f072010-08-23 23:25:46 +00005382 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5383 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005384 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005385
Douglas Gregor43959a92009-08-20 07:17:43 +00005386 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005387 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005388 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005389 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005390
Douglas Gregor43959a92009-08-20 07:17:43 +00005391 if (!getDerived().AlwaysRebuild() &&
5392 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005393 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005394 Inc.get() == S->getInc() &&
5395 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005396 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005397
Douglas Gregor43959a92009-08-20 07:17:43 +00005398 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005399 Init.get(), FullCond, ConditionVar,
5400 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005401}
5402
5403template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005404StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005405TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005406 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5407 S->getLabel());
5408 if (!LD)
5409 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005410
Douglas Gregor43959a92009-08-20 07:17:43 +00005411 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005412 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005413 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005414}
5415
5416template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005417StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005418TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005419 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005420 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005421 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005422 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005423
Douglas Gregor43959a92009-08-20 07:17:43 +00005424 if (!getDerived().AlwaysRebuild() &&
5425 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005426 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005427
5428 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005429 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005430}
5431
5432template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005433StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005434TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005435 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005436}
Mike Stump1eb44332009-09-09 15:08:12 +00005437
Douglas Gregor43959a92009-08-20 07:17:43 +00005438template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005439StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005440TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005441 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005442}
Mike Stump1eb44332009-09-09 15:08:12 +00005443
Douglas Gregor43959a92009-08-20 07:17:43 +00005444template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005445StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005446TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005447 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005448 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005449 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005450
Mike Stump1eb44332009-09-09 15:08:12 +00005451 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005452 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005453 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005454}
Mike Stump1eb44332009-09-09 15:08:12 +00005455
Douglas Gregor43959a92009-08-20 07:17:43 +00005456template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005457StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005458TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005459 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005460 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005461 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5462 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005463 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5464 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005465 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005466 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005467
Douglas Gregor43959a92009-08-20 07:17:43 +00005468 if (Transformed != *D)
5469 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005470
Douglas Gregor43959a92009-08-20 07:17:43 +00005471 Decls.push_back(Transformed);
5472 }
Mike Stump1eb44332009-09-09 15:08:12 +00005473
Douglas Gregor43959a92009-08-20 07:17:43 +00005474 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005475 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005476
5477 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005478 S->getStartLoc(), S->getEndLoc());
5479}
Mike Stump1eb44332009-09-09 15:08:12 +00005480
Douglas Gregor43959a92009-08-20 07:17:43 +00005481template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005482StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005483TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005484
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005485 SmallVector<Expr*, 8> Constraints;
5486 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005487 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005488
John McCall60d7b3a2010-08-24 06:29:42 +00005489 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005490 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005491
5492 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005493
Anders Carlsson703e3942010-01-24 05:50:09 +00005494 // Go through the outputs.
5495 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005496 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005497
Anders Carlsson703e3942010-01-24 05:50:09 +00005498 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005499 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005500
Anders Carlsson703e3942010-01-24 05:50:09 +00005501 // Transform the output expr.
5502 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005503 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005504 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005505 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005506
Anders Carlsson703e3942010-01-24 05:50:09 +00005507 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005508
John McCall9ae2f072010-08-23 23:25:46 +00005509 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005510 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005511
Anders Carlsson703e3942010-01-24 05:50:09 +00005512 // Go through the inputs.
5513 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005514 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005515
Anders Carlsson703e3942010-01-24 05:50:09 +00005516 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005517 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005518
Anders Carlsson703e3942010-01-24 05:50:09 +00005519 // Transform the input expr.
5520 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005521 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005522 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005523 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005524
Anders Carlsson703e3942010-01-24 05:50:09 +00005525 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005526
John McCall9ae2f072010-08-23 23:25:46 +00005527 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005528 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005529
Anders Carlsson703e3942010-01-24 05:50:09 +00005530 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005531 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005532
5533 // Go through the clobbers.
5534 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005535 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005536
5537 // No need to transform the asm string literal.
5538 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005539 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5540 S->isVolatile(), S->getNumOutputs(),
5541 S->getNumInputs(), Names.data(),
5542 Constraints, Exprs, AsmString.get(),
5543 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005544}
5545
Chad Rosier8cd64b42012-06-11 20:47:18 +00005546template<typename Derived>
5547StmtResult
5548TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005549 ArrayRef<Token> AsmToks =
5550 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005551
Chad Rosier7bd092b2012-08-15 16:53:30 +00005552 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5553 AsmToks, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005554}
Douglas Gregor43959a92009-08-20 07:17:43 +00005555
5556template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005557StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005558TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005559 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005560 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005561 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005562 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005563
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005564 // Transform the @catch statements (if present).
5565 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005566 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005567 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005568 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005569 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005570 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005571 if (Catch.get() != S->getCatchStmt(I))
5572 AnyCatchChanged = true;
5573 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005574 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005575
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005576 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005577 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005578 if (S->getFinallyStmt()) {
5579 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5580 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005581 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005582 }
5583
5584 // If nothing changed, just retain this statement.
5585 if (!getDerived().AlwaysRebuild() &&
5586 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005587 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005588 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005589 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005590
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005591 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005592 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005593 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005594}
Mike Stump1eb44332009-09-09 15:08:12 +00005595
Douglas Gregor43959a92009-08-20 07:17:43 +00005596template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005597StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005598TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005599 // Transform the @catch parameter, if there is one.
5600 VarDecl *Var = 0;
5601 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5602 TypeSourceInfo *TSInfo = 0;
5603 if (FromVar->getTypeSourceInfo()) {
5604 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5605 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005606 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005607 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005608
Douglas Gregorbe270a02010-04-26 17:57:08 +00005609 QualType T;
5610 if (TSInfo)
5611 T = TSInfo->getType();
5612 else {
5613 T = getDerived().TransformType(FromVar->getType());
5614 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005615 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005616 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005617
Douglas Gregorbe270a02010-04-26 17:57:08 +00005618 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5619 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005620 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005621 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005622
John McCall60d7b3a2010-08-24 06:29:42 +00005623 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005624 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005625 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005626
5627 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005628 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005629 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005630}
Mike Stump1eb44332009-09-09 15:08:12 +00005631
Douglas Gregor43959a92009-08-20 07:17:43 +00005632template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005633StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005634TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005635 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005636 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005637 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005638 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005639
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005640 // If nothing changed, just retain this statement.
5641 if (!getDerived().AlwaysRebuild() &&
5642 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005643 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005644
5645 // Build a new statement.
5646 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005647 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005648}
Mike Stump1eb44332009-09-09 15:08:12 +00005649
Douglas Gregor43959a92009-08-20 07:17:43 +00005650template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005651StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005652TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005653 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005654 if (S->getThrowExpr()) {
5655 Operand = getDerived().TransformExpr(S->getThrowExpr());
5656 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005657 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005658 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005659
Douglas Gregord1377b22010-04-22 21:44:01 +00005660 if (!getDerived().AlwaysRebuild() &&
5661 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005662 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005663
John McCall9ae2f072010-08-23 23:25:46 +00005664 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005665}
Mike Stump1eb44332009-09-09 15:08:12 +00005666
Douglas Gregor43959a92009-08-20 07:17:43 +00005667template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005668StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005669TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005670 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005671 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005672 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005673 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005674 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005675 Object =
5676 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5677 Object.get());
5678 if (Object.isInvalid())
5679 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005680
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005681 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005682 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005683 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005684 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005685
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005686 // If nothing change, just retain the current statement.
5687 if (!getDerived().AlwaysRebuild() &&
5688 Object.get() == S->getSynchExpr() &&
5689 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005690 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005691
5692 // Build a new statement.
5693 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005694 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005695}
5696
5697template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005698StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005699TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5700 ObjCAutoreleasePoolStmt *S) {
5701 // Transform the body.
5702 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5703 if (Body.isInvalid())
5704 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005705
John McCallf85e1932011-06-15 23:02:42 +00005706 // If nothing changed, just retain this statement.
5707 if (!getDerived().AlwaysRebuild() &&
5708 Body.get() == S->getSubStmt())
5709 return SemaRef.Owned(S);
5710
5711 // Build a new statement.
5712 return getDerived().RebuildObjCAutoreleasePoolStmt(
5713 S->getAtLoc(), Body.get());
5714}
5715
5716template<typename Derived>
5717StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005718TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005719 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005720 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005721 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005722 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005723 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005724
Douglas Gregorc3203e72010-04-22 23:10:45 +00005725 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005726 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005727 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005728 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005729
Douglas Gregorc3203e72010-04-22 23:10:45 +00005730 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005731 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005732 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005733 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005734
Douglas Gregorc3203e72010-04-22 23:10:45 +00005735 // If nothing changed, just retain this statement.
5736 if (!getDerived().AlwaysRebuild() &&
5737 Element.get() == S->getElement() &&
5738 Collection.get() == S->getCollection() &&
5739 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005740 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005741
Douglas Gregorc3203e72010-04-22 23:10:45 +00005742 // Build a new statement.
5743 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005744 Element.get(),
5745 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005746 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005747 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005748}
5749
5750
5751template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005752StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005753TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5754 // Transform the exception declaration, if any.
5755 VarDecl *Var = 0;
5756 if (S->getExceptionDecl()) {
5757 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005758 TypeSourceInfo *T = getDerived().TransformType(
5759 ExceptionDecl->getTypeSourceInfo());
5760 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005761 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005762
Douglas Gregor83cb9422010-09-09 17:09:21 +00005763 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005764 ExceptionDecl->getInnerLocStart(),
5765 ExceptionDecl->getLocation(),
5766 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005767 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005768 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005769 }
Mike Stump1eb44332009-09-09 15:08:12 +00005770
Douglas Gregor43959a92009-08-20 07:17:43 +00005771 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005772 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005773 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005774 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005775
Douglas Gregor43959a92009-08-20 07:17:43 +00005776 if (!getDerived().AlwaysRebuild() &&
5777 !Var &&
5778 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005779 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005780
5781 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5782 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005783 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005784}
Mike Stump1eb44332009-09-09 15:08:12 +00005785
Douglas Gregor43959a92009-08-20 07:17:43 +00005786template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005787StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005788TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5789 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005790 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005791 = getDerived().TransformCompoundStmt(S->getTryBlock());
5792 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005793 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005794
Douglas Gregor43959a92009-08-20 07:17:43 +00005795 // Transform the handlers.
5796 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005797 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005798 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005799 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005800 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5801 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005802 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005803
Douglas Gregor43959a92009-08-20 07:17:43 +00005804 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5805 Handlers.push_back(Handler.takeAs<Stmt>());
5806 }
Mike Stump1eb44332009-09-09 15:08:12 +00005807
Douglas Gregor43959a92009-08-20 07:17:43 +00005808 if (!getDerived().AlwaysRebuild() &&
5809 TryBlock.get() == S->getTryBlock() &&
5810 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005811 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005812
John McCall9ae2f072010-08-23 23:25:46 +00005813 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005814 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005815}
Mike Stump1eb44332009-09-09 15:08:12 +00005816
Richard Smithad762fc2011-04-14 22:09:26 +00005817template<typename Derived>
5818StmtResult
5819TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5820 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5821 if (Range.isInvalid())
5822 return StmtError();
5823
5824 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5825 if (BeginEnd.isInvalid())
5826 return StmtError();
5827
5828 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5829 if (Cond.isInvalid())
5830 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005831 if (Cond.get())
5832 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5833 if (Cond.isInvalid())
5834 return StmtError();
5835 if (Cond.get())
5836 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005837
5838 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5839 if (Inc.isInvalid())
5840 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005841 if (Inc.get())
5842 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005843
5844 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5845 if (LoopVar.isInvalid())
5846 return StmtError();
5847
5848 StmtResult NewStmt = S;
5849 if (getDerived().AlwaysRebuild() ||
5850 Range.get() != S->getRangeStmt() ||
5851 BeginEnd.get() != S->getBeginEndStmt() ||
5852 Cond.get() != S->getCond() ||
5853 Inc.get() != S->getInc() ||
5854 LoopVar.get() != S->getLoopVarStmt())
5855 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5856 S->getColonLoc(), Range.get(),
5857 BeginEnd.get(), Cond.get(),
5858 Inc.get(), LoopVar.get(),
5859 S->getRParenLoc());
5860
5861 StmtResult Body = getDerived().TransformStmt(S->getBody());
5862 if (Body.isInvalid())
5863 return StmtError();
5864
5865 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5866 // it now so we have a new statement to attach the body to.
5867 if (Body.get() != S->getBody() && NewStmt.get() == S)
5868 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5869 S->getColonLoc(), Range.get(),
5870 BeginEnd.get(), Cond.get(),
5871 Inc.get(), LoopVar.get(),
5872 S->getRParenLoc());
5873
5874 if (NewStmt.get() == S)
5875 return SemaRef.Owned(S);
5876
5877 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5878}
5879
John Wiegley28bbe4b2011-04-28 01:08:34 +00005880template<typename Derived>
5881StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005882TreeTransform<Derived>::TransformMSDependentExistsStmt(
5883 MSDependentExistsStmt *S) {
5884 // Transform the nested-name-specifier, if any.
5885 NestedNameSpecifierLoc QualifierLoc;
5886 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005887 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005888 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5889 if (!QualifierLoc)
5890 return StmtError();
5891 }
5892
5893 // Transform the declaration name.
5894 DeclarationNameInfo NameInfo = S->getNameInfo();
5895 if (NameInfo.getName()) {
5896 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5897 if (!NameInfo.getName())
5898 return StmtError();
5899 }
5900
5901 // Check whether anything changed.
5902 if (!getDerived().AlwaysRebuild() &&
5903 QualifierLoc == S->getQualifierLoc() &&
5904 NameInfo.getName() == S->getNameInfo().getName())
5905 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005906
Douglas Gregorba0513d2011-10-25 01:33:02 +00005907 // Determine whether this name exists, if we can.
5908 CXXScopeSpec SS;
5909 SS.Adopt(QualifierLoc);
5910 bool Dependent = false;
5911 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5912 case Sema::IER_Exists:
5913 if (S->isIfExists())
5914 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005915
Douglas Gregorba0513d2011-10-25 01:33:02 +00005916 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5917
5918 case Sema::IER_DoesNotExist:
5919 if (S->isIfNotExists())
5920 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005921
Douglas Gregorba0513d2011-10-25 01:33:02 +00005922 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005923
Douglas Gregorba0513d2011-10-25 01:33:02 +00005924 case Sema::IER_Dependent:
5925 Dependent = true;
5926 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005927
Douglas Gregor65019ac2011-10-25 03:44:56 +00005928 case Sema::IER_Error:
5929 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005930 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005931
Douglas Gregorba0513d2011-10-25 01:33:02 +00005932 // We need to continue with the instantiation, so do so now.
5933 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5934 if (SubStmt.isInvalid())
5935 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005936
Douglas Gregorba0513d2011-10-25 01:33:02 +00005937 // If we have resolved the name, just transform to the substatement.
5938 if (!Dependent)
5939 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005940
Douglas Gregorba0513d2011-10-25 01:33:02 +00005941 // The name is still dependent, so build a dependent expression again.
5942 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5943 S->isIfExists(),
5944 QualifierLoc,
5945 NameInfo,
5946 SubStmt.get());
5947}
5948
5949template<typename Derived>
5950StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00005951TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5952 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5953 if(TryBlock.isInvalid()) return StmtError();
5954
5955 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5956 if(!getDerived().AlwaysRebuild() &&
5957 TryBlock.get() == S->getTryBlock() &&
5958 Handler.get() == S->getHandler())
5959 return SemaRef.Owned(S);
5960
5961 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5962 S->getTryLoc(),
5963 TryBlock.take(),
5964 Handler.take());
5965}
5966
5967template<typename Derived>
5968StmtResult
5969TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5970 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5971 if(Block.isInvalid()) return StmtError();
5972
5973 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5974 Block.take());
5975}
5976
5977template<typename Derived>
5978StmtResult
5979TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5980 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5981 if(FilterExpr.isInvalid()) return StmtError();
5982
5983 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5984 if(Block.isInvalid()) return StmtError();
5985
5986 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5987 FilterExpr.take(),
5988 Block.take());
5989}
5990
5991template<typename Derived>
5992StmtResult
5993TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5994 if(isa<SEHFinallyStmt>(Handler))
5995 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5996 else
5997 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5998}
5999
Douglas Gregor43959a92009-08-20 07:17:43 +00006000//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006001// Expression transformation
6002//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006003template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006004ExprResult
John McCall454feb92009-12-08 09:21:05 +00006005TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006006 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006007}
Mike Stump1eb44332009-09-09 15:08:12 +00006008
6009template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006010ExprResult
John McCall454feb92009-12-08 09:21:05 +00006011TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006012 NestedNameSpecifierLoc QualifierLoc;
6013 if (E->getQualifierLoc()) {
6014 QualifierLoc
6015 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6016 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006017 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006018 }
John McCalldbd872f2009-12-08 09:08:17 +00006019
6020 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006021 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6022 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006023 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006024 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006025
John McCallec8045d2010-08-17 21:27:17 +00006026 DeclarationNameInfo NameInfo = E->getNameInfo();
6027 if (NameInfo.getName()) {
6028 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6029 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006030 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006031 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006032
6033 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006034 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006035 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006036 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006037 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006038
6039 // Mark it referenced in the new context regardless.
6040 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006041 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006042
John McCall3fa5cae2010-10-26 07:05:15 +00006043 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006044 }
John McCalldbd872f2009-12-08 09:08:17 +00006045
6046 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006047 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006048 TemplateArgs = &TransArgs;
6049 TransArgs.setLAngleLoc(E->getLAngleLoc());
6050 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006051 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6052 E->getNumTemplateArgs(),
6053 TransArgs))
6054 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006055 }
6056
Chad Rosier4a9d7952012-08-08 18:46:20 +00006057 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006058 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006059}
Mike Stump1eb44332009-09-09 15:08:12 +00006060
Douglas Gregorb98b1992009-08-11 05:31:07 +00006061template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006062ExprResult
John McCall454feb92009-12-08 09:21:05 +00006063TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006064 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006065}
Mike Stump1eb44332009-09-09 15:08:12 +00006066
Douglas Gregorb98b1992009-08-11 05:31:07 +00006067template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006068ExprResult
John McCall454feb92009-12-08 09:21:05 +00006069TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006070 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006071}
Mike Stump1eb44332009-09-09 15:08:12 +00006072
Douglas Gregorb98b1992009-08-11 05:31:07 +00006073template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006074ExprResult
John McCall454feb92009-12-08 09:21:05 +00006075TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006076 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006077}
Mike Stump1eb44332009-09-09 15:08:12 +00006078
Douglas Gregorb98b1992009-08-11 05:31:07 +00006079template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006080ExprResult
John McCall454feb92009-12-08 09:21:05 +00006081TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006082 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006083}
Mike Stump1eb44332009-09-09 15:08:12 +00006084
Douglas Gregorb98b1992009-08-11 05:31:07 +00006085template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006086ExprResult
John McCall454feb92009-12-08 09:21:05 +00006087TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006088 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006089}
6090
6091template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006092ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006093TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6094 return SemaRef.MaybeBindToTemporary(E);
6095}
6096
6097template<typename Derived>
6098ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006099TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6100 ExprResult ControllingExpr =
6101 getDerived().TransformExpr(E->getControllingExpr());
6102 if (ControllingExpr.isInvalid())
6103 return ExprError();
6104
Chris Lattner686775d2011-07-20 06:58:45 +00006105 SmallVector<Expr *, 4> AssocExprs;
6106 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006107 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6108 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6109 if (TS) {
6110 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6111 if (!AssocType)
6112 return ExprError();
6113 AssocTypes.push_back(AssocType);
6114 } else {
6115 AssocTypes.push_back(0);
6116 }
6117
6118 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6119 if (AssocExpr.isInvalid())
6120 return ExprError();
6121 AssocExprs.push_back(AssocExpr.release());
6122 }
6123
6124 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6125 E->getDefaultLoc(),
6126 E->getRParenLoc(),
6127 ControllingExpr.release(),
6128 AssocTypes.data(),
6129 AssocExprs.data(),
6130 E->getNumAssocs());
6131}
6132
6133template<typename Derived>
6134ExprResult
John McCall454feb92009-12-08 09:21:05 +00006135TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006136 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006137 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006138 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006139
Douglas Gregorb98b1992009-08-11 05:31:07 +00006140 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006141 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006142
John McCall9ae2f072010-08-23 23:25:46 +00006143 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006144 E->getRParen());
6145}
6146
Richard Smithefeeccf2012-10-21 03:28:35 +00006147/// \brief The operand of a unary address-of operator has special rules: it's
6148/// allowed to refer to a non-static member of a class even if there's no 'this'
6149/// object available.
6150template<typename Derived>
6151ExprResult
6152TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6153 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6154 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6155 else
6156 return getDerived().TransformExpr(E);
6157}
6158
Mike Stump1eb44332009-09-09 15:08:12 +00006159template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006160ExprResult
John McCall454feb92009-12-08 09:21:05 +00006161TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00006162 ExprResult SubExpr = TransformAddressOfOperand(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006163 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006164 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006165
Douglas Gregorb98b1992009-08-11 05:31:07 +00006166 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006167 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006168
Douglas Gregorb98b1992009-08-11 05:31:07 +00006169 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6170 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006171 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006172}
Mike Stump1eb44332009-09-09 15:08:12 +00006173
Douglas Gregorb98b1992009-08-11 05:31:07 +00006174template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006175ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006176TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6177 // Transform the type.
6178 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6179 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006180 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006181
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006182 // Transform all of the components into components similar to what the
6183 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006184 // FIXME: It would be slightly more efficient in the non-dependent case to
6185 // just map FieldDecls, rather than requiring the rebuilder to look for
6186 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006187 // template code that we don't care.
6188 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006189 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006190 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006191 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006192 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6193 const Node &ON = E->getComponent(I);
6194 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006195 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006196 Comp.LocStart = ON.getSourceRange().getBegin();
6197 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006198 switch (ON.getKind()) {
6199 case Node::Array: {
6200 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006201 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006202 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006203 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006204
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006205 ExprChanged = ExprChanged || Index.get() != FromIndex;
6206 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006207 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006208 break;
6209 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006210
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006211 case Node::Field:
6212 case Node::Identifier:
6213 Comp.isBrackets = false;
6214 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006215 if (!Comp.U.IdentInfo)
6216 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006217
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006218 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006219
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006220 case Node::Base:
6221 // Will be recomputed during the rebuild.
6222 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006223 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006224
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006225 Components.push_back(Comp);
6226 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006227
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006228 // If nothing changed, retain the existing expression.
6229 if (!getDerived().AlwaysRebuild() &&
6230 Type == E->getTypeSourceInfo() &&
6231 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006232 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006233
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006234 // Build a new offsetof expression.
6235 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6236 Components.data(), Components.size(),
6237 E->getRParenLoc());
6238}
6239
6240template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006241ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006242TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6243 assert(getDerived().AlreadyTransformed(E->getType()) &&
6244 "opaque value expression requires transformation");
6245 return SemaRef.Owned(E);
6246}
6247
6248template<typename Derived>
6249ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006250TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006251 // Rebuild the syntactic form. The original syntactic form has
6252 // opaque-value expressions in it, so strip those away and rebuild
6253 // the result. This is a really awful way of doing this, but the
6254 // better solution (rebuilding the semantic expressions and
6255 // rebinding OVEs as necessary) doesn't work; we'd need
6256 // TreeTransform to not strip away implicit conversions.
6257 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6258 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006259 if (result.isInvalid()) return ExprError();
6260
6261 // If that gives us a pseudo-object result back, the pseudo-object
6262 // expression must have been an lvalue-to-rvalue conversion which we
6263 // should reapply.
6264 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6265 result = SemaRef.checkPseudoObjectRValue(result.take());
6266
6267 return result;
6268}
6269
6270template<typename Derived>
6271ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006272TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6273 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006274 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006275 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006276
John McCalla93c9342009-12-07 02:54:59 +00006277 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006278 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006279 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006280
John McCall5ab75172009-11-04 07:28:41 +00006281 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006282 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006283
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006284 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6285 E->getKind(),
6286 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006287 }
Mike Stump1eb44332009-09-09 15:08:12 +00006288
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006289 // C++0x [expr.sizeof]p1:
6290 // The operand is either an expression, which is an unevaluated operand
6291 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006292 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6293 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006294
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006295 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6296 if (SubExpr.isInvalid())
6297 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006298
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006299 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6300 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006301
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006302 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6303 E->getOperatorLoc(),
6304 E->getKind(),
6305 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006306}
Mike Stump1eb44332009-09-09 15:08:12 +00006307
Douglas Gregorb98b1992009-08-11 05:31:07 +00006308template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006309ExprResult
John McCall454feb92009-12-08 09:21:05 +00006310TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006311 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006312 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006313 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006314
John McCall60d7b3a2010-08-24 06:29:42 +00006315 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006316 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006317 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006318
6319
Douglas Gregorb98b1992009-08-11 05:31:07 +00006320 if (!getDerived().AlwaysRebuild() &&
6321 LHS.get() == E->getLHS() &&
6322 RHS.get() == E->getRHS())
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().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006326 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006327 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006328 E->getRBracketLoc());
6329}
Mike Stump1eb44332009-09-09 15:08:12 +00006330
6331template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006332ExprResult
John McCall454feb92009-12-08 09:21:05 +00006333TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006334 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006335 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006336 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006337 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006338
6339 // Transform arguments.
6340 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006341 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006342 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006343 &ArgChanged))
6344 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006345
Douglas Gregorb98b1992009-08-11 05:31:07 +00006346 if (!getDerived().AlwaysRebuild() &&
6347 Callee.get() == E->getCallee() &&
6348 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006349 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006350
Douglas Gregorb98b1992009-08-11 05:31:07 +00006351 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006352 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006353 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006354 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006355 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006356 E->getRParenLoc());
6357}
Mike Stump1eb44332009-09-09 15:08:12 +00006358
6359template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006360ExprResult
John McCall454feb92009-12-08 09:21:05 +00006361TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006362 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006363 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006364 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006365
Douglas Gregor40d96a62011-02-28 21:54:11 +00006366 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006367 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006368 QualifierLoc
6369 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006370
Douglas Gregor40d96a62011-02-28 21:54:11 +00006371 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006372 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006373 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006374 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006375
Eli Friedmanf595cc42009-12-04 06:40:45 +00006376 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006377 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6378 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006379 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006380 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006381
John McCall6bb80172010-03-30 21:47:33 +00006382 NamedDecl *FoundDecl = E->getFoundDecl();
6383 if (FoundDecl == E->getMemberDecl()) {
6384 FoundDecl = Member;
6385 } else {
6386 FoundDecl = cast_or_null<NamedDecl>(
6387 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6388 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006389 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006390 }
6391
Douglas Gregorb98b1992009-08-11 05:31:07 +00006392 if (!getDerived().AlwaysRebuild() &&
6393 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006394 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006395 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006396 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006397 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006398
Anders Carlsson1f240322009-12-22 05:24:09 +00006399 // Mark it referenced in the new context regardless.
6400 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006401 SemaRef.MarkMemberReferenced(E);
6402
John McCall3fa5cae2010-10-26 07:05:15 +00006403 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006404 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006405
John McCalld5532b62009-11-23 01:53:49 +00006406 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006407 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006408 TransArgs.setLAngleLoc(E->getLAngleLoc());
6409 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006410 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6411 E->getNumTemplateArgs(),
6412 TransArgs))
6413 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006414 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006415
Douglas Gregorb98b1992009-08-11 05:31:07 +00006416 // FIXME: Bogus source location for the operator
6417 SourceLocation FakeOperatorLoc
6418 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6419
John McCallc2233c52010-01-15 08:34:02 +00006420 // FIXME: to do this check properly, we will need to preserve the
6421 // first-qualifier-in-scope here, just in case we had a dependent
6422 // base (and therefore couldn't do the check) and a
6423 // nested-name-qualifier (and therefore could do the lookup).
6424 NamedDecl *FirstQualifierInScope = 0;
6425
John McCall9ae2f072010-08-23 23:25:46 +00006426 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006427 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006428 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006429 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006430 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006431 Member,
John McCall6bb80172010-03-30 21:47:33 +00006432 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006433 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006434 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006435 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006436}
Mike Stump1eb44332009-09-09 15:08:12 +00006437
Douglas Gregorb98b1992009-08-11 05:31:07 +00006438template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006439ExprResult
John McCall454feb92009-12-08 09:21:05 +00006440TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006441 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006442 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006443 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006444
John McCall60d7b3a2010-08-24 06:29:42 +00006445 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006446 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006447 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006448
Douglas Gregorb98b1992009-08-11 05:31:07 +00006449 if (!getDerived().AlwaysRebuild() &&
6450 LHS.get() == E->getLHS() &&
6451 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006452 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006453
Lang Hamesbe9af122012-10-02 04:45:10 +00006454 Sema::FPContractStateRAII FPContractState(getSema());
6455 getSema().FPFeatures.fp_contract = E->isFPContractable();
6456
Douglas Gregorb98b1992009-08-11 05:31:07 +00006457 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006458 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006459}
6460
Mike Stump1eb44332009-09-09 15:08:12 +00006461template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006462ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006463TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006464 CompoundAssignOperator *E) {
6465 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006466}
Mike Stump1eb44332009-09-09 15:08:12 +00006467
Douglas Gregorb98b1992009-08-11 05:31:07 +00006468template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006469ExprResult TreeTransform<Derived>::
6470TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6471 // Just rebuild the common and RHS expressions and see whether we
6472 // get any changes.
6473
6474 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6475 if (commonExpr.isInvalid())
6476 return ExprError();
6477
6478 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6479 if (rhs.isInvalid())
6480 return ExprError();
6481
6482 if (!getDerived().AlwaysRebuild() &&
6483 commonExpr.get() == e->getCommon() &&
6484 rhs.get() == e->getFalseExpr())
6485 return SemaRef.Owned(e);
6486
6487 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6488 e->getQuestionLoc(),
6489 0,
6490 e->getColonLoc(),
6491 rhs.get());
6492}
6493
6494template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006495ExprResult
John McCall454feb92009-12-08 09:21:05 +00006496TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006497 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006498 if (Cond.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 LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006502 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006503 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006504
John McCall60d7b3a2010-08-24 06:29:42 +00006505 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006506 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006507 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006508
Douglas Gregorb98b1992009-08-11 05:31:07 +00006509 if (!getDerived().AlwaysRebuild() &&
6510 Cond.get() == E->getCond() &&
6511 LHS.get() == E->getLHS() &&
6512 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006513 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006514
John McCall9ae2f072010-08-23 23:25:46 +00006515 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006516 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006517 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006518 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006519 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006520}
Mike Stump1eb44332009-09-09 15:08:12 +00006521
6522template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006523ExprResult
John McCall454feb92009-12-08 09:21:05 +00006524TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006525 // Implicit casts are eliminated during transformation, since they
6526 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006527 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006528}
Mike Stump1eb44332009-09-09 15:08:12 +00006529
Douglas Gregorb98b1992009-08-11 05:31:07 +00006530template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006531ExprResult
John McCall454feb92009-12-08 09:21:05 +00006532TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006533 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6534 if (!Type)
6535 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006536
John McCall60d7b3a2010-08-24 06:29:42 +00006537 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006538 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006539 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006540 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006541
Douglas Gregorb98b1992009-08-11 05:31:07 +00006542 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006543 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006544 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006545 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006546
John McCall9d125032010-01-15 18:39:57 +00006547 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006548 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006549 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006550 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006551}
Mike Stump1eb44332009-09-09 15:08:12 +00006552
Douglas Gregorb98b1992009-08-11 05:31:07 +00006553template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006554ExprResult
John McCall454feb92009-12-08 09:21:05 +00006555TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006556 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6557 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6558 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006559 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006560
John McCall60d7b3a2010-08-24 06:29:42 +00006561 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006562 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006563 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006564
Douglas Gregorb98b1992009-08-11 05:31:07 +00006565 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006566 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006567 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006568 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006569
John McCall1d7d8d62010-01-19 22:33:45 +00006570 // Note: the expression type doesn't necessarily match the
6571 // type-as-written, but that's okay, because it should always be
6572 // derivable from the initializer.
6573
John McCall42f56b52010-01-18 19:35:47 +00006574 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006575 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006576 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006577}
Mike Stump1eb44332009-09-09 15:08:12 +00006578
Douglas Gregorb98b1992009-08-11 05:31:07 +00006579template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006580ExprResult
John McCall454feb92009-12-08 09:21:05 +00006581TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006582 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006583 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006584 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006585
Douglas Gregorb98b1992009-08-11 05:31:07 +00006586 if (!getDerived().AlwaysRebuild() &&
6587 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006588 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006589
Douglas Gregorb98b1992009-08-11 05:31:07 +00006590 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006591 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006592 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006593 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006594 E->getAccessorLoc(),
6595 E->getAccessor());
6596}
Mike Stump1eb44332009-09-09 15:08:12 +00006597
Douglas Gregorb98b1992009-08-11 05:31:07 +00006598template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006599ExprResult
John McCall454feb92009-12-08 09:21:05 +00006600TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006601 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006602
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006603 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006604 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006605 Inits, &InitChanged))
6606 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006607
Douglas Gregorb98b1992009-08-11 05:31:07 +00006608 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006609 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006610
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006611 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006612 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006613}
Mike Stump1eb44332009-09-09 15:08:12 +00006614
Douglas Gregorb98b1992009-08-11 05:31:07 +00006615template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006616ExprResult
John McCall454feb92009-12-08 09:21:05 +00006617TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006618 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006619
Douglas Gregor43959a92009-08-20 07:17:43 +00006620 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006621 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006622 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006623 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006624
Douglas Gregor43959a92009-08-20 07:17:43 +00006625 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006626 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006627 bool ExprChanged = false;
6628 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6629 DEnd = E->designators_end();
6630 D != DEnd; ++D) {
6631 if (D->isFieldDesignator()) {
6632 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6633 D->getDotLoc(),
6634 D->getFieldLoc()));
6635 continue;
6636 }
Mike Stump1eb44332009-09-09 15:08:12 +00006637
Douglas Gregorb98b1992009-08-11 05:31:07 +00006638 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006639 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006641 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006642
6643 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006644 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006645
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6647 ArrayExprs.push_back(Index.release());
6648 continue;
6649 }
Mike Stump1eb44332009-09-09 15:08:12 +00006650
Douglas Gregorb98b1992009-08-11 05:31:07 +00006651 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006652 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006653 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6654 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006655 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006656
John McCall60d7b3a2010-08-24 06:29:42 +00006657 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006658 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006659 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006660
6661 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006662 End.get(),
6663 D->getLBracketLoc(),
6664 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006665
Douglas Gregorb98b1992009-08-11 05:31:07 +00006666 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6667 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006668
Douglas Gregorb98b1992009-08-11 05:31:07 +00006669 ArrayExprs.push_back(Start.release());
6670 ArrayExprs.push_back(End.release());
6671 }
Mike Stump1eb44332009-09-09 15:08:12 +00006672
Douglas Gregorb98b1992009-08-11 05:31:07 +00006673 if (!getDerived().AlwaysRebuild() &&
6674 Init.get() == E->getInit() &&
6675 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006676 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006677
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006678 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006679 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006680 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006681}
Mike Stump1eb44332009-09-09 15:08:12 +00006682
Douglas Gregorb98b1992009-08-11 05:31:07 +00006683template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006684ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006685TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006686 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006687 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006688
Douglas Gregor5557b252009-10-28 00:29:27 +00006689 // FIXME: Will we ever have proper type location here? Will we actually
6690 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006691 QualType T = getDerived().TransformType(E->getType());
6692 if (T.isNull())
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 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006697 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006698
Douglas Gregorb98b1992009-08-11 05:31:07 +00006699 return getDerived().RebuildImplicitValueInitExpr(T);
6700}
Mike Stump1eb44332009-09-09 15:08:12 +00006701
Douglas Gregorb98b1992009-08-11 05:31:07 +00006702template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006703ExprResult
John McCall454feb92009-12-08 09:21:05 +00006704TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006705 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6706 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006707 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006708
John McCall60d7b3a2010-08-24 06:29:42 +00006709 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006710 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006711 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006712
Douglas Gregorb98b1992009-08-11 05:31:07 +00006713 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006714 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006715 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006716 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006717
John McCall9ae2f072010-08-23 23:25:46 +00006718 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006719 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006720}
6721
6722template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006723ExprResult
John McCall454feb92009-12-08 09:21:05 +00006724TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006725 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006726 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006727 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6728 &ArgumentChanged))
6729 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006730
Douglas Gregorb98b1992009-08-11 05:31:07 +00006731 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006732 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733 E->getRParenLoc());
6734}
Mike Stump1eb44332009-09-09 15:08:12 +00006735
Douglas Gregorb98b1992009-08-11 05:31:07 +00006736/// \brief Transform an address-of-label expression.
6737///
6738/// By default, the transformation of an address-of-label expression always
6739/// rebuilds the expression, so that the label identifier can be resolved to
6740/// the corresponding label statement by semantic analysis.
6741template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006742ExprResult
John McCall454feb92009-12-08 09:21:05 +00006743TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006744 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6745 E->getLabel());
6746 if (!LD)
6747 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006748
Douglas Gregorb98b1992009-08-11 05:31:07 +00006749 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006750 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006751}
Mike Stump1eb44332009-09-09 15:08:12 +00006752
6753template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006754ExprResult
John McCall454feb92009-12-08 09:21:05 +00006755TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006756 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006757 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006758 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006759 if (SubStmt.isInvalid()) {
6760 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006761 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006762 }
Mike Stump1eb44332009-09-09 15:08:12 +00006763
Douglas Gregorb98b1992009-08-11 05:31:07 +00006764 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006765 SubStmt.get() == E->getSubStmt()) {
6766 // Calling this an 'error' is unintuitive, but it does the right thing.
6767 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006768 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006769 }
Mike Stump1eb44332009-09-09 15:08:12 +00006770
6771 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006772 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006773 E->getRParenLoc());
6774}
Mike Stump1eb44332009-09-09 15:08:12 +00006775
Douglas Gregorb98b1992009-08-11 05:31:07 +00006776template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006777ExprResult
John McCall454feb92009-12-08 09:21:05 +00006778TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006779 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006780 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006781 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006782
John McCall60d7b3a2010-08-24 06:29:42 +00006783 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006784 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006785 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006786
John McCall60d7b3a2010-08-24 06:29:42 +00006787 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006788 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006789 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006790
Douglas Gregorb98b1992009-08-11 05:31:07 +00006791 if (!getDerived().AlwaysRebuild() &&
6792 Cond.get() == E->getCond() &&
6793 LHS.get() == E->getLHS() &&
6794 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006795 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006796
Douglas Gregorb98b1992009-08-11 05:31:07 +00006797 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006798 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006799 E->getRParenLoc());
6800}
Mike Stump1eb44332009-09-09 15:08:12 +00006801
Douglas Gregorb98b1992009-08-11 05:31:07 +00006802template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006803ExprResult
John McCall454feb92009-12-08 09:21:05 +00006804TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006805 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006806}
6807
6808template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006809ExprResult
John McCall454feb92009-12-08 09:21:05 +00006810TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006811 switch (E->getOperator()) {
6812 case OO_New:
6813 case OO_Delete:
6814 case OO_Array_New:
6815 case OO_Array_Delete:
6816 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006817
Douglas Gregor668d6d92009-12-13 20:44:55 +00006818 case OO_Call: {
6819 // This is a call to an object's operator().
6820 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6821
6822 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006823 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006824 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006825 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006826
6827 // FIXME: Poor location information
6828 SourceLocation FakeLParenLoc
6829 = SemaRef.PP.getLocForEndOfToken(
6830 static_cast<Expr *>(Object.get())->getLocEnd());
6831
6832 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006833 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006834 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006835 Args))
6836 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006837
John McCall9ae2f072010-08-23 23:25:46 +00006838 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006839 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006840 E->getLocEnd());
6841 }
6842
6843#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6844 case OO_##Name:
6845#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6846#include "clang/Basic/OperatorKinds.def"
6847 case OO_Subscript:
6848 // Handled below.
6849 break;
6850
6851 case OO_Conditional:
6852 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006853
6854 case OO_None:
6855 case NUM_OVERLOADED_OPERATORS:
6856 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006857 }
6858
John McCall60d7b3a2010-08-24 06:29:42 +00006859 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006860 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006861 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006862
Richard Smithefeeccf2012-10-21 03:28:35 +00006863 ExprResult First;
6864 if (E->getOperator() == OO_Amp)
6865 First = getDerived().TransformAddressOfOperand(E->getArg(0));
6866 else
6867 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006868 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006869 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006870
John McCall60d7b3a2010-08-24 06:29:42 +00006871 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006872 if (E->getNumArgs() == 2) {
6873 Second = getDerived().TransformExpr(E->getArg(1));
6874 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006875 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006876 }
Mike Stump1eb44332009-09-09 15:08:12 +00006877
Douglas Gregorb98b1992009-08-11 05:31:07 +00006878 if (!getDerived().AlwaysRebuild() &&
6879 Callee.get() == E->getCallee() &&
6880 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006881 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006882 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006883
Lang Hamesbe9af122012-10-02 04:45:10 +00006884 Sema::FPContractStateRAII FPContractState(getSema());
6885 getSema().FPFeatures.fp_contract = E->isFPContractable();
6886
Douglas Gregorb98b1992009-08-11 05:31:07 +00006887 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6888 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006889 Callee.get(),
6890 First.get(),
6891 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006892}
Mike Stump1eb44332009-09-09 15:08:12 +00006893
Douglas Gregorb98b1992009-08-11 05:31:07 +00006894template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006895ExprResult
John McCall454feb92009-12-08 09:21:05 +00006896TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6897 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006898}
Mike Stump1eb44332009-09-09 15:08:12 +00006899
Douglas Gregorb98b1992009-08-11 05:31:07 +00006900template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006901ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006902TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6903 // Transform the callee.
6904 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6905 if (Callee.isInvalid())
6906 return ExprError();
6907
6908 // Transform exec config.
6909 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6910 if (EC.isInvalid())
6911 return ExprError();
6912
6913 // Transform arguments.
6914 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006915 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006916 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006917 &ArgChanged))
6918 return ExprError();
6919
6920 if (!getDerived().AlwaysRebuild() &&
6921 Callee.get() == E->getCallee() &&
6922 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006923 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006924
6925 // FIXME: Wrong source location information for the '('.
6926 SourceLocation FakeLParenLoc
6927 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6928 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006929 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006930 E->getRParenLoc(), EC.get());
6931}
6932
6933template<typename Derived>
6934ExprResult
John McCall454feb92009-12-08 09:21:05 +00006935TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006936 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6937 if (!Type)
6938 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006939
John McCall60d7b3a2010-08-24 06:29:42 +00006940 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006941 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006942 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006943 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006944
Douglas Gregorb98b1992009-08-11 05:31:07 +00006945 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006946 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006947 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006948 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006949
Douglas Gregorb98b1992009-08-11 05:31:07 +00006950 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006951 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006952 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6953 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006954 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006955 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006956 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006957 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006958 FakeRAngleLoc,
6959 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006960 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00006961 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006962}
Mike Stump1eb44332009-09-09 15:08:12 +00006963
Douglas Gregorb98b1992009-08-11 05:31:07 +00006964template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006965ExprResult
John McCall454feb92009-12-08 09:21:05 +00006966TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6967 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006968}
Mike Stump1eb44332009-09-09 15:08:12 +00006969
6970template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006971ExprResult
John McCall454feb92009-12-08 09:21:05 +00006972TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6973 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006974}
6975
Douglas Gregorb98b1992009-08-11 05:31:07 +00006976template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006977ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006978TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006979 CXXReinterpretCastExpr *E) {
6980 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006981}
Mike Stump1eb44332009-09-09 15:08:12 +00006982
Douglas Gregorb98b1992009-08-11 05:31:07 +00006983template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006984ExprResult
John McCall454feb92009-12-08 09:21:05 +00006985TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6986 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006987}
Mike Stump1eb44332009-09-09 15:08:12 +00006988
Douglas Gregorb98b1992009-08-11 05:31:07 +00006989template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006990ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006991TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006992 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006993 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6994 if (!Type)
6995 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006996
John McCall60d7b3a2010-08-24 06:29:42 +00006997 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006998 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006999 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007000 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007001
Douglas Gregorb98b1992009-08-11 05:31:07 +00007002 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007003 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007004 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007005 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007006
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007007 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007008 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007009 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007010 E->getRParenLoc());
7011}
Mike Stump1eb44332009-09-09 15:08:12 +00007012
Douglas Gregorb98b1992009-08-11 05:31:07 +00007013template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007014ExprResult
John McCall454feb92009-12-08 09:21:05 +00007015TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007016 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007017 TypeSourceInfo *TInfo
7018 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7019 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007020 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007021
Douglas Gregorb98b1992009-08-11 05:31:07 +00007022 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007023 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007024 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007025
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007026 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7027 E->getLocStart(),
7028 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007029 E->getLocEnd());
7030 }
Mike Stump1eb44332009-09-09 15:08:12 +00007031
Eli Friedmanef331b72012-01-20 01:26:23 +00007032 // We don't know whether the subexpression is potentially evaluated until
7033 // after we perform semantic analysis. We speculatively assume it is
7034 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007035 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007036 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7037 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007038
John McCall60d7b3a2010-08-24 06:29:42 +00007039 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007040 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007041 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007042
Douglas Gregorb98b1992009-08-11 05:31:07 +00007043 if (!getDerived().AlwaysRebuild() &&
7044 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007045 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007046
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007047 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7048 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007049 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007050 E->getLocEnd());
7051}
7052
7053template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007054ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007055TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7056 if (E->isTypeOperand()) {
7057 TypeSourceInfo *TInfo
7058 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7059 if (!TInfo)
7060 return ExprError();
7061
7062 if (!getDerived().AlwaysRebuild() &&
7063 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007064 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007065
Douglas Gregor3c52a212011-03-06 17:40:41 +00007066 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007067 E->getLocStart(),
7068 TInfo,
7069 E->getLocEnd());
7070 }
7071
Francois Pichet01b7c302010-09-08 12:20:18 +00007072 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7073
7074 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7075 if (SubExpr.isInvalid())
7076 return ExprError();
7077
7078 if (!getDerived().AlwaysRebuild() &&
7079 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007080 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007081
7082 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7083 E->getLocStart(),
7084 SubExpr.get(),
7085 E->getLocEnd());
7086}
7087
7088template<typename Derived>
7089ExprResult
John McCall454feb92009-12-08 09:21:05 +00007090TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007091 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007092}
Mike Stump1eb44332009-09-09 15:08:12 +00007093
Douglas Gregorb98b1992009-08-11 05:31:07 +00007094template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007095ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007096TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007097 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007098 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007099}
Mike Stump1eb44332009-09-09 15:08:12 +00007100
Douglas Gregorb98b1992009-08-11 05:31:07 +00007101template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007102ExprResult
John McCall454feb92009-12-08 09:21:05 +00007103TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007104 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007105 QualType T;
7106 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7107 T = MD->getThisType(getSema().Context);
7108 else
7109 T = getSema().Context.getPointerType(
7110 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007111
Douglas Gregorec79d872012-02-24 17:41:38 +00007112 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7113 // Make sure that we capture 'this'.
7114 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007115 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007116 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007117
Douglas Gregor828a1972010-01-07 23:12:05 +00007118 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007119}
Mike Stump1eb44332009-09-09 15:08:12 +00007120
Douglas Gregorb98b1992009-08-11 05:31:07 +00007121template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007122ExprResult
John McCall454feb92009-12-08 09:21:05 +00007123TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007124 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007125 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007126 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007127
Douglas Gregorb98b1992009-08-11 05:31:07 +00007128 if (!getDerived().AlwaysRebuild() &&
7129 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007130 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007131
Douglas Gregorbca01b42011-07-06 22:04:06 +00007132 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7133 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007134}
Mike Stump1eb44332009-09-09 15:08:12 +00007135
Douglas Gregorb98b1992009-08-11 05:31:07 +00007136template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007137ExprResult
John McCall454feb92009-12-08 09:21:05 +00007138TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007139 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007140 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7141 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007142 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007143 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007144
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007145 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007146 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007147 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007148
Douglas Gregor036aed12009-12-23 23:03:06 +00007149 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007150}
Mike Stump1eb44332009-09-09 15:08:12 +00007151
Douglas Gregorb98b1992009-08-11 05:31:07 +00007152template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007153ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007154TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7155 CXXScalarValueInitExpr *E) {
7156 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7157 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007158 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007159
Douglas Gregorb98b1992009-08-11 05:31:07 +00007160 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007161 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007162 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007163
Chad Rosier4a9d7952012-08-08 18:46:20 +00007164 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007165 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007166 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007167}
Mike Stump1eb44332009-09-09 15:08:12 +00007168
Douglas Gregorb98b1992009-08-11 05:31:07 +00007169template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007170ExprResult
John McCall454feb92009-12-08 09:21:05 +00007171TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007172 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007173 TypeSourceInfo *AllocTypeInfo
7174 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7175 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007176 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007177
Douglas Gregorb98b1992009-08-11 05:31:07 +00007178 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007179 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007180 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007181 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007182
Douglas Gregorb98b1992009-08-11 05:31:07 +00007183 // Transform the placement arguments (if any).
7184 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007185 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007186 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007187 E->getNumPlacementArgs(), true,
7188 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007189 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007190
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007191 // Transform the initializer (if any).
7192 Expr *OldInit = E->getInitializer();
7193 ExprResult NewInit;
7194 if (OldInit)
7195 NewInit = getDerived().TransformExpr(OldInit);
7196 if (NewInit.isInvalid())
7197 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007198
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007199 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007200 FunctionDecl *OperatorNew = 0;
7201 if (E->getOperatorNew()) {
7202 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007203 getDerived().TransformDecl(E->getLocStart(),
7204 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007205 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007206 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007207 }
7208
7209 FunctionDecl *OperatorDelete = 0;
7210 if (E->getOperatorDelete()) {
7211 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007212 getDerived().TransformDecl(E->getLocStart(),
7213 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007214 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007215 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007216 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007217
Douglas Gregorb98b1992009-08-11 05:31:07 +00007218 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007219 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007220 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007221 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007222 OperatorNew == E->getOperatorNew() &&
7223 OperatorDelete == E->getOperatorDelete() &&
7224 !ArgumentChanged) {
7225 // Mark any declarations we need as referenced.
7226 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007227 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007228 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007229 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007230 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007231
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007232 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007233 QualType ElementType
7234 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7235 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7236 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7237 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007238 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007239 }
7240 }
7241 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007242
John McCall3fa5cae2010-10-26 07:05:15 +00007243 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007244 }
Mike Stump1eb44332009-09-09 15:08:12 +00007245
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007246 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007247 if (!ArraySize.get()) {
7248 // If no array size was specified, but the new expression was
7249 // instantiated with an array type (e.g., "new T" where T is
7250 // instantiated with "int[4]"), extract the outer bound from the
7251 // array type as our array size. We do this with constant and
7252 // dependently-sized array types.
7253 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7254 if (!ArrayT) {
7255 // Do nothing
7256 } else if (const ConstantArrayType *ConsArrayT
7257 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007258 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007259 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007260 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007261 SemaRef.Context.getSizeType(),
7262 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007263 AllocType = ConsArrayT->getElementType();
7264 } else if (const DependentSizedArrayType *DepArrayT
7265 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7266 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007267 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007268 AllocType = DepArrayT->getElementType();
7269 }
7270 }
7271 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007272
Douglas Gregorb98b1992009-08-11 05:31:07 +00007273 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7274 E->isGlobalNew(),
7275 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007276 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007277 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007278 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007279 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007280 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007281 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007282 E->getDirectInitRange(),
7283 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007284}
Mike Stump1eb44332009-09-09 15:08:12 +00007285
Douglas Gregorb98b1992009-08-11 05:31:07 +00007286template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007287ExprResult
John McCall454feb92009-12-08 09:21:05 +00007288TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007289 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007290 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007291 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007292
Douglas Gregor1af74512010-02-26 00:38:10 +00007293 // Transform the delete operator, if known.
7294 FunctionDecl *OperatorDelete = 0;
7295 if (E->getOperatorDelete()) {
7296 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007297 getDerived().TransformDecl(E->getLocStart(),
7298 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007299 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007300 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007301 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007302
Douglas Gregorb98b1992009-08-11 05:31:07 +00007303 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007304 Operand.get() == E->getArgument() &&
7305 OperatorDelete == E->getOperatorDelete()) {
7306 // Mark any declarations we need as referenced.
7307 // FIXME: instantiation-specific.
7308 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007309 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007310
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007311 if (!E->getArgument()->isTypeDependent()) {
7312 QualType Destroyed = SemaRef.Context.getBaseElementType(
7313 E->getDestroyedType());
7314 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7315 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007316 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007317 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007318 }
7319 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007320
John McCall3fa5cae2010-10-26 07:05:15 +00007321 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007322 }
Mike Stump1eb44332009-09-09 15:08:12 +00007323
Douglas Gregorb98b1992009-08-11 05:31:07 +00007324 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7325 E->isGlobalDelete(),
7326 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007327 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007328}
Mike Stump1eb44332009-09-09 15:08:12 +00007329
Douglas Gregorb98b1992009-08-11 05:31:07 +00007330template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007331ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007332TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007333 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007334 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007335 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007336 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007337
John McCallb3d87482010-08-24 05:47:05 +00007338 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007339 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007340 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007341 E->getOperatorLoc(),
7342 E->isArrow()? tok::arrow : tok::period,
7343 ObjectTypePtr,
7344 MayBePseudoDestructor);
7345 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007346 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007347
John McCallb3d87482010-08-24 05:47:05 +00007348 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007349 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7350 if (QualifierLoc) {
7351 QualifierLoc
7352 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7353 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007354 return ExprError();
7355 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007356 CXXScopeSpec SS;
7357 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007358
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007359 PseudoDestructorTypeStorage Destroyed;
7360 if (E->getDestroyedTypeInfo()) {
7361 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007362 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007363 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007364 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007365 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007366 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007367 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007368 // We aren't likely to be able to resolve the identifier down to a type
7369 // now anyway, so just retain the identifier.
7370 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7371 E->getDestroyedTypeLoc());
7372 } else {
7373 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007374 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007375 *E->getDestroyedTypeIdentifier(),
7376 E->getDestroyedTypeLoc(),
7377 /*Scope=*/0,
7378 SS, ObjectTypePtr,
7379 false);
7380 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007381 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007382
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007383 Destroyed
7384 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7385 E->getDestroyedTypeLoc());
7386 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007387
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007388 TypeSourceInfo *ScopeTypeInfo = 0;
7389 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007390 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007391 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007392 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007393 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007394
John McCall9ae2f072010-08-23 23:25:46 +00007395 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007396 E->getOperatorLoc(),
7397 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007398 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007399 ScopeTypeInfo,
7400 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007401 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007402 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007403}
Mike Stump1eb44332009-09-09 15:08:12 +00007404
Douglas Gregora71d8192009-09-04 17:36:40 +00007405template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007406ExprResult
John McCallba135432009-11-21 08:51:07 +00007407TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007408 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007409 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7410 Sema::LookupOrdinaryName);
7411
7412 // Transform all the decls.
7413 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7414 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007415 NamedDecl *InstD = static_cast<NamedDecl*>(
7416 getDerived().TransformDecl(Old->getNameLoc(),
7417 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007418 if (!InstD) {
7419 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7420 // This can happen because of dependent hiding.
7421 if (isa<UsingShadowDecl>(*I))
7422 continue;
7423 else
John McCallf312b1e2010-08-26 23:41:50 +00007424 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007425 }
John McCallf7a1a742009-11-24 19:00:30 +00007426
7427 // Expand using declarations.
7428 if (isa<UsingDecl>(InstD)) {
7429 UsingDecl *UD = cast<UsingDecl>(InstD);
7430 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7431 E = UD->shadow_end(); I != E; ++I)
7432 R.addDecl(*I);
7433 continue;
7434 }
7435
7436 R.addDecl(InstD);
7437 }
7438
7439 // Resolve a kind, but don't do any further analysis. If it's
7440 // ambiguous, the callee needs to deal with it.
7441 R.resolveKind();
7442
7443 // Rebuild the nested-name qualifier, if present.
7444 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007445 if (Old->getQualifierLoc()) {
7446 NestedNameSpecifierLoc QualifierLoc
7447 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7448 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007449 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007450
Douglas Gregor4c9be892011-02-28 20:01:57 +00007451 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007452 }
7453
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007454 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007455 CXXRecordDecl *NamingClass
7456 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7457 Old->getNameLoc(),
7458 Old->getNamingClass()));
7459 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007460 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007461
Douglas Gregor66c45152010-04-27 16:10:10 +00007462 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007463 }
7464
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007465 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7466
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007467 // If we have neither explicit template arguments, nor the template keyword,
7468 // it's a normal declaration name.
7469 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007470 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7471
7472 // If we have template arguments, rebuild them, then rebuild the
7473 // templateid expression.
7474 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007475 if (Old->hasExplicitTemplateArgs() &&
7476 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007477 Old->getNumTemplateArgs(),
7478 TransArgs))
7479 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007480
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007481 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007482 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007483}
Mike Stump1eb44332009-09-09 15:08:12 +00007484
Douglas Gregorb98b1992009-08-11 05:31:07 +00007485template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007486ExprResult
John McCall454feb92009-12-08 09:21:05 +00007487TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007488 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7489 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007490 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007491
Douglas Gregorb98b1992009-08-11 05:31:07 +00007492 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007493 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007494 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007495
Mike Stump1eb44332009-09-09 15:08:12 +00007496 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007497 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007498 T,
7499 E->getLocEnd());
7500}
Mike Stump1eb44332009-09-09 15:08:12 +00007501
Douglas Gregorb98b1992009-08-11 05:31:07 +00007502template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007503ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007504TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7505 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7506 if (!LhsT)
7507 return ExprError();
7508
7509 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7510 if (!RhsT)
7511 return ExprError();
7512
7513 if (!getDerived().AlwaysRebuild() &&
7514 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7515 return SemaRef.Owned(E);
7516
7517 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7518 E->getLocStart(),
7519 LhsT, RhsT,
7520 E->getLocEnd());
7521}
7522
7523template<typename Derived>
7524ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007525TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7526 bool ArgChanged = false;
7527 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7528 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7529 TypeSourceInfo *From = E->getArg(I);
7530 TypeLoc FromTL = From->getTypeLoc();
7531 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7532 TypeLocBuilder TLB;
7533 TLB.reserve(FromTL.getFullDataSize());
7534 QualType To = getDerived().TransformType(TLB, FromTL);
7535 if (To.isNull())
7536 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007537
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007538 if (To == From->getType())
7539 Args.push_back(From);
7540 else {
7541 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7542 ArgChanged = true;
7543 }
7544 continue;
7545 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007546
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007547 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007548
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007549 // We have a pack expansion. Instantiate it.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007550 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007551 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7552 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7553 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007554
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007555 // Determine whether the set of unexpanded parameter packs can and should
7556 // be expanded.
7557 bool Expand = true;
7558 bool RetainExpansion = false;
7559 llvm::Optional<unsigned> OrigNumExpansions
7560 = ExpansionTL.getTypePtr()->getNumExpansions();
7561 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7562 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7563 PatternTL.getSourceRange(),
7564 Unexpanded,
7565 Expand, RetainExpansion,
7566 NumExpansions))
7567 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007568
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007569 if (!Expand) {
7570 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007571 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007572 // expansion.
7573 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007574
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007575 TypeLocBuilder TLB;
7576 TLB.reserve(From->getTypeLoc().getFullDataSize());
7577
7578 QualType To = getDerived().TransformType(TLB, PatternTL);
7579 if (To.isNull())
7580 return ExprError();
7581
Chad Rosier4a9d7952012-08-08 18:46:20 +00007582 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007583 PatternTL.getSourceRange(),
7584 ExpansionTL.getEllipsisLoc(),
7585 NumExpansions);
7586 if (To.isNull())
7587 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007588
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007589 PackExpansionTypeLoc ToExpansionTL
7590 = TLB.push<PackExpansionTypeLoc>(To);
7591 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7592 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7593 continue;
7594 }
7595
7596 // Expand the pack expansion by substituting for each argument in the
7597 // pack(s).
7598 for (unsigned I = 0; I != *NumExpansions; ++I) {
7599 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7600 TypeLocBuilder TLB;
7601 TLB.reserve(PatternTL.getFullDataSize());
7602 QualType To = getDerived().TransformType(TLB, PatternTL);
7603 if (To.isNull())
7604 return ExprError();
7605
7606 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7607 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007608
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007609 if (!RetainExpansion)
7610 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007611
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007612 // If we're supposed to retain a pack expansion, do so by temporarily
7613 // forgetting the partially-substituted parameter pack.
7614 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7615
7616 TypeLocBuilder TLB;
7617 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007618
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007619 QualType To = getDerived().TransformType(TLB, PatternTL);
7620 if (To.isNull())
7621 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007622
7623 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007624 PatternTL.getSourceRange(),
7625 ExpansionTL.getEllipsisLoc(),
7626 NumExpansions);
7627 if (To.isNull())
7628 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007629
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007630 PackExpansionTypeLoc ToExpansionTL
7631 = TLB.push<PackExpansionTypeLoc>(To);
7632 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7633 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7634 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007635
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007636 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7637 return SemaRef.Owned(E);
7638
7639 return getDerived().RebuildTypeTrait(E->getTrait(),
7640 E->getLocStart(),
7641 Args,
7642 E->getLocEnd());
7643}
7644
7645template<typename Derived>
7646ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007647TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7648 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7649 if (!T)
7650 return ExprError();
7651
7652 if (!getDerived().AlwaysRebuild() &&
7653 T == E->getQueriedTypeSourceInfo())
7654 return SemaRef.Owned(E);
7655
7656 ExprResult SubExpr;
7657 {
7658 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7659 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7660 if (SubExpr.isInvalid())
7661 return ExprError();
7662
7663 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7664 return SemaRef.Owned(E);
7665 }
7666
7667 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7668 E->getLocStart(),
7669 T,
7670 SubExpr.get(),
7671 E->getLocEnd());
7672}
7673
7674template<typename Derived>
7675ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007676TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7677 ExprResult SubExpr;
7678 {
7679 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7680 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7681 if (SubExpr.isInvalid())
7682 return ExprError();
7683
7684 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7685 return SemaRef.Owned(E);
7686 }
7687
7688 return getDerived().RebuildExpressionTrait(
7689 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7690}
7691
7692template<typename Derived>
7693ExprResult
John McCall865d4472009-11-19 22:55:06 +00007694TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007695 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00007696 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
7697}
7698
7699template<typename Derived>
7700ExprResult
7701TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7702 DependentScopeDeclRefExpr *E,
7703 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007704 NestedNameSpecifierLoc QualifierLoc
7705 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7706 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007707 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007708 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007709
John McCall43fed0d2010-11-12 08:19:04 +00007710 // TODO: If this is a conversion-function-id, verify that the
7711 // destination type name (if present) resolves the same way after
7712 // instantiation as it did in the local scope.
7713
Abramo Bagnara25777432010-08-11 22:01:17 +00007714 DeclarationNameInfo NameInfo
7715 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7716 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007717 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007718
John McCallf7a1a742009-11-24 19:00:30 +00007719 if (!E->hasExplicitTemplateArgs()) {
7720 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007721 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007722 // Note: it is sufficient to compare the Name component of NameInfo:
7723 // if name has not changed, DNLoc has not changed either.
7724 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007725 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007726
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007727 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007728 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007729 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007730 /*TemplateArgs*/ 0,
7731 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007732 }
John McCalld5532b62009-11-23 01:53:49 +00007733
7734 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007735 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7736 E->getNumTemplateArgs(),
7737 TransArgs))
7738 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007739
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007740 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007741 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007742 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007743 &TransArgs,
7744 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007745}
7746
7747template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007748ExprResult
John McCall454feb92009-12-08 09:21:05 +00007749TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007750 // CXXConstructExprs are always implicit, so when we have a
7751 // 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00007752 if ((E->getNumArgs() == 1 ||
7753 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
7754 (!getDerived().DropCallArgument(E->getArg(0))))
Douglas Gregor321725d2010-02-03 03:01:57 +00007755 return getDerived().TransformExpr(E->getArg(0));
7756
Douglas Gregorb98b1992009-08-11 05:31:07 +00007757 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7758
7759 QualType T = getDerived().TransformType(E->getType());
7760 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007761 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007762
7763 CXXConstructorDecl *Constructor
7764 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007765 getDerived().TransformDecl(E->getLocStart(),
7766 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007767 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007768 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007769
Douglas Gregorb98b1992009-08-11 05:31:07 +00007770 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007771 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007772 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007773 &ArgumentChanged))
7774 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007775
Douglas Gregorb98b1992009-08-11 05:31:07 +00007776 if (!getDerived().AlwaysRebuild() &&
7777 T == E->getType() &&
7778 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007779 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007780 // Mark the constructor as referenced.
7781 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007782 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007783 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007784 }
Mike Stump1eb44332009-09-09 15:08:12 +00007785
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007786 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7787 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007788 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007789 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007790 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007791 E->getConstructionKind(),
7792 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007793}
Mike Stump1eb44332009-09-09 15:08:12 +00007794
Douglas Gregorb98b1992009-08-11 05:31:07 +00007795/// \brief Transform a C++ temporary-binding expression.
7796///
Douglas Gregor51326552009-12-24 18:51:59 +00007797/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7798/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007799template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007800ExprResult
John McCall454feb92009-12-08 09:21:05 +00007801TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007802 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007803}
Mike Stump1eb44332009-09-09 15:08:12 +00007804
John McCall4765fa02010-12-06 08:20:24 +00007805/// \brief Transform a C++ expression that contains cleanups that should
7806/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007807///
John McCall4765fa02010-12-06 08:20:24 +00007808/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007809/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007810template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007811ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007812TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007813 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007814}
Mike Stump1eb44332009-09-09 15:08:12 +00007815
Douglas Gregorb98b1992009-08-11 05:31:07 +00007816template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007817ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007818TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007819 CXXTemporaryObjectExpr *E) {
7820 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7821 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007822 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007823
Douglas Gregorb98b1992009-08-11 05:31:07 +00007824 CXXConstructorDecl *Constructor
7825 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007826 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007827 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007828 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007829 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007830
Douglas Gregorb98b1992009-08-11 05:31:07 +00007831 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007832 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007833 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007834 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007835 &ArgumentChanged))
7836 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007837
Douglas Gregorb98b1992009-08-11 05:31:07 +00007838 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007839 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007840 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007841 !ArgumentChanged) {
7842 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007843 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007844 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007845 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007846
Douglas Gregorab6677e2010-09-08 00:15:04 +00007847 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7848 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007849 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007850 E->getLocEnd());
7851}
Mike Stump1eb44332009-09-09 15:08:12 +00007852
Douglas Gregorb98b1992009-08-11 05:31:07 +00007853template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007854ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007855TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007856 // Transform the type of the lambda parameters and start the definition of
7857 // the lambda itself.
7858 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00007859 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00007860 if (!MethodTy)
7861 return ExprError();
7862
Eli Friedman8da8a662012-09-19 01:18:11 +00007863 // Create the local class that will describe the lambda.
7864 CXXRecordDecl *Class
7865 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7866 MethodTy,
7867 /*KnownDependent=*/false);
7868 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7869
Douglas Gregorc6889e72012-02-14 22:28:59 +00007870 // Transform lambda parameters.
Douglas Gregorc6889e72012-02-14 22:28:59 +00007871 llvm::SmallVector<QualType, 4> ParamTypes;
7872 llvm::SmallVector<ParmVarDecl *, 4> Params;
7873 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7874 E->getCallOperator()->param_begin(),
7875 E->getCallOperator()->param_size(),
7876 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00007877 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00007878
Douglas Gregordfca6f52012-02-13 22:00:16 +00007879 // Build the call operator.
7880 CXXMethodDecl *CallOperator
7881 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007882 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007883 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007884 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007885 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00007886
Richard Smith612409e2012-07-25 03:56:55 +00007887 return getDerived().TransformLambdaScope(E, CallOperator);
7888}
7889
7890template<typename Derived>
7891ExprResult
7892TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
7893 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00007894 // Introduce the context of the call operator.
7895 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7896
Douglas Gregordfca6f52012-02-13 22:00:16 +00007897 // Enter the scope of the lambda.
7898 sema::LambdaScopeInfo *LSI
7899 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7900 E->getCaptureDefault(),
7901 E->hasExplicitParameters(),
7902 E->hasExplicitResultType(),
7903 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007904
Douglas Gregordfca6f52012-02-13 22:00:16 +00007905 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00007906 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00007907 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007908 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007909 CEnd = E->capture_end();
7910 C != CEnd; ++C) {
7911 // When we hit the first implicit capture, tell Sema that we've finished
7912 // the list of explicit captures.
7913 if (!FinishedExplicitCaptures && C->isImplicit()) {
7914 getSema().finishLambdaExplicitCaptures(LSI);
7915 FinishedExplicitCaptures = true;
7916 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007917
Douglas Gregordfca6f52012-02-13 22:00:16 +00007918 // Capturing 'this' is trivial.
7919 if (C->capturesThis()) {
7920 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7921 continue;
7922 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007923
Douglas Gregora7365242012-02-14 19:27:52 +00007924 // Determine the capture kind for Sema.
7925 Sema::TryCaptureKind Kind
7926 = C->isImplicit()? Sema::TryCapture_Implicit
7927 : C->getCaptureKind() == LCK_ByCopy
7928 ? Sema::TryCapture_ExplicitByVal
7929 : Sema::TryCapture_ExplicitByRef;
7930 SourceLocation EllipsisLoc;
7931 if (C->isPackExpansion()) {
7932 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7933 bool ShouldExpand = false;
7934 bool RetainExpansion = false;
7935 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007936 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7937 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00007938 Unexpanded,
7939 ShouldExpand, RetainExpansion,
7940 NumExpansions))
7941 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007942
Douglas Gregora7365242012-02-14 19:27:52 +00007943 if (ShouldExpand) {
7944 // The transform has determined that we should perform an expansion;
7945 // transform and capture each of the arguments.
7946 // expansion of the pattern. Do so.
7947 VarDecl *Pack = C->getCapturedVar();
7948 for (unsigned I = 0; I != *NumExpansions; ++I) {
7949 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7950 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00007951 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00007952 Pack));
7953 if (!CapturedVar) {
7954 Invalid = true;
7955 continue;
7956 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007957
Douglas Gregora7365242012-02-14 19:27:52 +00007958 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007959 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
7960 }
Douglas Gregora7365242012-02-14 19:27:52 +00007961 continue;
7962 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007963
Douglas Gregora7365242012-02-14 19:27:52 +00007964 EllipsisLoc = C->getEllipsisLoc();
7965 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007966
Douglas Gregordfca6f52012-02-13 22:00:16 +00007967 // Transform the captured variable.
7968 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00007969 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007970 C->getCapturedVar()));
7971 if (!CapturedVar) {
7972 Invalid = true;
7973 continue;
7974 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007975
Douglas Gregordfca6f52012-02-13 22:00:16 +00007976 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007977 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007978 }
7979 if (!FinishedExplicitCaptures)
7980 getSema().finishLambdaExplicitCaptures(LSI);
7981
Douglas Gregordfca6f52012-02-13 22:00:16 +00007982
7983 // Enter a new evaluation context to insulate the lambda from any
7984 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007985 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007986
7987 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007988 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00007989 /*IsInstantiation=*/true);
7990 return ExprError();
7991 }
7992
7993 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00007994 StmtResult Body = getDerived().TransformStmt(E->getBody());
7995 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007996 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00007997 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007998 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00007999 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008000
Chad Rosier4a9d7952012-08-08 18:46:20 +00008001 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008002 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008003}
8004
8005template<typename Derived>
8006ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008007TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008008 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008009 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8010 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008011 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008012
Douglas Gregorb98b1992009-08-11 05:31:07 +00008013 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008014 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008015 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008016 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008017 &ArgumentChanged))
8018 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008019
Douglas Gregorb98b1992009-08-11 05:31:07 +00008020 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008021 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008022 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008023 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008024
Douglas Gregorb98b1992009-08-11 05:31:07 +00008025 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008026 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008027 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008028 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008029 E->getRParenLoc());
8030}
Mike Stump1eb44332009-09-09 15:08:12 +00008031
Douglas Gregorb98b1992009-08-11 05:31:07 +00008032template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008033ExprResult
John McCall865d4472009-11-19 22:55:06 +00008034TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008035 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008036 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008037 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008038 Expr *OldBase;
8039 QualType BaseType;
8040 QualType ObjectType;
8041 if (!E->isImplicitAccess()) {
8042 OldBase = E->getBase();
8043 Base = getDerived().TransformExpr(OldBase);
8044 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008045 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008046
John McCallaa81e162009-12-01 22:10:20 +00008047 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008048 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008049 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008050 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008051 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008052 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008053 ObjectTy,
8054 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008055 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008056 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008057
John McCallb3d87482010-08-24 05:47:05 +00008058 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008059 BaseType = ((Expr*) Base.get())->getType();
8060 } else {
8061 OldBase = 0;
8062 BaseType = getDerived().TransformType(E->getBaseType());
8063 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8064 }
Mike Stump1eb44332009-09-09 15:08:12 +00008065
Douglas Gregor6cd21982009-10-20 05:58:46 +00008066 // Transform the first part of the nested-name-specifier that qualifies
8067 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008068 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008069 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008070 E->getFirstQualifierFoundInScope(),
8071 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008072
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008073 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008074 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008075 QualifierLoc
8076 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8077 ObjectType,
8078 FirstQualifierInScope);
8079 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008080 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008081 }
Mike Stump1eb44332009-09-09 15:08:12 +00008082
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008083 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8084
John McCall43fed0d2010-11-12 08:19:04 +00008085 // TODO: If this is a conversion-function-id, verify that the
8086 // destination type name (if present) resolves the same way after
8087 // instantiation as it did in the local scope.
8088
Abramo Bagnara25777432010-08-11 22:01:17 +00008089 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008090 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008091 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008092 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008093
John McCallaa81e162009-12-01 22:10:20 +00008094 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008095 // This is a reference to a member without an explicitly-specified
8096 // template argument list. Optimize for this common case.
8097 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008098 Base.get() == OldBase &&
8099 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008100 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008101 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008102 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008103 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008104
John McCall9ae2f072010-08-23 23:25:46 +00008105 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008106 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008107 E->isArrow(),
8108 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008109 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008110 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008111 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008112 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008113 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008114 }
8115
John McCalld5532b62009-11-23 01:53:49 +00008116 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008117 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8118 E->getNumTemplateArgs(),
8119 TransArgs))
8120 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008121
John McCall9ae2f072010-08-23 23:25:46 +00008122 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008123 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008124 E->isArrow(),
8125 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008126 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008127 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008128 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008129 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008130 &TransArgs);
8131}
8132
8133template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008134ExprResult
John McCall454feb92009-12-08 09:21:05 +00008135TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008136 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008137 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008138 QualType BaseType;
8139 if (!Old->isImplicitAccess()) {
8140 Base = getDerived().TransformExpr(Old->getBase());
8141 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008142 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008143 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8144 Old->isArrow());
8145 if (Base.isInvalid())
8146 return ExprError();
8147 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008148 } else {
8149 BaseType = getDerived().TransformType(Old->getBaseType());
8150 }
John McCall129e2df2009-11-30 22:42:35 +00008151
Douglas Gregor4c9be892011-02-28 20:01:57 +00008152 NestedNameSpecifierLoc QualifierLoc;
8153 if (Old->getQualifierLoc()) {
8154 QualifierLoc
8155 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8156 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008157 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008158 }
8159
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008160 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8161
Abramo Bagnara25777432010-08-11 22:01:17 +00008162 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008163 Sema::LookupOrdinaryName);
8164
8165 // Transform all the decls.
8166 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8167 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008168 NamedDecl *InstD = static_cast<NamedDecl*>(
8169 getDerived().TransformDecl(Old->getMemberLoc(),
8170 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008171 if (!InstD) {
8172 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8173 // This can happen because of dependent hiding.
8174 if (isa<UsingShadowDecl>(*I))
8175 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008176 else {
8177 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008178 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008179 }
John McCall9f54ad42009-12-10 09:41:52 +00008180 }
John McCall129e2df2009-11-30 22:42:35 +00008181
8182 // Expand using declarations.
8183 if (isa<UsingDecl>(InstD)) {
8184 UsingDecl *UD = cast<UsingDecl>(InstD);
8185 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8186 E = UD->shadow_end(); I != E; ++I)
8187 R.addDecl(*I);
8188 continue;
8189 }
8190
8191 R.addDecl(InstD);
8192 }
8193
8194 R.resolveKind();
8195
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008196 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008197 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008198 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008199 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008200 Old->getMemberLoc(),
8201 Old->getNamingClass()));
8202 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008203 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008204
Douglas Gregor66c45152010-04-27 16:10:10 +00008205 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008206 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008207
John McCall129e2df2009-11-30 22:42:35 +00008208 TemplateArgumentListInfo TransArgs;
8209 if (Old->hasExplicitTemplateArgs()) {
8210 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8211 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008212 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8213 Old->getNumTemplateArgs(),
8214 TransArgs))
8215 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008216 }
John McCallc2233c52010-01-15 08:34:02 +00008217
8218 // FIXME: to do this check properly, we will need to preserve the
8219 // first-qualifier-in-scope here, just in case we had a dependent
8220 // base (and therefore couldn't do the check) and a
8221 // nested-name-qualifier (and therefore could do the lookup).
8222 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008223
John McCall9ae2f072010-08-23 23:25:46 +00008224 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008225 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008226 Old->getOperatorLoc(),
8227 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008228 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008229 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008230 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008231 R,
8232 (Old->hasExplicitTemplateArgs()
8233 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008234}
8235
8236template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008237ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008238TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008239 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008240 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8241 if (SubExpr.isInvalid())
8242 return ExprError();
8243
8244 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008245 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008246
8247 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8248}
8249
8250template<typename Derived>
8251ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008252TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008253 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8254 if (Pattern.isInvalid())
8255 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008256
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008257 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8258 return SemaRef.Owned(E);
8259
Douglas Gregor67fd1252011-01-14 21:20:45 +00008260 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8261 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008262}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008263
8264template<typename Derived>
8265ExprResult
8266TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8267 // If E is not value-dependent, then nothing will change when we transform it.
8268 // Note: This is an instantiation-centric view.
8269 if (!E->isValueDependent())
8270 return SemaRef.Owned(E);
8271
8272 // Note: None of the implementations of TryExpandParameterPacks can ever
8273 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008274 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008275 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8276 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008277 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008278 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008279 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008280 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008281 ShouldExpand, RetainExpansion,
8282 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008283 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008284
Douglas Gregor089e8932011-10-10 18:59:29 +00008285 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008286 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008287
Douglas Gregor089e8932011-10-10 18:59:29 +00008288 NamedDecl *Pack = E->getPack();
8289 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008290 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008291 Pack));
8292 if (!Pack)
8293 return ExprError();
8294 }
8295
Chad Rosier4a9d7952012-08-08 18:46:20 +00008296
Douglas Gregoree8aff02011-01-04 17:33:58 +00008297 // We now know the length of the parameter pack, so build a new expression
8298 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008299 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8300 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008301 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008302}
8303
Douglas Gregorbe230c32011-01-03 17:17:50 +00008304template<typename Derived>
8305ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008306TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8307 SubstNonTypeTemplateParmPackExpr *E) {
8308 // Default behavior is to do nothing with this transformation.
8309 return SemaRef.Owned(E);
8310}
8311
8312template<typename Derived>
8313ExprResult
John McCall91a57552011-07-15 05:09:51 +00008314TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8315 SubstNonTypeTemplateParmExpr *E) {
8316 // Default behavior is to do nothing with this transformation.
8317 return SemaRef.Owned(E);
8318}
8319
8320template<typename Derived>
8321ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008322TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8323 // Default behavior is to do nothing with this transformation.
8324 return SemaRef.Owned(E);
8325}
8326
8327template<typename Derived>
8328ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008329TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8330 MaterializeTemporaryExpr *E) {
8331 return getDerived().TransformExpr(E->GetTemporaryExpr());
8332}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008333
Douglas Gregor03e80032011-06-21 17:03:29 +00008334template<typename Derived>
8335ExprResult
John McCall454feb92009-12-08 09:21:05 +00008336TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008337 return SemaRef.MaybeBindToTemporary(E);
8338}
8339
8340template<typename Derived>
8341ExprResult
8342TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008343 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008344}
8345
8346template<typename Derived>
8347ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008348TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8349 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8350 if (SubExpr.isInvalid())
8351 return ExprError();
8352
8353 if (!getDerived().AlwaysRebuild() &&
8354 SubExpr.get() == E->getSubExpr())
8355 return SemaRef.Owned(E);
8356
8357 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008358}
8359
8360template<typename Derived>
8361ExprResult
8362TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8363 // Transform each of the elements.
8364 llvm::SmallVector<Expr *, 8> Elements;
8365 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008366 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008367 /*IsCall=*/false, Elements, &ArgChanged))
8368 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008369
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008370 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8371 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008372
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008373 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8374 Elements.data(),
8375 Elements.size());
8376}
8377
8378template<typename Derived>
8379ExprResult
8380TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008381 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008382 // Transform each of the elements.
8383 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8384 bool ArgChanged = false;
8385 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8386 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008387
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008388 if (OrigElement.isPackExpansion()) {
8389 // This key/value element is a pack expansion.
8390 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8391 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8392 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8393 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8394
8395 // Determine whether the set of unexpanded parameter packs can
8396 // and should be expanded.
8397 bool Expand = true;
8398 bool RetainExpansion = false;
8399 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8400 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8401 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8402 OrigElement.Value->getLocEnd());
8403 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8404 PatternRange,
8405 Unexpanded,
8406 Expand, RetainExpansion,
8407 NumExpansions))
8408 return ExprError();
8409
8410 if (!Expand) {
8411 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008412 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008413 // expansion.
8414 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8415 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8416 if (Key.isInvalid())
8417 return ExprError();
8418
8419 if (Key.get() != OrigElement.Key)
8420 ArgChanged = true;
8421
8422 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8423 if (Value.isInvalid())
8424 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008425
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008426 if (Value.get() != OrigElement.Value)
8427 ArgChanged = true;
8428
Chad Rosier4a9d7952012-08-08 18:46:20 +00008429 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008430 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8431 };
8432 Elements.push_back(Expansion);
8433 continue;
8434 }
8435
8436 // Record right away that the argument was changed. This needs
8437 // to happen even if the array expands to nothing.
8438 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008439
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008440 // The transform has determined that we should perform an elementwise
8441 // expansion of the pattern. Do so.
8442 for (unsigned I = 0; I != *NumExpansions; ++I) {
8443 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8444 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8445 if (Key.isInvalid())
8446 return ExprError();
8447
8448 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8449 if (Value.isInvalid())
8450 return ExprError();
8451
Chad Rosier4a9d7952012-08-08 18:46:20 +00008452 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008453 Key.get(), Value.get(), SourceLocation(), NumExpansions
8454 };
8455
8456 // If any unexpanded parameter packs remain, we still have a
8457 // pack expansion.
8458 if (Key.get()->containsUnexpandedParameterPack() ||
8459 Value.get()->containsUnexpandedParameterPack())
8460 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008461
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008462 Elements.push_back(Element);
8463 }
8464
8465 // We've finished with this pack expansion.
8466 continue;
8467 }
8468
8469 // Transform and check key.
8470 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8471 if (Key.isInvalid())
8472 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008473
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008474 if (Key.get() != OrigElement.Key)
8475 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008476
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008477 // Transform and check value.
8478 ExprResult Value
8479 = getDerived().TransformExpr(OrigElement.Value);
8480 if (Value.isInvalid())
8481 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008482
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008483 if (Value.get() != OrigElement.Value)
8484 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008485
8486 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008487 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8488 };
8489 Elements.push_back(Element);
8490 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008491
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008492 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8493 return SemaRef.MaybeBindToTemporary(E);
8494
8495 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8496 Elements.data(),
8497 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008498}
8499
Mike Stump1eb44332009-09-09 15:08:12 +00008500template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008501ExprResult
John McCall454feb92009-12-08 09:21:05 +00008502TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008503 TypeSourceInfo *EncodedTypeInfo
8504 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8505 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008506 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008507
Douglas Gregorb98b1992009-08-11 05:31:07 +00008508 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008509 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008510 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008511
8512 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008513 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008514 E->getRParenLoc());
8515}
Mike Stump1eb44332009-09-09 15:08:12 +00008516
Douglas Gregorb98b1992009-08-11 05:31:07 +00008517template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008518ExprResult TreeTransform<Derived>::
8519TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8520 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8521 if (result.isInvalid()) return ExprError();
8522 Expr *subExpr = result.take();
8523
8524 if (!getDerived().AlwaysRebuild() &&
8525 subExpr == E->getSubExpr())
8526 return SemaRef.Owned(E);
8527
8528 return SemaRef.Owned(new(SemaRef.Context)
8529 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8530}
8531
8532template<typename Derived>
8533ExprResult TreeTransform<Derived>::
8534TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008535 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008536 = getDerived().TransformType(E->getTypeInfoAsWritten());
8537 if (!TSInfo)
8538 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008539
John McCallf85e1932011-06-15 23:02:42 +00008540 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008541 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008542 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008543
John McCallf85e1932011-06-15 23:02:42 +00008544 if (!getDerived().AlwaysRebuild() &&
8545 TSInfo == E->getTypeInfoAsWritten() &&
8546 Result.get() == E->getSubExpr())
8547 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008548
John McCallf85e1932011-06-15 23:02:42 +00008549 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008550 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008551 Result.get());
8552}
8553
8554template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008555ExprResult
John McCall454feb92009-12-08 09:21:05 +00008556TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008557 // Transform arguments.
8558 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008559 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008560 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008561 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008562 &ArgChanged))
8563 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008564
Douglas Gregor92e986e2010-04-22 16:44:27 +00008565 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8566 // Class message: transform the receiver type.
8567 TypeSourceInfo *ReceiverTypeInfo
8568 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8569 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008570 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008571
Douglas Gregor92e986e2010-04-22 16:44:27 +00008572 // If nothing changed, just retain the existing message send.
8573 if (!getDerived().AlwaysRebuild() &&
8574 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008575 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008576
8577 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008578 SmallVector<SourceLocation, 16> SelLocs;
8579 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008580 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8581 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008582 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008583 E->getMethodDecl(),
8584 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008585 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008586 E->getRightLoc());
8587 }
8588
8589 // Instance message: transform the receiver
8590 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8591 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008592 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008593 = getDerived().TransformExpr(E->getInstanceReceiver());
8594 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008595 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008596
8597 // If nothing changed, just retain the existing message send.
8598 if (!getDerived().AlwaysRebuild() &&
8599 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008600 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008601
Douglas Gregor92e986e2010-04-22 16:44:27 +00008602 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008603 SmallVector<SourceLocation, 16> SelLocs;
8604 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008605 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008606 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008607 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008608 E->getMethodDecl(),
8609 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008610 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008611 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008612}
8613
Mike Stump1eb44332009-09-09 15:08:12 +00008614template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008615ExprResult
John McCall454feb92009-12-08 09:21:05 +00008616TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008617 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008618}
8619
Mike Stump1eb44332009-09-09 15:08:12 +00008620template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008621ExprResult
John McCall454feb92009-12-08 09:21:05 +00008622TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008623 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008624}
8625
Mike Stump1eb44332009-09-09 15:08:12 +00008626template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008627ExprResult
John McCall454feb92009-12-08 09:21:05 +00008628TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008629 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008630 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008631 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008632 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008633
8634 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008635
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008636 // If nothing changed, just retain the existing expression.
8637 if (!getDerived().AlwaysRebuild() &&
8638 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008639 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008640
John McCall9ae2f072010-08-23 23:25:46 +00008641 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008642 E->getLocation(),
8643 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008644}
8645
Mike Stump1eb44332009-09-09 15:08:12 +00008646template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008647ExprResult
John McCall454feb92009-12-08 09:21:05 +00008648TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008649 // 'super' and types never change. Property never changes. Just
8650 // retain the existing expression.
8651 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008652 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008653
Douglas Gregore3303542010-04-26 20:47:02 +00008654 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008655 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008656 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008657 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008658
Douglas Gregore3303542010-04-26 20:47:02 +00008659 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008660
Douglas Gregore3303542010-04-26 20:47:02 +00008661 // If nothing changed, just retain the existing expression.
8662 if (!getDerived().AlwaysRebuild() &&
8663 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008664 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008665
John McCall12f78a62010-12-02 01:19:52 +00008666 if (E->isExplicitProperty())
8667 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8668 E->getExplicitProperty(),
8669 E->getLocation());
8670
8671 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008672 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008673 E->getImplicitPropertyGetter(),
8674 E->getImplicitPropertySetter(),
8675 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008676}
8677
Mike Stump1eb44332009-09-09 15:08:12 +00008678template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008679ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008680TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8681 // Transform the base expression.
8682 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8683 if (Base.isInvalid())
8684 return ExprError();
8685
8686 // Transform the key expression.
8687 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8688 if (Key.isInvalid())
8689 return ExprError();
8690
8691 // If nothing changed, just retain the existing expression.
8692 if (!getDerived().AlwaysRebuild() &&
8693 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8694 return SemaRef.Owned(E);
8695
Chad Rosier4a9d7952012-08-08 18:46:20 +00008696 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008697 Base.get(), Key.get(),
8698 E->getAtIndexMethodDecl(),
8699 E->setAtIndexMethodDecl());
8700}
8701
8702template<typename Derived>
8703ExprResult
John McCall454feb92009-12-08 09:21:05 +00008704TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008705 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008706 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008707 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008708 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008709
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008710 // If nothing changed, just retain the existing expression.
8711 if (!getDerived().AlwaysRebuild() &&
8712 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008713 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008714
John McCall9ae2f072010-08-23 23:25:46 +00008715 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008716 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008717}
8718
Mike Stump1eb44332009-09-09 15:08:12 +00008719template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008720ExprResult
John McCall454feb92009-12-08 09:21:05 +00008721TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008722 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008723 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008724 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008725 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008726 SubExprs, &ArgumentChanged))
8727 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008728
Douglas Gregorb98b1992009-08-11 05:31:07 +00008729 if (!getDerived().AlwaysRebuild() &&
8730 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008731 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008732
Douglas Gregorb98b1992009-08-11 05:31:07 +00008733 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008734 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008735 E->getRParenLoc());
8736}
8737
Mike Stump1eb44332009-09-09 15:08:12 +00008738template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008739ExprResult
John McCall454feb92009-12-08 09:21:05 +00008740TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008741 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008742
John McCallc6ac9c32011-02-04 18:33:18 +00008743 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8744 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8745
8746 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008747 blockScope->TheDecl->setBlockMissingReturnType(
8748 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008749
Chris Lattner686775d2011-07-20 06:58:45 +00008750 SmallVector<ParmVarDecl*, 4> params;
8751 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008752
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008753 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008754 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8755 oldBlock->param_begin(),
8756 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008757 0, paramTypes, &params)) {
8758 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008759 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008760 }
John McCallc6ac9c32011-02-04 18:33:18 +00008761
8762 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008763 QualType exprResultType =
8764 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008765
8766 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008767 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008768 getSema().Diag(E->getCaretLocation(),
8769 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008770 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008771 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008772 return ExprError();
8773 }
John McCall711c52b2011-01-05 12:14:39 +00008774
John McCallc6ac9c32011-02-04 18:33:18 +00008775 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008776 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008777 paramTypes.data(),
8778 paramTypes.size(),
8779 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008780 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008781 exprFunctionType->getExtInfo());
8782 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008783
8784 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008785 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008786 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008787
8788 if (!oldBlock->blockMissingReturnType()) {
8789 blockScope->HasImplicitReturnType = false;
8790 blockScope->ReturnType = exprResultType;
8791 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008792
John McCall711c52b2011-01-05 12:14:39 +00008793 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008794 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008795 if (body.isInvalid()) {
8796 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008797 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008798 }
John McCall711c52b2011-01-05 12:14:39 +00008799
John McCallc6ac9c32011-02-04 18:33:18 +00008800#ifndef NDEBUG
8801 // In builds with assertions, make sure that we captured everything we
8802 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008803 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8804 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8805 e = oldBlock->capture_end(); i != e; ++i) {
8806 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008807
Douglas Gregorfc921372011-05-20 15:32:55 +00008808 // Ignore parameter packs.
8809 if (isa<ParmVarDecl>(oldCapture) &&
8810 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8811 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008812
Douglas Gregorfc921372011-05-20 15:32:55 +00008813 VarDecl *newCapture =
8814 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8815 oldCapture));
8816 assert(blockScope->CaptureMap.count(newCapture));
8817 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008818 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008819 }
8820#endif
8821
8822 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8823 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008824}
8825
Mike Stump1eb44332009-09-09 15:08:12 +00008826template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008827ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008828TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008829 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008830}
Eli Friedman276b0612011-10-11 02:20:01 +00008831
8832template<typename Derived>
8833ExprResult
8834TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008835 QualType RetTy = getDerived().TransformType(E->getType());
8836 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008837 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008838 SubExprs.reserve(E->getNumSubExprs());
8839 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8840 SubExprs, &ArgumentChanged))
8841 return ExprError();
8842
8843 if (!getDerived().AlwaysRebuild() &&
8844 !ArgumentChanged)
8845 return SemaRef.Owned(E);
8846
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008847 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008848 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008849}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008850
Douglas Gregorb98b1992009-08-11 05:31:07 +00008851//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008852// Type reconstruction
8853//===----------------------------------------------------------------------===//
8854
Mike Stump1eb44332009-09-09 15:08:12 +00008855template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008856QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8857 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008858 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008859 getDerived().getBaseEntity());
8860}
8861
Mike Stump1eb44332009-09-09 15:08:12 +00008862template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008863QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8864 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008865 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008866 getDerived().getBaseEntity());
8867}
8868
Mike Stump1eb44332009-09-09 15:08:12 +00008869template<typename Derived>
8870QualType
John McCall85737a72009-10-30 00:06:24 +00008871TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8872 bool WrittenAsLValue,
8873 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008874 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008875 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008876}
8877
8878template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008879QualType
John McCall85737a72009-10-30 00:06:24 +00008880TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8881 QualType ClassType,
8882 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008883 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008884 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008885}
8886
8887template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008888QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008889TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8890 ArrayType::ArraySizeModifier SizeMod,
8891 const llvm::APInt *Size,
8892 Expr *SizeExpr,
8893 unsigned IndexTypeQuals,
8894 SourceRange BracketsRange) {
8895 if (SizeExpr || !Size)
8896 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8897 IndexTypeQuals, BracketsRange,
8898 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008899
8900 QualType Types[] = {
8901 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8902 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8903 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008904 };
8905 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8906 QualType SizeType;
8907 for (unsigned I = 0; I != NumTypes; ++I)
8908 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8909 SizeType = Types[I];
8910 break;
8911 }
Mike Stump1eb44332009-09-09 15:08:12 +00008912
Eli Friedman01f276d2012-01-25 23:20:27 +00008913 // Note that we can return a VariableArrayType here in the case where
8914 // the element type was a dependent VariableArrayType.
8915 IntegerLiteral *ArraySize
8916 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8917 /*FIXME*/BracketsRange.getBegin());
8918 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008919 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008920 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008921}
Mike Stump1eb44332009-09-09 15:08:12 +00008922
Douglas Gregor577f75a2009-08-04 16:50:30 +00008923template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008924QualType
8925TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008926 ArrayType::ArraySizeModifier SizeMod,
8927 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008928 unsigned IndexTypeQuals,
8929 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008930 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008931 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008932}
8933
8934template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008935QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008936TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008937 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008938 unsigned IndexTypeQuals,
8939 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008940 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008941 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008942}
Mike Stump1eb44332009-09-09 15:08:12 +00008943
Douglas Gregor577f75a2009-08-04 16:50:30 +00008944template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008945QualType
8946TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008947 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008948 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008949 unsigned IndexTypeQuals,
8950 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008951 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008952 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008953 IndexTypeQuals, BracketsRange);
8954}
8955
8956template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008957QualType
8958TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008959 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008960 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008961 unsigned IndexTypeQuals,
8962 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008963 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008964 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008965 IndexTypeQuals, BracketsRange);
8966}
8967
8968template<typename Derived>
8969QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008970 unsigned NumElements,
8971 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008972 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008973 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008974}
Mike Stump1eb44332009-09-09 15:08:12 +00008975
Douglas Gregor577f75a2009-08-04 16:50:30 +00008976template<typename Derived>
8977QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8978 unsigned NumElements,
8979 SourceLocation AttributeLoc) {
8980 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8981 NumElements, true);
8982 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008983 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8984 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008985 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008986}
Mike Stump1eb44332009-09-09 15:08:12 +00008987
Douglas Gregor577f75a2009-08-04 16:50:30 +00008988template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008989QualType
8990TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008991 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008992 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008993 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008994}
Mike Stump1eb44332009-09-09 15:08:12 +00008995
Douglas Gregor577f75a2009-08-04 16:50:30 +00008996template<typename Derived>
8997QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008998 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008999 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00009000 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009001 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00009002 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00009003 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00009004 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00009005 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009006 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009007 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009008 getDerived().getBaseEntity(),
9009 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009010}
Mike Stump1eb44332009-09-09 15:08:12 +00009011
Douglas Gregor577f75a2009-08-04 16:50:30 +00009012template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009013QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9014 return SemaRef.Context.getFunctionNoProtoType(T);
9015}
9016
9017template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009018QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9019 assert(D && "no decl found");
9020 if (D->isInvalidDecl()) return QualType();
9021
Douglas Gregor92e986e2010-04-22 16:44:27 +00009022 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009023 TypeDecl *Ty;
9024 if (isa<UsingDecl>(D)) {
9025 UsingDecl *Using = cast<UsingDecl>(D);
9026 assert(Using->isTypeName() &&
9027 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9028
9029 // A valid resolved using typename decl points to exactly one type decl.
9030 assert(++Using->shadow_begin() == Using->shadow_end());
9031 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009032
John McCalled976492009-12-04 22:46:56 +00009033 } else {
9034 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9035 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9036 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9037 }
9038
9039 return SemaRef.Context.getTypeDeclType(Ty);
9040}
9041
9042template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009043QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9044 SourceLocation Loc) {
9045 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009046}
9047
9048template<typename Derived>
9049QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9050 return SemaRef.Context.getTypeOfType(Underlying);
9051}
9052
9053template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009054QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9055 SourceLocation Loc) {
9056 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009057}
9058
9059template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009060QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9061 UnaryTransformType::UTTKind UKind,
9062 SourceLocation Loc) {
9063 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9064}
9065
9066template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009067QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009068 TemplateName Template,
9069 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009070 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009071 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009072}
Mike Stump1eb44332009-09-09 15:08:12 +00009073
Douglas Gregordcee1a12009-08-06 05:28:30 +00009074template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009075QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9076 SourceLocation KWLoc) {
9077 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9078}
9079
9080template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009081TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009082TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009083 bool TemplateKW,
9084 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009085 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009086 Template);
9087}
9088
9089template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009090TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009091TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9092 const IdentifierInfo &Name,
9093 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009094 QualType ObjectType,
9095 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009096 UnqualifiedId TemplateName;
9097 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009098 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009099 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009100 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009101 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009102 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009103 /*EnteringContext=*/false,
9104 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009105 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009106}
Mike Stump1eb44332009-09-09 15:08:12 +00009107
Douglas Gregorb98b1992009-08-11 05:31:07 +00009108template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009109TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009110TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009111 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009112 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009113 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009114 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009115 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009116 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009117 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009118 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009119 Sema::TemplateTy Template;
9120 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009121 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009122 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009123 /*EnteringContext=*/false,
9124 Template);
9125 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009126}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009127
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009128template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009129ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009130TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9131 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009132 Expr *OrigCallee,
9133 Expr *First,
9134 Expr *Second) {
9135 Expr *Callee = OrigCallee->IgnoreParenCasts();
9136 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009137
Douglas Gregorb98b1992009-08-11 05:31:07 +00009138 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009139 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009140 if (!First->getType()->isOverloadableType() &&
9141 !Second->getType()->isOverloadableType())
9142 return getSema().CreateBuiltinArraySubscriptExpr(First,
9143 Callee->getLocStart(),
9144 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009145 } else if (Op == OO_Arrow) {
9146 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009147 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9148 } else if (Second == 0 || isPostIncDec) {
9149 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009150 // The argument is not of overloadable type, so try to create a
9151 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009152 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009153 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009154
John McCall9ae2f072010-08-23 23:25:46 +00009155 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009156 }
9157 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009158 if (!First->getType()->isOverloadableType() &&
9159 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009160 // Neither of the arguments is an overloadable type, so try to
9161 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009162 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009163 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009164 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009165 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009166 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009167
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009168 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009169 }
9170 }
Mike Stump1eb44332009-09-09 15:08:12 +00009171
9172 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009173 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009174 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009175
John McCall9ae2f072010-08-23 23:25:46 +00009176 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009177 assert(ULE->requiresADL());
9178
9179 // FIXME: Do we have to check
9180 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009181 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009182 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009183 // If we've resolved this to a particular non-member function, just call
9184 // that function. If we resolved it to a member function,
9185 // CreateOverloaded* will find that function for us.
9186 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9187 if (!isa<CXXMethodDecl>(ND))
9188 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009189 }
Mike Stump1eb44332009-09-09 15:08:12 +00009190
Douglas Gregorb98b1992009-08-11 05:31:07 +00009191 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009192 Expr *Args[2] = { First, Second };
9193 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009194
Douglas Gregorb98b1992009-08-11 05:31:07 +00009195 // Create the overloaded operator invocation for unary operators.
9196 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009197 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009198 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009199 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009200 }
Mike Stump1eb44332009-09-09 15:08:12 +00009201
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009202 if (Op == OO_Subscript) {
9203 SourceLocation LBrace;
9204 SourceLocation RBrace;
9205
9206 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9207 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9208 LBrace = SourceLocation::getFromRawEncoding(
9209 NameLoc.CXXOperatorName.BeginOpNameLoc);
9210 RBrace = SourceLocation::getFromRawEncoding(
9211 NameLoc.CXXOperatorName.EndOpNameLoc);
9212 } else {
9213 LBrace = Callee->getLocStart();
9214 RBrace = OpLoc;
9215 }
9216
9217 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9218 First, Second);
9219 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009220
Douglas Gregorb98b1992009-08-11 05:31:07 +00009221 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009222 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009223 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009224 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9225 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009226 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009227
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009228 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009229}
Mike Stump1eb44332009-09-09 15:08:12 +00009230
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009231template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009232ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009233TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009234 SourceLocation OperatorLoc,
9235 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009236 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009237 TypeSourceInfo *ScopeType,
9238 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009239 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009240 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009241 QualType BaseType = Base->getType();
9242 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009243 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009244 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009245 !BaseType->getAs<PointerType>()->getPointeeType()
9246 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009247 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009248 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009249 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009250 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009251 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009252 /*FIXME?*/true);
9253 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009254
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009255 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009256 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9257 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9258 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9259 NameInfo.setNamedTypeInfo(DestroyedType);
9260
Richard Smith6314db92012-05-15 06:15:11 +00009261 // The scope type is now known to be a valid nested name specifier
9262 // component. Tack it on to the end of the nested name specifier.
9263 if (ScopeType)
9264 SS.Extend(SemaRef.Context, SourceLocation(),
9265 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009266
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009267 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009268 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009269 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009270 SS, TemplateKWLoc,
9271 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009272 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009273 /*TemplateArgs*/ 0);
9274}
9275
Douglas Gregor577f75a2009-08-04 16:50:30 +00009276} // end namespace clang
9277
9278#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H