blob: 5511fc00f559d7849c434ce3e61e4a13053d2dda [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
John McCall2d887082010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor8491ffe2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Richard Smith3e4c6c42011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall19510852010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000034#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000035#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000036#include "TypeLocBuilder.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;
101
102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
106
107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
111
Douglas Gregor577f75a2009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Douglas Gregor8491ffe2010-12-20 22:05:00 +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;
119
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();
Douglas Gregorae201f72011-01-25 17:51:48 +0000180
181 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 }
Sean Huntc3021132010-05-05 15:23:54 +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 ///
224 /// \param Unexpanded The set of unexpanded parameter packs within the
225 /// pattern.
226 ///
227 /// \param NumUnexpanded The number of unexpanded parameter packs in
228 /// \p Unexpanded.
229 ///
230 /// \param ShouldExpand Will be set to \c true if the transformer should
231 /// expand the corresponding pack expansions into separate arguments. When
232 /// set, \c NumExpansions must also be set.
233 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000234 /// \param RetainExpansion Whether the caller should add an unexpanded
235 /// pack expansion after all of the expanded arguments. This is used
236 /// when extending explicitly-specified template argument packs per
237 /// C++0x [temp.arg.explicit]p9.
238 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000239 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000240 /// the expanded form of the corresponding pack expansion. This is both an
241 /// input and an output parameter, which can be set by the caller if the
242 /// number of expansions is known a priori (e.g., due to a prior substitution)
243 /// and will be set by the callee when the number of expansions is known.
244 /// The callee must set this value when \c ShouldExpand is \c true; it may
245 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000246 ///
247 /// \returns true if an error occurred (e.g., because the parameter packs
248 /// are to be instantiated with arguments of different lengths), false
249 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
250 /// must be set.
251 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
252 SourceRange PatternRange,
David Blaikiea71f9d02011-09-22 02:34:54 +0000253 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000254 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000255 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000256 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000257 ShouldExpand = false;
258 return false;
259 }
260
Douglas Gregord3731192011-01-10 07:32:04 +0000261 /// \brief "Forget" about the partially-substituted pack template argument,
262 /// when performing an instantiation that must preserve the parameter pack
263 /// use.
264 ///
265 /// This routine is meant to be overridden by the template instantiator.
266 TemplateArgument ForgetPartiallySubstitutedPack() {
267 return TemplateArgument();
268 }
269
270 /// \brief "Remember" the partially-substituted pack template argument
271 /// after performing an instantiation that must preserve the parameter pack
272 /// use.
273 ///
274 /// This routine is meant to be overridden by the template instantiator.
275 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
276
Douglas Gregor12c9c002011-01-07 16:43:16 +0000277 /// \brief Note to the derived class when a function parameter pack is
278 /// being expanded.
279 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
280
Douglas Gregor577f75a2009-08-04 16:50:30 +0000281 /// \brief Transforms the given type into another type.
282 ///
John McCalla2becad2009-10-21 00:40:46 +0000283 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000284 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000285 /// function. This is expensive, but we don't mind, because
286 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000287 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000288 ///
289 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000290 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000291
John McCalla2becad2009-10-21 00:40:46 +0000292 /// \brief Transforms the given type-with-location into a new
293 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000294 ///
John McCalla2becad2009-10-21 00:40:46 +0000295 /// By default, this routine transforms a type by delegating to the
296 /// appropriate TransformXXXType to build a new type. Subclasses
297 /// may override this function (to take over all type
298 /// transformations) or some set of the TransformXXXType functions
299 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000300 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000301
302 /// \brief Transform the given type-with-location into a new
303 /// type, collecting location information in the given builder
304 /// as necessary.
305 ///
John McCall43fed0d2010-11-12 08:19:04 +0000306 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000307
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000308 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000309 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000310 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000311 /// appropriate TransformXXXStmt function to transform a specific kind of
312 /// statement or the TransformExpr() function to transform an expression.
313 /// Subclasses may override this function to transform statements using some
314 /// other mechanism.
315 ///
316 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000317 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000318
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000319 /// \brief Transform the given expression.
320 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000321 /// By default, this routine transforms an expression by delegating to the
322 /// appropriate TransformXXXExpr function to build a new expression.
323 /// Subclasses may override this function to transform expressions using some
324 /// other mechanism.
325 ///
326 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000327 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000328
Douglas Gregoraa165f82011-01-03 19:04:46 +0000329 /// \brief Transform the given list of expressions.
330 ///
331 /// This routine transforms a list of expressions by invoking
332 /// \c TransformExpr() for each subexpression. However, it also provides
333 /// support for variadic templates by expanding any pack expansions (if the
334 /// derived class permits such expansion) along the way. When pack expansions
335 /// are present, the number of outputs may not equal the number of inputs.
336 ///
337 /// \param Inputs The set of expressions to be transformed.
338 ///
339 /// \param NumInputs The number of expressions in \c Inputs.
340 ///
341 /// \param IsCall If \c true, then this transform is being performed on
342 /// function-call arguments, and any arguments that should be dropped, will
343 /// be.
344 ///
345 /// \param Outputs The transformed input expressions will be added to this
346 /// vector.
347 ///
348 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
349 /// due to transformation.
350 ///
351 /// \returns true if an error occurred, false otherwise.
352 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000353 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000354 bool *ArgChanged = 0);
355
Douglas Gregor577f75a2009-08-04 16:50:30 +0000356 /// \brief Transform the given declaration, which is referenced from a type
357 /// or expression.
358 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000359 /// By default, acts as the identity function on declarations, unless the
360 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000361 /// may override this function to provide alternate behavior.
Douglas Gregordfca6f52012-02-13 22:00:16 +0000362 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
363 llvm::DenseMap<Decl *, Decl *>::iterator Known
364 = TransformedLocalDecls.find(D);
365 if (Known != TransformedLocalDecls.end())
366 return Known->second;
367
368 return D;
369 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000370
Douglas Gregordfca6f52012-02-13 22:00:16 +0000371 /// \brief Transform the attributes associated with the given declaration and
372 /// place them on the new declaration.
373 ///
374 /// By default, this operation does nothing. Subclasses may override this
375 /// behavior to transform attributes.
376 void transformAttrs(Decl *Old, Decl *New) { }
377
378 /// \brief Note that a local declaration has been transformed by this
379 /// transformer.
380 ///
381 /// Local declarations are typically transformed via a call to
382 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
383 /// the transformer itself has to transform the declarations. This routine
384 /// can be overridden by a subclass that keeps track of such mappings.
385 void transformedLocalDecl(Decl *Old, Decl *New) {
386 TransformedLocalDecls[Old] = New;
387 }
388
Douglas Gregor43959a92009-08-20 07:17:43 +0000389 /// \brief Transform the definition of the given declaration.
390 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000391 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000392 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000393 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
394 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000395 }
Mike Stump1eb44332009-09-09 15:08:12 +0000396
Douglas Gregor6cd21982009-10-20 05:58:46 +0000397 /// \brief Transform the given declaration, which was the first part of a
398 /// nested-name-specifier in a member access expression.
399 ///
Sean Huntc3021132010-05-05 15:23:54 +0000400 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000401 /// identifier in a nested-name-specifier of a member access expression, e.g.,
402 /// the \c T in \c x->T::member
403 ///
404 /// By default, invokes TransformDecl() to transform the declaration.
405 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000406 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
407 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000408 }
Sean Huntc3021132010-05-05 15:23:54 +0000409
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000410 /// \brief Transform the given nested-name-specifier with source-location
411 /// information.
412 ///
413 /// By default, transforms all of the types and declarations within the
414 /// nested-name-specifier. Subclasses may override this function to provide
415 /// alternate behavior.
416 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
417 NestedNameSpecifierLoc NNS,
418 QualType ObjectType = QualType(),
419 NamedDecl *FirstQualifierInScope = 0);
420
Douglas Gregor81499bb2009-09-03 22:13:48 +0000421 /// \brief Transform the given declaration name.
422 ///
423 /// By default, transforms the types of conversion function, constructor,
424 /// and destructor names and then (if needed) rebuilds the declaration name.
425 /// Identifiers and selectors are returned unmodified. Sublcasses may
426 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000427 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000428 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000429
Douglas Gregor577f75a2009-08-04 16:50:30 +0000430 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000431 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000432 /// \param SS The nested-name-specifier that qualifies the template
433 /// name. This nested-name-specifier must already have been transformed.
434 ///
435 /// \param Name The template name to transform.
436 ///
437 /// \param NameLoc The source location of the template name.
438 ///
439 /// \param ObjectType If we're translating a template name within a member
440 /// access expression, this is the type of the object whose member template
441 /// is being referenced.
442 ///
443 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
444 /// also refers to a name within the current (lexical) scope, this is the
445 /// declaration it refers to.
446 ///
447 /// By default, transforms the template name by transforming the declarations
448 /// and nested-name-specifiers that occur within the template name.
449 /// Subclasses may override this function to provide alternate behavior.
450 TemplateName TransformTemplateName(CXXScopeSpec &SS,
451 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000452 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000453 QualType ObjectType = QualType(),
454 NamedDecl *FirstQualifierInScope = 0);
455
Douglas Gregor577f75a2009-08-04 16:50:30 +0000456 /// \brief Transform the given template argument.
457 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000458 /// By default, this operation transforms the type, expression, or
459 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000460 /// new template argument from the transformed result. Subclasses may
461 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000462 ///
463 /// Returns true if there was an error.
464 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
465 TemplateArgumentLoc &Output);
466
Douglas Gregorfcc12532010-12-20 17:31:10 +0000467 /// \brief Transform the given set of template arguments.
468 ///
469 /// By default, this operation transforms all of the template arguments
470 /// in the input set using \c TransformTemplateArgument(), and appends
471 /// the transformed arguments to the output list.
472 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000473 /// Note that this overload of \c TransformTemplateArguments() is merely
474 /// a convenience function. Subclasses that wish to override this behavior
475 /// should override the iterator-based member template version.
476 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000477 /// \param Inputs The set of template arguments to be transformed.
478 ///
479 /// \param NumInputs The number of template arguments in \p Inputs.
480 ///
481 /// \param Outputs The set of transformed template arguments output by this
482 /// routine.
483 ///
484 /// Returns true if an error occurred.
485 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
486 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000487 TemplateArgumentListInfo &Outputs) {
488 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
489 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000490
491 /// \brief Transform the given set of template arguments.
492 ///
493 /// By default, this operation transforms all of the template arguments
494 /// in the input set using \c TransformTemplateArgument(), and appends
495 /// the transformed arguments to the output list.
496 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000497 /// \param First An iterator to the first template argument.
498 ///
499 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000500 ///
501 /// \param Outputs The set of transformed template arguments output by this
502 /// routine.
503 ///
504 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000505 template<typename InputIterator>
506 bool TransformTemplateArguments(InputIterator First,
507 InputIterator Last,
508 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000509
John McCall833ca992009-10-29 08:12:44 +0000510 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
511 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
512 TemplateArgumentLoc &ArgLoc);
513
John McCalla93c9342009-12-07 02:54:59 +0000514 /// \brief Fakes up a TypeSourceInfo for a type.
515 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
516 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000517 getDerived().getBaseLocation());
518 }
Mike Stump1eb44332009-09-09 15:08:12 +0000519
John McCalla2becad2009-10-21 00:40:46 +0000520#define ABSTRACT_TYPELOC(CLASS, PARENT)
521#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000522 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000523#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000524
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000525 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
526 FunctionProtoTypeLoc TL,
527 CXXRecordDecl *ThisContext,
528 unsigned ThisTypeQuals);
529
John Wiegley28bbe4b2011-04-28 01:08:34 +0000530 StmtResult
531 TransformSEHHandler(Stmt *Handler);
532
John McCall43fed0d2010-11-12 08:19:04 +0000533 QualType
534 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
535 TemplateSpecializationTypeLoc TL,
536 TemplateName Template);
537
538 QualType
539 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
540 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000541 TemplateName Template,
542 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000543
544 QualType
545 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000546 DependentTemplateSpecializationTypeLoc TL,
547 NestedNameSpecifierLoc QualifierLoc);
548
John McCall21ef0fa2010-03-11 09:03:00 +0000549 /// \brief Transforms the parameters of a function type into the
550 /// given vectors.
551 ///
552 /// The result vectors should be kept in sync; null entries in the
553 /// variables vector are acceptable.
554 ///
555 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000556 bool TransformFunctionTypeParams(SourceLocation Loc,
557 ParmVarDecl **Params, unsigned NumParams,
558 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000559 SmallVectorImpl<QualType> &PTypes,
560 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000561
562 /// \brief Transforms a single function-type parameter. Return null
563 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000564 ///
565 /// \param indexAdjustment - A number to add to the parameter's
566 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000567 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000568 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000569 llvm::Optional<unsigned> NumExpansions,
570 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000571
John McCall43fed0d2010-11-12 08:19:04 +0000572 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000573
John McCall60d7b3a2010-08-24 06:29:42 +0000574 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
575 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000576
Douglas Gregor43959a92009-08-20 07:17:43 +0000577#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000578 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000579#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000580 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000581#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000582#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000583
Douglas Gregor577f75a2009-08-04 16:50:30 +0000584 /// \brief Build a new pointer type given its pointee type.
585 ///
586 /// By default, performs semantic analysis when building the pointer type.
587 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000588 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000589
590 /// \brief Build a new block pointer type given its pointee type.
591 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000592 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000593 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000594 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000595
John McCall85737a72009-10-30 00:06:24 +0000596 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000597 ///
John McCall85737a72009-10-30 00:06:24 +0000598 /// By default, performs semantic analysis when building the
599 /// reference type. Subclasses may override this routine to provide
600 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000601 ///
John McCall85737a72009-10-30 00:06:24 +0000602 /// \param LValue whether the type was written with an lvalue sigil
603 /// or an rvalue sigil.
604 QualType RebuildReferenceType(QualType ReferentType,
605 bool LValue,
606 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000607
Douglas Gregor577f75a2009-08-04 16:50:30 +0000608 /// \brief Build a new member pointer type given the pointee type and the
609 /// class type it refers into.
610 ///
611 /// By default, performs semantic analysis when building the member pointer
612 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000613 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
614 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000615
Douglas Gregor577f75a2009-08-04 16:50:30 +0000616 /// \brief Build a new array type given the element type, size
617 /// modifier, size of the array (if known), size expression, and index type
618 /// qualifiers.
619 ///
620 /// By default, performs semantic analysis when building the array type.
621 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000622 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000623 QualType RebuildArrayType(QualType ElementType,
624 ArrayType::ArraySizeModifier SizeMod,
625 const llvm::APInt *Size,
626 Expr *SizeExpr,
627 unsigned IndexTypeQuals,
628 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000629
Douglas Gregor577f75a2009-08-04 16:50:30 +0000630 /// \brief Build a new constant array type given the element type, size
631 /// modifier, (known) size of the array, and index type qualifiers.
632 ///
633 /// By default, performs semantic analysis when building the array type.
634 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000635 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636 ArrayType::ArraySizeModifier SizeMod,
637 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000638 unsigned IndexTypeQuals,
639 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000640
Douglas Gregor577f75a2009-08-04 16:50:30 +0000641 /// \brief Build a new incomplete array type given the element type, size
642 /// modifier, and index type qualifiers.
643 ///
644 /// By default, performs semantic analysis when building the array type.
645 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000646 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000647 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000648 unsigned IndexTypeQuals,
649 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000650
Mike Stump1eb44332009-09-09 15:08:12 +0000651 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000652 /// size modifier, size expression, and index type qualifiers.
653 ///
654 /// By default, performs semantic analysis when building the array type.
655 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000656 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000657 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000658 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000659 unsigned IndexTypeQuals,
660 SourceRange BracketsRange);
661
Mike Stump1eb44332009-09-09 15:08:12 +0000662 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663 /// size modifier, size expression, and index type qualifiers.
664 ///
665 /// By default, performs semantic analysis when building the array type.
666 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000667 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000668 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000669 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000670 unsigned IndexTypeQuals,
671 SourceRange BracketsRange);
672
673 /// \brief Build a new vector type given the element type and
674 /// number of elements.
675 ///
676 /// By default, performs semantic analysis when building the vector type.
677 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000678 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000679 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000680
Douglas Gregor577f75a2009-08-04 16:50:30 +0000681 /// \brief Build a new extended vector type given the element type and
682 /// number of elements.
683 ///
684 /// By default, performs semantic analysis when building the vector type.
685 /// Subclasses may override this routine to provide different behavior.
686 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
687 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000688
689 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000690 /// given the element type and number of elements.
691 ///
692 /// By default, performs semantic analysis when building the vector type.
693 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000694 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000695 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000696 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000697
Douglas Gregor577f75a2009-08-04 16:50:30 +0000698 /// \brief Build a new function type.
699 ///
700 /// By default, performs semantic analysis when building the function type.
701 /// Subclasses may override this routine to provide different behavior.
702 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000703 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000704 unsigned NumParamTypes,
Richard Smitheefb3d52012-02-10 09:58:53 +0000705 bool Variadic, bool HasTrailingReturn,
706 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000707 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000708 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000709
John McCalla2becad2009-10-21 00:40:46 +0000710 /// \brief Build a new unprototyped function type.
711 QualType RebuildFunctionNoProtoType(QualType ResultType);
712
John McCalled976492009-12-04 22:46:56 +0000713 /// \brief Rebuild an unresolved typename type, given the decl that
714 /// the UnresolvedUsingTypenameDecl was transformed to.
715 QualType RebuildUnresolvedUsingType(Decl *D);
716
Douglas Gregor577f75a2009-08-04 16:50:30 +0000717 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000718 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000719 return SemaRef.Context.getTypeDeclType(Typedef);
720 }
721
722 /// \brief Build a new class/struct/union type.
723 QualType RebuildRecordType(RecordDecl *Record) {
724 return SemaRef.Context.getTypeDeclType(Record);
725 }
726
727 /// \brief Build a new Enum type.
728 QualType RebuildEnumType(EnumDecl *Enum) {
729 return SemaRef.Context.getTypeDeclType(Enum);
730 }
John McCall7da24312009-09-05 00:15:47 +0000731
Mike Stump1eb44332009-09-09 15:08:12 +0000732 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000733 ///
734 /// By default, performs semantic analysis when building the typeof type.
735 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000736 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000737
Mike Stump1eb44332009-09-09 15:08:12 +0000738 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000739 ///
740 /// By default, builds a new TypeOfType with the given underlying type.
741 QualType RebuildTypeOfType(QualType Underlying);
742
Sean Huntca63c202011-05-24 22:41:36 +0000743 /// \brief Build a new unary transform type.
744 QualType RebuildUnaryTransformType(QualType BaseType,
745 UnaryTransformType::UTTKind UKind,
746 SourceLocation Loc);
747
Mike Stump1eb44332009-09-09 15:08:12 +0000748 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000749 ///
750 /// By default, performs semantic analysis when building the decltype type.
751 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000752 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000753
Richard Smith34b41d92011-02-20 03:19:35 +0000754 /// \brief Build a new C++0x auto type.
755 ///
756 /// By default, builds a new AutoType with the given deduced type.
757 QualType RebuildAutoType(QualType Deduced) {
758 return SemaRef.Context.getAutoType(Deduced);
759 }
760
Douglas Gregor577f75a2009-08-04 16:50:30 +0000761 /// \brief Build a new template specialization type.
762 ///
763 /// By default, performs semantic analysis when building the template
764 /// specialization type. Subclasses may override this routine to provide
765 /// different behavior.
766 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000767 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000768 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000769
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000770 /// \brief Build a new parenthesized type.
771 ///
772 /// By default, builds a new ParenType type from the inner type.
773 /// Subclasses may override this routine to provide different behavior.
774 QualType RebuildParenType(QualType InnerType) {
775 return SemaRef.Context.getParenType(InnerType);
776 }
777
Douglas Gregor577f75a2009-08-04 16:50:30 +0000778 /// \brief Build a new qualified name type.
779 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000780 /// By default, builds a new ElaboratedType type from the keyword,
781 /// the nested-name-specifier and the named type.
782 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000783 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
784 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000785 NestedNameSpecifierLoc QualifierLoc,
786 QualType Named) {
787 return SemaRef.Context.getElaboratedType(Keyword,
788 QualifierLoc.getNestedNameSpecifier(),
789 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000790 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000791
792 /// \brief Build a new typename type that refers to a template-id.
793 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000794 /// By default, builds a new DependentNameType type from the
795 /// nested-name-specifier and the given type. Subclasses may override
796 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000797 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000798 ElaboratedTypeKeyword Keyword,
799 NestedNameSpecifierLoc QualifierLoc,
800 const IdentifierInfo *Name,
801 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000802 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000803 // Rebuild the template name.
804 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000805 CXXScopeSpec SS;
806 SS.Adopt(QualifierLoc);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000807 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000808 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000809
810 if (InstName.isNull())
811 return QualType();
812
813 // If it's still dependent, make a dependent specialization.
814 if (InstName.getAsDependentTemplateName())
815 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
816 QualifierLoc.getNestedNameSpecifier(),
817 Name,
818 Args);
819
820 // Otherwise, make an elaborated type wrapping a non-dependent
821 // specialization.
822 QualType T =
823 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
824 if (T.isNull()) return QualType();
825
826 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
827 return T;
828
829 return SemaRef.Context.getElaboratedType(Keyword,
830 QualifierLoc.getNestedNameSpecifier(),
831 T);
832 }
833
Douglas Gregor577f75a2009-08-04 16:50:30 +0000834 /// \brief Build a new typename type that refers to an identifier.
835 ///
836 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000837 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000838 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000839 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000840 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000841 NestedNameSpecifierLoc QualifierLoc,
842 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000843 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000844 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000845 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000846
Douglas Gregor2494dd02011-03-01 01:34:45 +0000847 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000848 // If the name is still dependent, just build a new dependent name type.
849 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor2494dd02011-03-01 01:34:45 +0000850 return SemaRef.Context.getDependentNameType(Keyword,
851 QualifierLoc.getNestedNameSpecifier(),
852 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000853 }
854
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000855 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000856 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000857 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000858
859 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
860
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000861 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000862 // into a non-dependent elaborated-type-specifier. Find the tag we're
863 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000864 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000865 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
866 if (!DC)
867 return QualType();
868
John McCall56138762010-05-27 06:40:31 +0000869 if (SemaRef.RequireCompleteDeclContext(SS, DC))
870 return QualType();
871
Douglas Gregor40336422010-03-31 22:19:08 +0000872 TagDecl *Tag = 0;
873 SemaRef.LookupQualifiedName(Result, DC);
874 switch (Result.getResultKind()) {
875 case LookupResult::NotFound:
876 case LookupResult::NotFoundInCurrentInstantiation:
877 break;
Sean Huntc3021132010-05-05 15:23:54 +0000878
Douglas Gregor40336422010-03-31 22:19:08 +0000879 case LookupResult::Found:
880 Tag = Result.getAsSingle<TagDecl>();
881 break;
Sean Huntc3021132010-05-05 15:23:54 +0000882
Douglas Gregor40336422010-03-31 22:19:08 +0000883 case LookupResult::FoundOverloaded:
884 case LookupResult::FoundUnresolvedValue:
885 llvm_unreachable("Tag lookup cannot find non-tags");
Sean Huntc3021132010-05-05 15:23:54 +0000886
Douglas Gregor40336422010-03-31 22:19:08 +0000887 case LookupResult::Ambiguous:
888 // Let the LookupResult structure handle ambiguities.
889 return QualType();
890 }
891
892 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000893 // Check where the name exists but isn't a tag type and use that to emit
894 // better diagnostics.
895 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
896 SemaRef.LookupQualifiedName(Result, DC);
897 switch (Result.getResultKind()) {
898 case LookupResult::Found:
899 case LookupResult::FoundOverloaded:
900 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000901 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000902 unsigned Kind = 0;
903 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000904 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
905 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000906 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
907 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
908 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000909 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000910 default:
911 // FIXME: Would be nice to highlight just the source range.
912 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
913 << Kind << Id << DC;
914 break;
915 }
Douglas Gregor40336422010-03-31 22:19:08 +0000916 return QualType();
917 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000918
Richard Trieubbf34c02011-06-10 03:11:26 +0000919 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
920 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000921 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000922 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
923 return QualType();
924 }
925
926 // Build the elaborated-type-specifier type.
927 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor2494dd02011-03-01 01:34:45 +0000928 return SemaRef.Context.getElaboratedType(Keyword,
929 QualifierLoc.getNestedNameSpecifier(),
930 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000931 }
Mike Stump1eb44332009-09-09 15:08:12 +0000932
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000933 /// \brief Build a new pack expansion type.
934 ///
935 /// By default, builds a new PackExpansionType type from the given pattern.
936 /// Subclasses may override this routine to provide different behavior.
937 QualType RebuildPackExpansionType(QualType Pattern,
938 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000939 SourceLocation EllipsisLoc,
940 llvm::Optional<unsigned> NumExpansions) {
941 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
942 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000943 }
944
Eli Friedmanb001de72011-10-06 23:00:33 +0000945 /// \brief Build a new atomic type given its value type.
946 ///
947 /// By default, performs semantic analysis when building the atomic type.
948 /// Subclasses may override this routine to provide different behavior.
949 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
950
Douglas Gregord1067e52009-08-06 06:41:21 +0000951 /// \brief Build a new template name given a nested name specifier, a flag
952 /// indicating whether the "template" keyword was provided, and the template
953 /// that the template name refers to.
954 ///
955 /// By default, builds the new template name directly. Subclasses may override
956 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000957 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000958 bool TemplateKW,
959 TemplateDecl *Template);
960
Douglas Gregord1067e52009-08-06 06:41:21 +0000961 /// \brief Build a new template name given a nested name specifier and the
962 /// name that is referred to as a template.
963 ///
964 /// By default, performs semantic analysis to determine whether the name can
965 /// be resolved to a specific template, then builds the appropriate kind of
966 /// template name. Subclasses may override this routine to provide different
967 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000968 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
969 const IdentifierInfo &Name,
970 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000971 QualType ObjectType,
972 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000973
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000974 /// \brief Build a new template name given a nested name specifier and the
975 /// overloaded operator name that is referred to as a template.
976 ///
977 /// By default, performs semantic analysis to determine whether the name can
978 /// be resolved to a specific template, then builds the appropriate kind of
979 /// template name. Subclasses may override this routine to provide different
980 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000981 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000982 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000983 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000984 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000985
986 /// \brief Build a new template name given a template template parameter pack
987 /// and the
988 ///
989 /// By default, performs semantic analysis to determine whether the name can
990 /// be resolved to a specific template, then builds the appropriate kind of
991 /// template name. Subclasses may override this routine to provide different
992 /// behavior.
993 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
994 const TemplateArgument &ArgPack) {
995 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
996 }
997
Douglas Gregor43959a92009-08-20 07:17:43 +0000998 /// \brief Build a new compound statement.
999 ///
1000 /// By default, performs semantic analysis to build the new statement.
1001 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001002 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001003 MultiStmtArg Statements,
1004 SourceLocation RBraceLoc,
1005 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001006 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001007 IsStmtExpr);
1008 }
1009
1010 /// \brief Build a new case statement.
1011 ///
1012 /// By default, performs semantic analysis to build the new statement.
1013 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001014 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001015 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001016 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001017 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001018 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001019 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001020 ColonLoc);
1021 }
Mike Stump1eb44332009-09-09 15:08:12 +00001022
Douglas Gregor43959a92009-08-20 07:17:43 +00001023 /// \brief Attach the body to a new case statement.
1024 ///
1025 /// By default, performs semantic analysis to build the new statement.
1026 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001027 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001028 getSema().ActOnCaseStmtBody(S, Body);
1029 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001030 }
Mike Stump1eb44332009-09-09 15:08:12 +00001031
Douglas Gregor43959a92009-08-20 07:17:43 +00001032 /// \brief Build a new default statement.
1033 ///
1034 /// By default, performs semantic analysis to build the new statement.
1035 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001036 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001037 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001038 Stmt *SubStmt) {
1039 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001040 /*CurScope=*/0);
1041 }
Mike Stump1eb44332009-09-09 15:08:12 +00001042
Douglas Gregor43959a92009-08-20 07:17:43 +00001043 /// \brief Build a new label statement.
1044 ///
1045 /// By default, performs semantic analysis to build the new statement.
1046 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001047 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1048 SourceLocation ColonLoc, Stmt *SubStmt) {
1049 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001050 }
Mike Stump1eb44332009-09-09 15:08:12 +00001051
Richard Smith534986f2012-04-14 00:33:13 +00001052 /// \brief Build a new label statement.
1053 ///
1054 /// By default, performs semantic analysis to build the new statement.
1055 /// Subclasses may override this routine to provide different behavior.
1056 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, const AttrVec &Attrs,
1057 Stmt *SubStmt) {
1058 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1059 }
1060
Douglas Gregor43959a92009-08-20 07:17:43 +00001061 /// \brief Build a new "if" statement.
1062 ///
1063 /// By default, performs semantic analysis to build the new statement.
1064 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001065 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001066 VarDecl *CondVar, Stmt *Then,
1067 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001068 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001069 }
Mike Stump1eb44332009-09-09 15:08:12 +00001070
Douglas Gregor43959a92009-08-20 07:17:43 +00001071 /// \brief Start building a new switch statement.
1072 ///
1073 /// By default, performs semantic analysis to build the new statement.
1074 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001075 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001076 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001077 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001078 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001079 }
Mike Stump1eb44332009-09-09 15:08:12 +00001080
Douglas Gregor43959a92009-08-20 07:17:43 +00001081 /// \brief Attach the body to the switch statement.
1082 ///
1083 /// By default, performs semantic analysis to build the new statement.
1084 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001085 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001086 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001087 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001088 }
1089
1090 /// \brief Build a new while statement.
1091 ///
1092 /// By default, performs semantic analysis to build the new statement.
1093 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001094 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1095 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001096 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001097 }
Mike Stump1eb44332009-09-09 15:08:12 +00001098
Douglas Gregor43959a92009-08-20 07:17:43 +00001099 /// \brief Build a new do-while statement.
1100 ///
1101 /// By default, performs semantic analysis to build the new statement.
1102 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001103 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001104 SourceLocation WhileLoc, SourceLocation LParenLoc,
1105 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001106 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1107 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001108 }
1109
1110 /// \brief Build a new for statement.
1111 ///
1112 /// By default, performs semantic analysis to build the new statement.
1113 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001114 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1115 Stmt *Init, Sema::FullExprArg Cond,
1116 VarDecl *CondVar, Sema::FullExprArg Inc,
1117 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001118 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001119 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001120 }
Mike Stump1eb44332009-09-09 15:08:12 +00001121
Douglas Gregor43959a92009-08-20 07:17:43 +00001122 /// \brief Build a new goto statement.
1123 ///
1124 /// By default, performs semantic analysis to build the new statement.
1125 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001126 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1127 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001128 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001129 }
1130
1131 /// \brief Build a new indirect goto statement.
1132 ///
1133 /// By default, performs semantic analysis to build the new statement.
1134 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001135 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001136 SourceLocation StarLoc,
1137 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001138 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001139 }
Mike Stump1eb44332009-09-09 15:08:12 +00001140
Douglas Gregor43959a92009-08-20 07:17:43 +00001141 /// \brief Build a new return statement.
1142 ///
1143 /// By default, performs semantic analysis to build the new statement.
1144 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001145 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001146 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001147 }
Mike Stump1eb44332009-09-09 15:08:12 +00001148
Douglas Gregor43959a92009-08-20 07:17:43 +00001149 /// \brief Build a new declaration statement.
1150 ///
1151 /// By default, performs semantic analysis to build the new statement.
1152 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001153 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001154 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001155 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001156 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1157 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001158 }
Mike Stump1eb44332009-09-09 15:08:12 +00001159
Anders Carlsson703e3942010-01-24 05:50:09 +00001160 /// \brief Build a new inline asm statement.
1161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001164 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001165 bool IsSimple,
1166 bool IsVolatile,
1167 unsigned NumOutputs,
1168 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001169 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001170 MultiExprArg Constraints,
1171 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001172 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001173 MultiExprArg Clobbers,
1174 SourceLocation RParenLoc,
1175 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001176 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001177 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001178 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001179 RParenLoc, MSAsm);
1180 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001181
1182 /// \brief Build a new Objective-C @try statement.
1183 ///
1184 /// By default, performs semantic analysis to build the new statement.
1185 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001186 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001187 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001188 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001189 Stmt *Finally) {
1190 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1191 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001192 }
1193
Douglas Gregorbe270a02010-04-26 17:57:08 +00001194 /// \brief Rebuild an Objective-C exception declaration.
1195 ///
1196 /// By default, performs semantic analysis to build the new declaration.
1197 /// Subclasses may override this routine to provide different behavior.
1198 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1199 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001200 return getSema().BuildObjCExceptionDecl(TInfo, T,
1201 ExceptionDecl->getInnerLocStart(),
1202 ExceptionDecl->getLocation(),
1203 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001204 }
Sean Huntc3021132010-05-05 15:23:54 +00001205
Douglas Gregorbe270a02010-04-26 17:57:08 +00001206 /// \brief Build a new Objective-C @catch statement.
1207 ///
1208 /// By default, performs semantic analysis to build the new statement.
1209 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001210 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001211 SourceLocation RParenLoc,
1212 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001213 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001214 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001215 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001216 }
Sean Huntc3021132010-05-05 15:23:54 +00001217
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001218 /// \brief Build a new Objective-C @finally statement.
1219 ///
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001222 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001223 Stmt *Body) {
1224 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001225 }
Sean Huntc3021132010-05-05 15:23:54 +00001226
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001227 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001228 ///
1229 /// By default, performs semantic analysis to build the new statement.
1230 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001231 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001232 Expr *Operand) {
1233 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001234 }
Sean Huntc3021132010-05-05 15:23:54 +00001235
John McCall07524032011-07-27 21:50:02 +00001236 /// \brief Rebuild the operand to an Objective-C @synchronized statement.
1237 ///
1238 /// By default, performs semantic analysis to build the new statement.
1239 /// Subclasses may override this routine to provide different behavior.
1240 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1241 Expr *object) {
1242 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1243 }
1244
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001245 /// \brief Build a new Objective-C @synchronized statement.
1246 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001247 /// By default, performs semantic analysis to build the new statement.
1248 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001249 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001250 Expr *Object, Stmt *Body) {
1251 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001252 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001253
John McCallf85e1932011-06-15 23:02:42 +00001254 /// \brief Build a new Objective-C @autoreleasepool statement.
1255 ///
1256 /// By default, performs semantic analysis to build the new statement.
1257 /// Subclasses may override this routine to provide different behavior.
1258 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1259 Stmt *Body) {
1260 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1261 }
John McCall990567c2011-07-27 01:07:15 +00001262
1263 /// \brief Build the collection operand to a new Objective-C fast
1264 /// enumeration statement.
1265 ///
1266 /// By default, performs semantic analysis to build the new statement.
1267 /// Subclasses may override this routine to provide different behavior.
1268 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1269 Expr *collection) {
1270 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1271 }
John McCallf85e1932011-06-15 23:02:42 +00001272
Douglas Gregorc3203e72010-04-22 23:10:45 +00001273 /// \brief Build a new Objective-C fast enumeration statement.
1274 ///
1275 /// By default, performs semantic analysis to build the new statement.
1276 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001277 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001278 SourceLocation LParenLoc,
1279 Stmt *Element,
1280 Expr *Collection,
1281 SourceLocation RParenLoc,
1282 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001283 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001284 Element,
1285 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001286 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001287 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001288 }
Sean Huntc3021132010-05-05 15:23:54 +00001289
Douglas Gregor43959a92009-08-20 07:17:43 +00001290 /// \brief Build a new C++ exception declaration.
1291 ///
1292 /// By default, performs semantic analysis to build the new decaration.
1293 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001294 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001295 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001296 SourceLocation StartLoc,
1297 SourceLocation IdLoc,
1298 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001299 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1300 StartLoc, IdLoc, Id);
1301 if (Var)
1302 getSema().CurContext->addDecl(Var);
1303 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001304 }
1305
1306 /// \brief Build a new C++ catch statement.
1307 ///
1308 /// By default, performs semantic analysis to build the new statement.
1309 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001310 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001311 VarDecl *ExceptionDecl,
1312 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001313 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1314 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001315 }
Mike Stump1eb44332009-09-09 15:08:12 +00001316
Douglas Gregor43959a92009-08-20 07:17:43 +00001317 /// \brief Build a new C++ try statement.
1318 ///
1319 /// By default, performs semantic analysis to build the new statement.
1320 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001321 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001322 Stmt *TryBlock,
1323 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001324 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001325 }
Mike Stump1eb44332009-09-09 15:08:12 +00001326
Richard Smithad762fc2011-04-14 22:09:26 +00001327 /// \brief Build a new C++0x range-based for statement.
1328 ///
1329 /// By default, performs semantic analysis to build the new statement.
1330 /// Subclasses may override this routine to provide different behavior.
1331 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1332 SourceLocation ColonLoc,
1333 Stmt *Range, Stmt *BeginEnd,
1334 Expr *Cond, Expr *Inc,
1335 Stmt *LoopVar,
1336 SourceLocation RParenLoc) {
1337 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1338 Cond, Inc, LoopVar, RParenLoc);
1339 }
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.
1345 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1346 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 }
1361
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 }
Sean Huntc3021132010-05-05 15:23:54 +00001451
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001452 /// \brief Build a new sizeof, alignof or vec_step expression with a
1453 /// 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
Douglas Gregorb98b1992009-08-11 05:31:07 +00001477 return move(Result);
1478 }
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,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001502 move(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
Douglas Gregore48319a2009-11-09 17:16:50 +00001637 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1638 if (Result.isInvalid() || ResultTy->isDependentType())
1639 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +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);
1645 return move(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
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 ArrayExprs.release();
1664 return move(Result);
1665 }
Mike Stump1eb44332009-09-09 15:08:12 +00001666
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001668 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 /// By default, builds the implicit value initialization without performing
1670 /// any semantic analysis. Subclasses may override this routine to provide
1671 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001672 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1674 }
Mike Stump1eb44332009-09-09 15:08:12 +00001675
Douglas Gregorb98b1992009-08-11 05:31:07 +00001676 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001677 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001678 /// By default, performs semantic analysis to build the new expression.
1679 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001680 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001681 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001682 SourceLocation RParenLoc) {
1683 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001684 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001685 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001686 }
1687
1688 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001689 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001690 /// By default, performs semantic analysis to build the new expression.
1691 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001692 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001693 MultiExprArg SubExprs,
1694 SourceLocation RParenLoc) {
1695 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 }
Mike Stump1eb44332009-09-09 15:08:12 +00001697
Douglas Gregorb98b1992009-08-11 05:31:07 +00001698 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001699 ///
1700 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001701 /// rather than attempting to map the label statement itself.
1702 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001703 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001704 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001705 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001706 }
Mike Stump1eb44332009-09-09 15:08:12 +00001707
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001709 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 /// By default, performs semantic analysis to build the new expression.
1711 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001712 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001713 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001714 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001715 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001716 }
Mike Stump1eb44332009-09-09 15:08:12 +00001717
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 /// \brief Build a new __builtin_choose_expr expression.
1719 ///
1720 /// By default, performs semantic analysis to build the new expression.
1721 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001722 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001723 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001724 SourceLocation RParenLoc) {
1725 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001726 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001727 RParenLoc);
1728 }
Mike Stump1eb44332009-09-09 15:08:12 +00001729
Peter Collingbournef111d932011-04-15 00:35:48 +00001730 /// \brief Build a new generic selection expression.
1731 ///
1732 /// By default, performs semantic analysis to build the new expression.
1733 /// Subclasses may override this routine to provide different behavior.
1734 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1735 SourceLocation DefaultLoc,
1736 SourceLocation RParenLoc,
1737 Expr *ControllingExpr,
1738 TypeSourceInfo **Types,
1739 Expr **Exprs,
1740 unsigned NumAssocs) {
1741 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1742 ControllingExpr, Types, Exprs,
1743 NumAssocs);
1744 }
1745
Douglas Gregorb98b1992009-08-11 05:31:07 +00001746 /// \brief Build a new overloaded operator call expression.
1747 ///
1748 /// By default, performs semantic analysis to build the new expression.
1749 /// The semantic analysis provides the behavior of template instantiation,
1750 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001751 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001752 /// argument-dependent lookup, etc. Subclasses may override this routine to
1753 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001754 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001756 Expr *Callee,
1757 Expr *First,
1758 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001759
1760 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001761 /// reinterpret_cast.
1762 ///
1763 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001764 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001766 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001767 Stmt::StmtClass Class,
1768 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001769 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001770 SourceLocation RAngleLoc,
1771 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001772 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001773 SourceLocation RParenLoc) {
1774 switch (Class) {
1775 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001776 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001777 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001778 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001779
1780 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001781 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001782 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001783 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001784
Douglas Gregorb98b1992009-08-11 05:31:07 +00001785 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001786 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001787 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001788 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001790
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001792 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001793 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001794 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001795
Douglas Gregorb98b1992009-08-11 05:31:07 +00001796 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001797 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001798 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 }
Mike Stump1eb44332009-09-09 15:08:12 +00001800
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 /// \brief Build a new C++ static_cast expression.
1802 ///
1803 /// By default, performs semantic analysis to build the new expression.
1804 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001805 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001807 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001808 SourceLocation RAngleLoc,
1809 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001810 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001812 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001813 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001814 SourceRange(LAngleLoc, RAngleLoc),
1815 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001816 }
1817
1818 /// \brief Build a new C++ dynamic_cast expression.
1819 ///
1820 /// By default, performs semantic analysis to build the new expression.
1821 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001822 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001823 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001824 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001825 SourceLocation RAngleLoc,
1826 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001827 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001828 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001829 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001830 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001831 SourceRange(LAngleLoc, RAngleLoc),
1832 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001833 }
1834
1835 /// \brief Build a new C++ reinterpret_cast expression.
1836 ///
1837 /// By default, performs semantic analysis to build the new expression.
1838 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001839 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001840 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001841 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001842 SourceLocation RAngleLoc,
1843 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001844 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001845 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001846 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001847 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001848 SourceRange(LAngleLoc, RAngleLoc),
1849 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001850 }
1851
1852 /// \brief Build a new C++ const_cast expression.
1853 ///
1854 /// By default, performs semantic analysis to build the new expression.
1855 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001856 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001857 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001858 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001859 SourceLocation RAngleLoc,
1860 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001861 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001862 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001863 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001864 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001865 SourceRange(LAngleLoc, RAngleLoc),
1866 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001867 }
Mike Stump1eb44332009-09-09 15:08:12 +00001868
Douglas Gregorb98b1992009-08-11 05:31:07 +00001869 /// \brief Build a new C++ functional-style cast expression.
1870 ///
1871 /// By default, performs semantic analysis to build the new expression.
1872 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001873 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1874 SourceLocation LParenLoc,
1875 Expr *Sub,
1876 SourceLocation RParenLoc) {
1877 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001878 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001879 RParenLoc);
1880 }
Mike Stump1eb44332009-09-09 15:08:12 +00001881
Douglas Gregorb98b1992009-08-11 05:31:07 +00001882 /// \brief Build a new C++ typeid(type) expression.
1883 ///
1884 /// By default, performs semantic analysis to build the new expression.
1885 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001886 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001887 SourceLocation TypeidLoc,
1888 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001890 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001891 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001892 }
Mike Stump1eb44332009-09-09 15:08:12 +00001893
Francois Pichet01b7c302010-09-08 12:20:18 +00001894
Douglas Gregorb98b1992009-08-11 05:31:07 +00001895 /// \brief Build a new C++ typeid(expr) expression.
1896 ///
1897 /// By default, performs semantic analysis to build the new expression.
1898 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001899 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001900 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001901 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001902 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001903 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001904 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001905 }
1906
Francois Pichet01b7c302010-09-08 12:20:18 +00001907 /// \brief Build a new C++ __uuidof(type) expression.
1908 ///
1909 /// By default, performs semantic analysis to build the new expression.
1910 /// Subclasses may override this routine to provide different behavior.
1911 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1912 SourceLocation TypeidLoc,
1913 TypeSourceInfo *Operand,
1914 SourceLocation RParenLoc) {
1915 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1916 RParenLoc);
1917 }
1918
1919 /// \brief Build a new C++ __uuidof(expr) expression.
1920 ///
1921 /// By default, performs semantic analysis to build the new expression.
1922 /// Subclasses may override this routine to provide different behavior.
1923 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1924 SourceLocation TypeidLoc,
1925 Expr *Operand,
1926 SourceLocation RParenLoc) {
1927 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1928 RParenLoc);
1929 }
1930
Douglas Gregorb98b1992009-08-11 05:31:07 +00001931 /// \brief Build a new C++ "this" expression.
1932 ///
1933 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001934 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001936 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001937 QualType ThisType,
1938 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001939 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001940 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001941 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1942 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001943 }
1944
1945 /// \brief Build a new C++ throw expression.
1946 ///
1947 /// By default, performs semantic analysis to build the new expression.
1948 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001949 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1950 bool IsThrownVariableInScope) {
1951 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952 }
1953
1954 /// \brief Build a new C++ default-argument expression.
1955 ///
1956 /// By default, builds a new default-argument expression, which does not
1957 /// require any semantic analysis. Subclasses may override this routine to
1958 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001959 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001960 ParmVarDecl *Param) {
1961 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1962 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001963 }
1964
1965 /// \brief Build a new C++ zero-initialization expression.
1966 ///
1967 /// By default, performs semantic analysis to build the new expression.
1968 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001969 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1970 SourceLocation LParenLoc,
1971 SourceLocation RParenLoc) {
1972 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001973 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001974 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001975 }
Mike Stump1eb44332009-09-09 15:08:12 +00001976
Douglas Gregorb98b1992009-08-11 05:31:07 +00001977 /// \brief Build a new C++ "new" expression.
1978 ///
1979 /// By default, performs semantic analysis to build the new expression.
1980 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001981 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001982 bool UseGlobal,
1983 SourceLocation PlacementLParen,
1984 MultiExprArg PlacementArgs,
1985 SourceLocation PlacementRParen,
1986 SourceRange TypeIdParens,
1987 QualType AllocatedType,
1988 TypeSourceInfo *AllocatedTypeInfo,
1989 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001990 SourceRange DirectInitRange,
1991 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001992 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001993 PlacementLParen,
1994 move(PlacementArgs),
1995 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001996 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001997 AllocatedType,
1998 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001999 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002000 DirectInitRange,
2001 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002002 }
Mike Stump1eb44332009-09-09 15:08:12 +00002003
Douglas Gregorb98b1992009-08-11 05:31:07 +00002004 /// \brief Build a new C++ "delete" expression.
2005 ///
2006 /// By default, performs semantic analysis to build the new expression.
2007 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002008 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002009 bool IsGlobalDelete,
2010 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002011 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002012 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002013 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002014 }
Mike Stump1eb44332009-09-09 15:08:12 +00002015
Douglas Gregorb98b1992009-08-11 05:31:07 +00002016 /// \brief Build a new unary type trait expression.
2017 ///
2018 /// By default, performs semantic analysis to build the new expression.
2019 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002020 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002021 SourceLocation StartLoc,
2022 TypeSourceInfo *T,
2023 SourceLocation RParenLoc) {
2024 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002025 }
2026
Francois Pichet6ad6f282010-12-07 00:08:36 +00002027 /// \brief Build a new binary type trait expression.
2028 ///
2029 /// By default, performs semantic analysis to build the new expression.
2030 /// Subclasses may override this routine to provide different behavior.
2031 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2032 SourceLocation StartLoc,
2033 TypeSourceInfo *LhsT,
2034 TypeSourceInfo *RhsT,
2035 SourceLocation RParenLoc) {
2036 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2037 }
2038
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002039 /// \brief Build a new type trait expression.
2040 ///
2041 /// By default, performs semantic analysis to build the new expression.
2042 /// Subclasses may override this routine to provide different behavior.
2043 ExprResult RebuildTypeTrait(TypeTrait Trait,
2044 SourceLocation StartLoc,
2045 ArrayRef<TypeSourceInfo *> Args,
2046 SourceLocation RParenLoc) {
2047 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2048 }
2049
John Wiegley21ff2e52011-04-28 00:16:57 +00002050 /// \brief Build a new array type trait expression.
2051 ///
2052 /// By default, performs semantic analysis to build the new expression.
2053 /// Subclasses may override this routine to provide different behavior.
2054 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2055 SourceLocation StartLoc,
2056 TypeSourceInfo *TSInfo,
2057 Expr *DimExpr,
2058 SourceLocation RParenLoc) {
2059 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2060 }
2061
John Wiegley55262202011-04-25 06:54:41 +00002062 /// \brief Build a new expression trait expression.
2063 ///
2064 /// By default, performs semantic analysis to build the new expression.
2065 /// Subclasses may override this routine to provide different behavior.
2066 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2067 SourceLocation StartLoc,
2068 Expr *Queried,
2069 SourceLocation RParenLoc) {
2070 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2071 }
2072
Mike Stump1eb44332009-09-09 15:08:12 +00002073 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002074 /// expression.
2075 ///
2076 /// By default, performs semantic analysis to build the new expression.
2077 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002078 ExprResult RebuildDependentScopeDeclRefExpr(
2079 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002080 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002081 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002082 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002083 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002084 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002085
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002086 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002087 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002088 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002089
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002090 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
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) {
John McCallca0408f2010-08-23 06:44:23 +00002119 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002120 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002121 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002122 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002123
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002124 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002125 move_arg(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,
2141 move(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,
2155 move(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.
2214 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2215 SourceLocation PackLoc,
2216 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002217 llvm::Optional<unsigned> Length) {
2218 if (Length)
2219 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2220 OperatorLoc, Pack, PackLoc,
2221 RParenLoc, *Length);
2222
Douglas Gregoree8aff02011-01-04 17:33:58 +00002223 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
2228 /// \brief Build a new Objective-C array literal.
2229 ///
2230 /// By default, performs semantic analysis to build the new expression.
2231 /// Subclasses may override this routine to provide different behavior.
2232 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2233 Expr **Elements, unsigned NumElements) {
2234 return getSema().BuildObjCArrayLiteral(Range,
2235 MultiExprArg(Elements, NumElements));
2236 }
2237
2238 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
2239 Expr *Base, Expr *Key,
2240 ObjCMethodDecl *getterMethod,
2241 ObjCMethodDecl *setterMethod) {
2242 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2243 getterMethod, setterMethod);
2244 }
2245
2246 /// \brief Build a new Objective-C dictionary literal.
2247 ///
2248 /// By default, performs semantic analysis to build the new expression.
2249 /// Subclasses may override this routine to provide different behavior.
2250 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2251 ObjCDictionaryElement *Elements,
2252 unsigned NumElements) {
2253 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2254 }
2255
Douglas Gregorb98b1992009-08-11 05:31:07 +00002256 /// \brief Build a new Objective-C @encode expression.
2257 ///
2258 /// By default, performs semantic analysis to build the new expression.
2259 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002260 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002261 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002262 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002263 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002264 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002265 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002266
Douglas Gregor92e986e2010-04-22 16:44:27 +00002267 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002268 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002269 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002270 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002271 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002272 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002273 MultiExprArg Args,
2274 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002275 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2276 ReceiverTypeInfo->getType(),
2277 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002278 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002279 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002280 }
2281
2282 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002283 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002284 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002285 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002286 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002287 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002288 MultiExprArg Args,
2289 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002290 return SemaRef.BuildInstanceMessage(Receiver,
2291 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002292 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002293 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002294 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002295 }
2296
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002297 /// \brief Build a new Objective-C ivar reference expression.
2298 ///
2299 /// By default, performs semantic analysis to build the new expression.
2300 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002301 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002302 SourceLocation IvarLoc,
2303 bool IsArrow, bool IsFreeIvar) {
2304 // FIXME: We lose track of the IsFreeIvar bit.
2305 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002306 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002307 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2308 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002309 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002310 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002311 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002312 false);
John Wiegley429bb272011-04-08 18:41:53 +00002313 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002314 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002315
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002316 if (Result.get())
2317 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002318
John Wiegley429bb272011-04-08 18:41:53 +00002319 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002320 /*FIXME:*/IvarLoc, IsArrow,
2321 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002322 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002323 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002324 /*TemplateArgs=*/0);
2325 }
Douglas Gregore3303542010-04-26 20:47:02 +00002326
2327 /// \brief Build a new Objective-C property reference expression.
2328 ///
2329 /// By default, performs semantic analysis to build the new expression.
2330 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002331 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002332 ObjCPropertyDecl *Property,
2333 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002334 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002335 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002336 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2337 Sema::LookupMemberName);
2338 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002339 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002340 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002341 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002342 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002343 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002344
Douglas Gregore3303542010-04-26 20:47:02 +00002345 if (Result.get())
2346 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002347
John Wiegley429bb272011-04-08 18:41:53 +00002348 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002349 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002350 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002351 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002352 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002353 /*TemplateArgs=*/0);
2354 }
Sean Huntc3021132010-05-05 15:23:54 +00002355
John McCall12f78a62010-12-02 01:19:52 +00002356 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002357 ///
2358 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002359 /// Subclasses may override this routine to provide different behavior.
2360 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2361 ObjCMethodDecl *Getter,
2362 ObjCMethodDecl *Setter,
2363 SourceLocation PropertyLoc) {
2364 // Since these expressions can only be value-dependent, we do not
2365 // need to perform semantic analysis again.
2366 return Owned(
2367 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2368 VK_LValue, OK_ObjCProperty,
2369 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002370 }
2371
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002372 /// \brief Build a new Objective-C "isa" expression.
2373 ///
2374 /// By default, performs semantic analysis to build the new expression.
2375 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002376 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002377 bool IsArrow) {
2378 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002379 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002380 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2381 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002382 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002383 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002384 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002385 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002386 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002387
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002388 if (Result.get())
2389 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002390
John Wiegley429bb272011-04-08 18:41:53 +00002391 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002392 /*FIXME:*/IsaLoc, IsArrow,
2393 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002394 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002395 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002396 /*TemplateArgs=*/0);
2397 }
Sean Huntc3021132010-05-05 15:23:54 +00002398
Douglas Gregorb98b1992009-08-11 05:31:07 +00002399 /// \brief Build a new shuffle vector expression.
2400 ///
2401 /// By default, performs semantic analysis to build the new expression.
2402 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002403 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002404 MultiExprArg SubExprs,
2405 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002406 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002407 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002408 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2409 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2410 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2411 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002412
Douglas Gregorb98b1992009-08-11 05:31:07 +00002413 // Build a reference to the __builtin_shufflevector builtin
2414 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002415 ExprResult Callee
John McCallf4b88a42012-03-10 09:33:50 +00002416 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false,
2417 Builtin->getType(),
John Wiegley429bb272011-04-08 18:41:53 +00002418 VK_LValue, BuiltinLoc));
2419 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2420 if (Callee.isInvalid())
2421 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002422
2423 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002424 unsigned NumSubExprs = SubExprs.size();
2425 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002426 ExprResult TheCall = SemaRef.Owned(
2427 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002428 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002429 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002430 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002431 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002432
Douglas Gregorb98b1992009-08-11 05:31:07 +00002433 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002434 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002435 }
John McCall43fed0d2010-11-12 08:19:04 +00002436
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002437 /// \brief Build a new template argument pack expansion.
2438 ///
2439 /// By default, performs semantic analysis to build a new pack expansion
2440 /// for a template argument. Subclasses may override this routine to provide
2441 /// different behavior.
2442 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002443 SourceLocation EllipsisLoc,
2444 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002445 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002446 case TemplateArgument::Expression: {
2447 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002448 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2449 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002450 if (Result.isInvalid())
2451 return TemplateArgumentLoc();
2452
2453 return TemplateArgumentLoc(Result.get(), Result.get());
2454 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002455
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002456 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002457 return TemplateArgumentLoc(TemplateArgument(
2458 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002459 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002460 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002461 Pattern.getTemplateNameLoc(),
2462 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002463
2464 case TemplateArgument::Null:
2465 case TemplateArgument::Integral:
2466 case TemplateArgument::Declaration:
2467 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002468 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002469 llvm_unreachable("Pack expansion pattern has no parameter packs");
2470
2471 case TemplateArgument::Type:
2472 if (TypeSourceInfo *Expansion
2473 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002474 EllipsisLoc,
2475 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002476 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2477 Expansion);
2478 break;
2479 }
2480
2481 return TemplateArgumentLoc();
2482 }
2483
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002484 /// \brief Build a new expression pack expansion.
2485 ///
2486 /// By default, performs semantic analysis to build a new pack expansion
2487 /// for an expression. Subclasses may override this routine to provide
2488 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002489 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2490 llvm::Optional<unsigned> NumExpansions) {
2491 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002492 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002493
2494 /// \brief Build a new atomic operation expression.
2495 ///
2496 /// By default, performs semantic analysis to build the new expression.
2497 /// Subclasses may override this routine to provide different behavior.
2498 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2499 MultiExprArg SubExprs,
2500 QualType RetTy,
2501 AtomicExpr::AtomicOp Op,
2502 SourceLocation RParenLoc) {
2503 // Just create the expression; there is not any interesting semantic
2504 // analysis here because we can't actually build an AtomicExpr until
2505 // we are sure it is semantically sound.
2506 unsigned NumSubExprs = SubExprs.size();
2507 Expr **Subs = (Expr **)SubExprs.release();
2508 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2509 NumSubExprs, RetTy, Op,
2510 RParenLoc);
2511 }
2512
John McCall43fed0d2010-11-12 08:19:04 +00002513private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002514 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2515 QualType ObjectType,
2516 NamedDecl *FirstQualifierInScope,
2517 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002518
2519 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2520 QualType ObjectType,
2521 NamedDecl *FirstQualifierInScope,
2522 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002523};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002524
Douglas Gregor43959a92009-08-20 07:17:43 +00002525template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002526StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002527 if (!S)
2528 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002529
Douglas Gregor43959a92009-08-20 07:17:43 +00002530 switch (S->getStmtClass()) {
2531 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002532
Douglas Gregor43959a92009-08-20 07:17:43 +00002533 // Transform individual statement nodes
2534#define STMT(Node, Parent) \
2535 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002536#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002537#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002538#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002539
Douglas Gregor43959a92009-08-20 07:17:43 +00002540 // Transform expressions by calling TransformExpr.
2541#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002542#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002543#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002544#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002545 {
John McCall60d7b3a2010-08-24 06:29:42 +00002546 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002547 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002548 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002549
John McCall9ae2f072010-08-23 23:25:46 +00002550 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002551 }
Mike Stump1eb44332009-09-09 15:08:12 +00002552 }
2553
John McCall3fa5cae2010-10-26 07:05:15 +00002554 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002555}
Mike Stump1eb44332009-09-09 15:08:12 +00002556
2557
Douglas Gregor670444e2009-08-04 22:27:00 +00002558template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002559ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002560 if (!E)
2561 return SemaRef.Owned(E);
2562
2563 switch (E->getStmtClass()) {
2564 case Stmt::NoStmtClass: break;
2565#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002566#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002567#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002568 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002569#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002570 }
2571
John McCall3fa5cae2010-10-26 07:05:15 +00002572 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002573}
2574
2575template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002576bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2577 unsigned NumInputs,
2578 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002579 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002580 bool *ArgChanged) {
2581 for (unsigned I = 0; I != NumInputs; ++I) {
2582 // If requested, drop call arguments that need to be dropped.
2583 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2584 if (ArgChanged)
2585 *ArgChanged = true;
2586
2587 break;
2588 }
2589
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002590 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2591 Expr *Pattern = Expansion->getPattern();
2592
Chris Lattner686775d2011-07-20 06:58:45 +00002593 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002594 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2595 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2596
2597 // Determine whether the set of unexpanded parameter packs can and should
2598 // be expanded.
2599 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002600 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002601 llvm::Optional<unsigned> OrigNumExpansions
2602 = Expansion->getNumExpansions();
2603 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002604 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2605 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002606 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002607 Expand, RetainExpansion,
2608 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002609 return true;
2610
2611 if (!Expand) {
2612 // The transform has determined that we should perform a simple
2613 // transformation on the pack expansion, producing another pack
2614 // expansion.
2615 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2616 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2617 if (OutPattern.isInvalid())
2618 return true;
2619
2620 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002621 Expansion->getEllipsisLoc(),
2622 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002623 if (Out.isInvalid())
2624 return true;
2625
2626 if (ArgChanged)
2627 *ArgChanged = true;
2628 Outputs.push_back(Out.get());
2629 continue;
2630 }
John McCallc8fc90a2011-07-06 07:30:07 +00002631
2632 // Record right away that the argument was changed. This needs
2633 // to happen even if the array expands to nothing.
2634 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002635
2636 // The transform has determined that we should perform an elementwise
2637 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002638 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002639 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2640 ExprResult Out = getDerived().TransformExpr(Pattern);
2641 if (Out.isInvalid())
2642 return true;
2643
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002644 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002645 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2646 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002647 if (Out.isInvalid())
2648 return true;
2649 }
2650
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002651 Outputs.push_back(Out.get());
2652 }
2653
2654 continue;
2655 }
2656
Douglas Gregoraa165f82011-01-03 19:04:46 +00002657 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2658 if (Result.isInvalid())
2659 return true;
2660
2661 if (Result.get() != Inputs[I] && ArgChanged)
2662 *ArgChanged = true;
2663
2664 Outputs.push_back(Result.get());
2665 }
2666
2667 return false;
2668}
2669
2670template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002671NestedNameSpecifierLoc
2672TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2673 NestedNameSpecifierLoc NNS,
2674 QualType ObjectType,
2675 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002676 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002677 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2678 Qualifier = Qualifier.getPrefix())
2679 Qualifiers.push_back(Qualifier);
2680
2681 CXXScopeSpec SS;
2682 while (!Qualifiers.empty()) {
2683 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2684 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2685
2686 switch (QNNS->getKind()) {
2687 case NestedNameSpecifier::Identifier:
2688 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2689 *QNNS->getAsIdentifier(),
2690 Q.getLocalBeginLoc(),
2691 Q.getLocalEndLoc(),
2692 ObjectType, false, SS,
2693 FirstQualifierInScope, false))
2694 return NestedNameSpecifierLoc();
2695
2696 break;
2697
2698 case NestedNameSpecifier::Namespace: {
2699 NamespaceDecl *NS
2700 = cast_or_null<NamespaceDecl>(
2701 getDerived().TransformDecl(
2702 Q.getLocalBeginLoc(),
2703 QNNS->getAsNamespace()));
2704 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2705 break;
2706 }
2707
2708 case NestedNameSpecifier::NamespaceAlias: {
2709 NamespaceAliasDecl *Alias
2710 = cast_or_null<NamespaceAliasDecl>(
2711 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2712 QNNS->getAsNamespaceAlias()));
2713 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2714 Q.getLocalEndLoc());
2715 break;
2716 }
2717
2718 case NestedNameSpecifier::Global:
2719 // There is no meaningful transformation that one could perform on the
2720 // global scope.
2721 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2722 break;
2723
2724 case NestedNameSpecifier::TypeSpecWithTemplate:
2725 case NestedNameSpecifier::TypeSpec: {
2726 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2727 FirstQualifierInScope, SS);
2728
2729 if (!TL)
2730 return NestedNameSpecifierLoc();
2731
2732 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
David Blaikie4e4d0842012-03-11 07:00:24 +00002733 (SemaRef.getLangOpts().CPlusPlus0x &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002734 TL.getType()->isEnumeralType())) {
2735 assert(!TL.getType().hasLocalQualifiers() &&
2736 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002737 if (TL.getType()->isEnumeralType())
2738 SemaRef.Diag(TL.getBeginLoc(),
2739 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002740 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2741 Q.getLocalEndLoc());
2742 break;
2743 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002744 // If the nested-name-specifier is an invalid type def, don't emit an
2745 // error because a previous error should have already been emitted.
2746 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2747 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2748 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2749 << TL.getType() << SS.getRange();
2750 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002751 return NestedNameSpecifierLoc();
2752 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002753 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002754
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002755 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002756 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002757 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002758 }
2759
2760 // Don't rebuild the nested-name-specifier if we don't have to.
2761 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2762 !getDerived().AlwaysRebuild())
2763 return NNS;
2764
2765 // If we can re-use the source-location data from the original
2766 // nested-name-specifier, do so.
2767 if (SS.location_size() == NNS.getDataLength() &&
2768 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2769 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2770
2771 // Allocate new nested-name-specifier location information.
2772 return SS.getWithLocInContext(SemaRef.Context);
2773}
2774
2775template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002776DeclarationNameInfo
2777TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002778::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002779 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002780 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002781 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002782
2783 switch (Name.getNameKind()) {
2784 case DeclarationName::Identifier:
2785 case DeclarationName::ObjCZeroArgSelector:
2786 case DeclarationName::ObjCOneArgSelector:
2787 case DeclarationName::ObjCMultiArgSelector:
2788 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002789 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002790 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002791 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002792
Douglas Gregor81499bb2009-09-03 22:13:48 +00002793 case DeclarationName::CXXConstructorName:
2794 case DeclarationName::CXXDestructorName:
2795 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002796 TypeSourceInfo *NewTInfo;
2797 CanQualType NewCanTy;
2798 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002799 NewTInfo = getDerived().TransformType(OldTInfo);
2800 if (!NewTInfo)
2801 return DeclarationNameInfo();
2802 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002803 }
2804 else {
2805 NewTInfo = 0;
2806 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002807 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002808 if (NewT.isNull())
2809 return DeclarationNameInfo();
2810 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2811 }
Mike Stump1eb44332009-09-09 15:08:12 +00002812
Abramo Bagnara25777432010-08-11 22:01:17 +00002813 DeclarationName NewName
2814 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2815 NewCanTy);
2816 DeclarationNameInfo NewNameInfo(NameInfo);
2817 NewNameInfo.setName(NewName);
2818 NewNameInfo.setNamedTypeInfo(NewTInfo);
2819 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002820 }
Mike Stump1eb44332009-09-09 15:08:12 +00002821 }
2822
David Blaikieb219cfc2011-09-23 05:06:16 +00002823 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002824}
2825
2826template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002827TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002828TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2829 TemplateName Name,
2830 SourceLocation NameLoc,
2831 QualType ObjectType,
2832 NamedDecl *FirstQualifierInScope) {
2833 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2834 TemplateDecl *Template = QTN->getTemplateDecl();
2835 assert(Template && "qualified template name must refer to a template");
2836
2837 TemplateDecl *TransTemplate
2838 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2839 Template));
2840 if (!TransTemplate)
2841 return TemplateName();
2842
2843 if (!getDerived().AlwaysRebuild() &&
2844 SS.getScopeRep() == QTN->getQualifier() &&
2845 TransTemplate == Template)
2846 return Name;
2847
2848 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2849 TransTemplate);
2850 }
2851
2852 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2853 if (SS.getScopeRep()) {
2854 // These apply to the scope specifier, not the template.
2855 ObjectType = QualType();
2856 FirstQualifierInScope = 0;
2857 }
2858
2859 if (!getDerived().AlwaysRebuild() &&
2860 SS.getScopeRep() == DTN->getQualifier() &&
2861 ObjectType.isNull())
2862 return Name;
2863
2864 if (DTN->isIdentifier()) {
2865 return getDerived().RebuildTemplateName(SS,
2866 *DTN->getIdentifier(),
2867 NameLoc,
2868 ObjectType,
2869 FirstQualifierInScope);
2870 }
2871
2872 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2873 ObjectType);
2874 }
2875
2876 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2877 TemplateDecl *TransTemplate
2878 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2879 Template));
2880 if (!TransTemplate)
2881 return TemplateName();
2882
2883 if (!getDerived().AlwaysRebuild() &&
2884 TransTemplate == Template)
2885 return Name;
2886
2887 return TemplateName(TransTemplate);
2888 }
2889
2890 if (SubstTemplateTemplateParmPackStorage *SubstPack
2891 = Name.getAsSubstTemplateTemplateParmPack()) {
2892 TemplateTemplateParmDecl *TransParam
2893 = cast_or_null<TemplateTemplateParmDecl>(
2894 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2895 if (!TransParam)
2896 return TemplateName();
2897
2898 if (!getDerived().AlwaysRebuild() &&
2899 TransParam == SubstPack->getParameterPack())
2900 return Name;
2901
2902 return getDerived().RebuildTemplateName(TransParam,
2903 SubstPack->getArgumentPack());
2904 }
2905
2906 // These should be getting filtered out before they reach the AST.
2907 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002908}
2909
2910template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002911void TreeTransform<Derived>::InventTemplateArgumentLoc(
2912 const TemplateArgument &Arg,
2913 TemplateArgumentLoc &Output) {
2914 SourceLocation Loc = getDerived().getBaseLocation();
2915 switch (Arg.getKind()) {
2916 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002917 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002918 break;
2919
2920 case TemplateArgument::Type:
2921 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002922 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002923
John McCall833ca992009-10-29 08:12:44 +00002924 break;
2925
Douglas Gregor788cd062009-11-11 01:00:40 +00002926 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002927 case TemplateArgument::TemplateExpansion: {
2928 NestedNameSpecifierLocBuilder Builder;
2929 TemplateName Template = Arg.getAsTemplate();
2930 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2931 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2932 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2933 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2934
2935 if (Arg.getKind() == TemplateArgument::Template)
2936 Output = TemplateArgumentLoc(Arg,
2937 Builder.getWithLocInContext(SemaRef.Context),
2938 Loc);
2939 else
2940 Output = TemplateArgumentLoc(Arg,
2941 Builder.getWithLocInContext(SemaRef.Context),
2942 Loc, Loc);
2943
Douglas Gregor788cd062009-11-11 01:00:40 +00002944 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002945 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002946
John McCall833ca992009-10-29 08:12:44 +00002947 case TemplateArgument::Expression:
2948 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2949 break;
2950
2951 case TemplateArgument::Declaration:
2952 case TemplateArgument::Integral:
2953 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002954 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002955 break;
2956 }
2957}
2958
2959template<typename Derived>
2960bool TreeTransform<Derived>::TransformTemplateArgument(
2961 const TemplateArgumentLoc &Input,
2962 TemplateArgumentLoc &Output) {
2963 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002964 switch (Arg.getKind()) {
2965 case TemplateArgument::Null:
2966 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002967 Output = Input;
2968 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002969
Douglas Gregor670444e2009-08-04 22:27:00 +00002970 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002971 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002972 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002973 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002974
2975 DI = getDerived().TransformType(DI);
2976 if (!DI) return true;
2977
2978 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2979 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002980 }
Mike Stump1eb44332009-09-09 15:08:12 +00002981
Douglas Gregor670444e2009-08-04 22:27:00 +00002982 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002983 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002984 DeclarationName Name;
2985 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2986 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002987 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002988 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002989 if (!D) return true;
2990
John McCall828bff22009-10-29 18:45:58 +00002991 Expr *SourceExpr = Input.getSourceDeclExpression();
2992 if (SourceExpr) {
2993 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002994 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002995 ExprResult E = getDerived().TransformExpr(SourceExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00002996 E = SemaRef.ActOnConstantExpression(E);
John McCall9ae2f072010-08-23 23:25:46 +00002997 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002998 }
2999
3000 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00003001 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003002 }
Mike Stump1eb44332009-09-09 15:08:12 +00003003
Douglas Gregor788cd062009-11-11 01:00:40 +00003004 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003005 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3006 if (QualifierLoc) {
3007 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3008 if (!QualifierLoc)
3009 return true;
3010 }
3011
Douglas Gregor1d752d72011-03-02 18:46:51 +00003012 CXXScopeSpec SS;
3013 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003014 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003015 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3016 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003017 if (Template.isNull())
3018 return true;
Sean Huntc3021132010-05-05 15:23:54 +00003019
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003020 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003021 Input.getTemplateNameLoc());
3022 return false;
3023 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003024
3025 case TemplateArgument::TemplateExpansion:
3026 llvm_unreachable("Caller should expand pack expansions");
3027
Douglas Gregor670444e2009-08-04 22:27:00 +00003028 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003029 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003030 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003031 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003032
John McCall833ca992009-10-29 08:12:44 +00003033 Expr *InputExpr = Input.getSourceExpression();
3034 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3035
Chris Lattner223de242011-04-25 20:37:58 +00003036 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003037 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003038 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003039 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003040 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003041 }
Mike Stump1eb44332009-09-09 15:08:12 +00003042
Douglas Gregor670444e2009-08-04 22:27:00 +00003043 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00003044 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00003045 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00003046 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00003047 AEnd = Arg.pack_end();
3048 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00003049
John McCall833ca992009-10-29 08:12:44 +00003050 // FIXME: preserve source information here when we start
3051 // caring about parameter packs.
3052
John McCall828bff22009-10-29 18:45:58 +00003053 TemplateArgumentLoc InputArg;
3054 TemplateArgumentLoc OutputArg;
3055 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3056 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00003057 return true;
3058
John McCall828bff22009-10-29 18:45:58 +00003059 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00003060 }
Douglas Gregor910f8002010-11-07 23:05:16 +00003061
3062 TemplateArgument *TransformedArgsPtr
3063 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3064 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3065 TransformedArgsPtr);
3066 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3067 TransformedArgs.size()),
3068 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003069 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003070 }
3071 }
Mike Stump1eb44332009-09-09 15:08:12 +00003072
Douglas Gregor670444e2009-08-04 22:27:00 +00003073 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003074 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003075}
3076
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003077/// \brief Iterator adaptor that invents template argument location information
3078/// for each of the template arguments in its underlying iterator.
3079template<typename Derived, typename InputIterator>
3080class TemplateArgumentLocInventIterator {
3081 TreeTransform<Derived> &Self;
3082 InputIterator Iter;
3083
3084public:
3085 typedef TemplateArgumentLoc value_type;
3086 typedef TemplateArgumentLoc reference;
3087 typedef typename std::iterator_traits<InputIterator>::difference_type
3088 difference_type;
3089 typedef std::input_iterator_tag iterator_category;
3090
3091 class pointer {
3092 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003093
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003094 public:
3095 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3096
3097 const TemplateArgumentLoc *operator->() const { return &Arg; }
3098 };
3099
3100 TemplateArgumentLocInventIterator() { }
3101
3102 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3103 InputIterator Iter)
3104 : Self(Self), Iter(Iter) { }
3105
3106 TemplateArgumentLocInventIterator &operator++() {
3107 ++Iter;
3108 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003109 }
3110
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003111 TemplateArgumentLocInventIterator operator++(int) {
3112 TemplateArgumentLocInventIterator Old(*this);
3113 ++(*this);
3114 return Old;
3115 }
3116
3117 reference operator*() const {
3118 TemplateArgumentLoc Result;
3119 Self.InventTemplateArgumentLoc(*Iter, Result);
3120 return Result;
3121 }
3122
3123 pointer operator->() const { return pointer(**this); }
3124
3125 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3126 const TemplateArgumentLocInventIterator &Y) {
3127 return X.Iter == Y.Iter;
3128 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003129
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003130 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3131 const TemplateArgumentLocInventIterator &Y) {
3132 return X.Iter != Y.Iter;
3133 }
3134};
3135
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003136template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003137template<typename InputIterator>
3138bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3139 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003140 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003141 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003142 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003143 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003144
3145 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3146 // Unpack argument packs, which we translate them into separate
3147 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003148 // FIXME: We could do much better if we could guarantee that the
3149 // TemplateArgumentLocInfo for the pack expansion would be usable for
3150 // all of the template arguments in the argument pack.
3151 typedef TemplateArgumentLocInventIterator<Derived,
3152 TemplateArgument::pack_iterator>
3153 PackLocIterator;
3154 if (TransformTemplateArguments(PackLocIterator(*this,
3155 In.getArgument().pack_begin()),
3156 PackLocIterator(*this,
3157 In.getArgument().pack_end()),
3158 Outputs))
3159 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003160
3161 continue;
3162 }
3163
3164 if (In.getArgument().isPackExpansion()) {
3165 // We have a pack expansion, for which we will be substituting into
3166 // the pattern.
3167 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003168 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003169 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003170 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3171 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003172
Chris Lattner686775d2011-07-20 06:58:45 +00003173 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003174 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3175 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3176
3177 // Determine whether the set of unexpanded parameter packs can and should
3178 // be expanded.
3179 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003180 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003181 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003182 if (getDerived().TryExpandParameterPacks(Ellipsis,
3183 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003184 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003185 Expand,
3186 RetainExpansion,
3187 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003188 return true;
3189
3190 if (!Expand) {
3191 // The transform has determined that we should perform a simple
3192 // transformation on the pack expansion, producing another pack
3193 // expansion.
3194 TemplateArgumentLoc OutPattern;
3195 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3196 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3197 return true;
3198
Douglas Gregorcded4f62011-01-14 17:04:44 +00003199 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3200 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003201 if (Out.getArgument().isNull())
3202 return true;
3203
3204 Outputs.addArgument(Out);
3205 continue;
3206 }
3207
3208 // The transform has determined that we should perform an elementwise
3209 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003210 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003211 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3212
3213 if (getDerived().TransformTemplateArgument(Pattern, Out))
3214 return true;
3215
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003216 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003217 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3218 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003219 if (Out.getArgument().isNull())
3220 return true;
3221 }
3222
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003223 Outputs.addArgument(Out);
3224 }
3225
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003226 // If we're supposed to retain a pack expansion, do so by temporarily
3227 // forgetting the partially-substituted parameter pack.
3228 if (RetainExpansion) {
3229 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3230
3231 if (getDerived().TransformTemplateArgument(Pattern, Out))
3232 return true;
3233
Douglas Gregorcded4f62011-01-14 17:04:44 +00003234 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3235 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003236 if (Out.getArgument().isNull())
3237 return true;
3238
3239 Outputs.addArgument(Out);
3240 }
Douglas Gregord3731192011-01-10 07:32:04 +00003241
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003242 continue;
3243 }
3244
3245 // The simple case:
3246 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003247 return true;
3248
3249 Outputs.addArgument(Out);
3250 }
3251
3252 return false;
3253
3254}
3255
Douglas Gregor577f75a2009-08-04 16:50:30 +00003256//===----------------------------------------------------------------------===//
3257// Type transformation
3258//===----------------------------------------------------------------------===//
3259
3260template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003261QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003262 if (getDerived().AlreadyTransformed(T))
3263 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003264
John McCalla2becad2009-10-21 00:40:46 +00003265 // Temporary workaround. All of these transformations should
3266 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003267 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3268 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003269
John McCall43fed0d2010-11-12 08:19:04 +00003270 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003271
John McCalla2becad2009-10-21 00:40:46 +00003272 if (!NewDI)
3273 return QualType();
3274
3275 return NewDI->getType();
3276}
3277
3278template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003279TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003280 // Refine the base location to the type's location.
3281 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3282 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003283 if (getDerived().AlreadyTransformed(DI->getType()))
3284 return DI;
3285
3286 TypeLocBuilder TLB;
3287
3288 TypeLoc TL = DI->getTypeLoc();
3289 TLB.reserve(TL.getFullDataSize());
3290
John McCall43fed0d2010-11-12 08:19:04 +00003291 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003292 if (Result.isNull())
3293 return 0;
3294
John McCalla93c9342009-12-07 02:54:59 +00003295 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003296}
3297
3298template<typename Derived>
3299QualType
John McCall43fed0d2010-11-12 08:19:04 +00003300TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003301 switch (T.getTypeLocClass()) {
3302#define ABSTRACT_TYPELOC(CLASS, PARENT)
3303#define TYPELOC(CLASS, PARENT) \
3304 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003305 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003306#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003307 }
Mike Stump1eb44332009-09-09 15:08:12 +00003308
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003309 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003310}
3311
3312/// FIXME: By default, this routine adds type qualifiers only to types
3313/// that can have qualifiers, and silently suppresses those qualifiers
3314/// that are not permitted (e.g., qualifiers on reference or function
3315/// types). This is the right thing for template instantiation, but
3316/// probably not for other clients.
3317template<typename Derived>
3318QualType
3319TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003320 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003321 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003322
John McCall43fed0d2010-11-12 08:19:04 +00003323 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003324 if (Result.isNull())
3325 return QualType();
3326
3327 // Silently suppress qualifiers if the result type can't be qualified.
3328 // FIXME: this is the right thing for template instantiation, but
3329 // probably not for other clients.
3330 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003331 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003332
John McCallf85e1932011-06-15 23:02:42 +00003333 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003334 // resulting type.
3335 if (Quals.hasObjCLifetime()) {
3336 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3337 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003338 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003339 // Objective-C ARC:
3340 // A lifetime qualifier applied to a substituted template parameter
3341 // overrides the lifetime qualifier from the template argument.
3342 if (const SubstTemplateTypeParmType *SubstTypeParam
3343 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3344 QualType Replacement = SubstTypeParam->getReplacementType();
3345 Qualifiers Qs = Replacement.getQualifiers();
3346 Qs.removeObjCLifetime();
3347 Replacement
3348 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3349 Qs);
3350 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3351 SubstTypeParam->getReplacedParameter(),
3352 Replacement);
3353 TLB.TypeWasModifiedSafely(Result);
3354 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003355 // Otherwise, complain about the addition of a qualifier to an
3356 // already-qualified type.
3357 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003358 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003359 << Result << R;
3360
Douglas Gregore559ca12011-06-17 22:11:49 +00003361 Quals.removeObjCLifetime();
3362 }
3363 }
3364 }
John McCall28654742010-06-05 06:41:15 +00003365 if (!Quals.empty()) {
3366 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3367 TLB.push<QualifiedTypeLoc>(Result);
3368 // No location information to preserve.
3369 }
John McCalla2becad2009-10-21 00:40:46 +00003370
3371 return Result;
3372}
3373
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003374template<typename Derived>
3375TypeLoc
3376TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3377 QualType ObjectType,
3378 NamedDecl *UnqualLookup,
3379 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003380 QualType T = TL.getType();
3381 if (getDerived().AlreadyTransformed(T))
3382 return TL;
3383
3384 TypeLocBuilder TLB;
3385 QualType Result;
3386
3387 if (isa<TemplateSpecializationType>(T)) {
3388 TemplateSpecializationTypeLoc SpecTL
3389 = cast<TemplateSpecializationTypeLoc>(TL);
3390
3391 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003392 getDerived().TransformTemplateName(SS,
3393 SpecTL.getTypePtr()->getTemplateName(),
3394 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003395 ObjectType, UnqualLookup);
3396 if (Template.isNull())
3397 return TypeLoc();
3398
3399 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3400 Template);
3401 } else if (isa<DependentTemplateSpecializationType>(T)) {
3402 DependentTemplateSpecializationTypeLoc SpecTL
3403 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3404
Douglas Gregora88f09f2011-02-28 17:23:35 +00003405 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003406 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003407 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003408 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003409 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003410 if (Template.isNull())
3411 return TypeLoc();
3412
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003413 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003414 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003415 Template,
3416 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003417 } else {
3418 // Nothing special needs to be done for these.
3419 Result = getDerived().TransformType(TLB, TL);
3420 }
3421
3422 if (Result.isNull())
3423 return TypeLoc();
3424
3425 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3426}
3427
Douglas Gregorb71d8212011-03-02 18:32:08 +00003428template<typename Derived>
3429TypeSourceInfo *
3430TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3431 QualType ObjectType,
3432 NamedDecl *UnqualLookup,
3433 CXXScopeSpec &SS) {
3434 // FIXME: Painfully copy-paste from the above!
3435
3436 QualType T = TSInfo->getType();
3437 if (getDerived().AlreadyTransformed(T))
3438 return TSInfo;
3439
3440 TypeLocBuilder TLB;
3441 QualType Result;
3442
3443 TypeLoc TL = TSInfo->getTypeLoc();
3444 if (isa<TemplateSpecializationType>(T)) {
3445 TemplateSpecializationTypeLoc SpecTL
3446 = cast<TemplateSpecializationTypeLoc>(TL);
3447
3448 TemplateName Template
3449 = getDerived().TransformTemplateName(SS,
3450 SpecTL.getTypePtr()->getTemplateName(),
3451 SpecTL.getTemplateNameLoc(),
3452 ObjectType, UnqualLookup);
3453 if (Template.isNull())
3454 return 0;
3455
3456 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3457 Template);
3458 } else if (isa<DependentTemplateSpecializationType>(T)) {
3459 DependentTemplateSpecializationTypeLoc SpecTL
3460 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3461
3462 TemplateName Template
3463 = getDerived().RebuildTemplateName(SS,
3464 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003465 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003466 ObjectType, UnqualLookup);
3467 if (Template.isNull())
3468 return 0;
3469
3470 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3471 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003472 Template,
3473 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003474 } else {
3475 // Nothing special needs to be done for these.
3476 Result = getDerived().TransformType(TLB, TL);
3477 }
3478
3479 if (Result.isNull())
3480 return 0;
3481
3482 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3483}
3484
John McCalla2becad2009-10-21 00:40:46 +00003485template <class TyLoc> static inline
3486QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3487 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3488 NewT.setNameLoc(T.getNameLoc());
3489 return T.getType();
3490}
3491
John McCalla2becad2009-10-21 00:40:46 +00003492template<typename Derived>
3493QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003494 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003495 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3496 NewT.setBuiltinLoc(T.getBuiltinLoc());
3497 if (T.needsExtraLocalData())
3498 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3499 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003500}
Mike Stump1eb44332009-09-09 15:08:12 +00003501
Douglas Gregor577f75a2009-08-04 16:50:30 +00003502template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003503QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003504 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003505 // FIXME: recurse?
3506 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003507}
Mike Stump1eb44332009-09-09 15:08:12 +00003508
Douglas Gregor577f75a2009-08-04 16:50:30 +00003509template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003510QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003511 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003512 QualType PointeeType
3513 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003514 if (PointeeType.isNull())
3515 return QualType();
3516
3517 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003518 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003519 // A dependent pointer type 'T *' has is being transformed such
3520 // that an Objective-C class type is being replaced for 'T'. The
3521 // resulting pointer type is an ObjCObjectPointerType, not a
3522 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003523 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003524
John McCallc12c5bb2010-05-15 11:32:37 +00003525 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3526 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003527 return Result;
3528 }
John McCall43fed0d2010-11-12 08:19:04 +00003529
Douglas Gregor92e986e2010-04-22 16:44:27 +00003530 if (getDerived().AlwaysRebuild() ||
3531 PointeeType != TL.getPointeeLoc().getType()) {
3532 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3533 if (Result.isNull())
3534 return QualType();
3535 }
John McCallf85e1932011-06-15 23:02:42 +00003536
3537 // Objective-C ARC can add lifetime qualifiers to the type that we're
3538 // pointing to.
3539 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3540
Douglas Gregor92e986e2010-04-22 16:44:27 +00003541 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3542 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003543 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003544}
Mike Stump1eb44332009-09-09 15:08:12 +00003545
3546template<typename Derived>
3547QualType
John McCalla2becad2009-10-21 00:40:46 +00003548TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003549 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003550 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003551 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3552 if (PointeeType.isNull())
3553 return QualType();
3554
3555 QualType Result = TL.getType();
3556 if (getDerived().AlwaysRebuild() ||
3557 PointeeType != TL.getPointeeLoc().getType()) {
3558 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003559 TL.getSigilLoc());
3560 if (Result.isNull())
3561 return QualType();
3562 }
3563
Douglas Gregor39968ad2010-04-22 16:50:51 +00003564 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003565 NewT.setSigilLoc(TL.getSigilLoc());
3566 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003567}
3568
John McCall85737a72009-10-30 00:06:24 +00003569/// Transforms a reference type. Note that somewhat paradoxically we
3570/// don't care whether the type itself is an l-value type or an r-value
3571/// type; we only care if the type was *written* as an l-value type
3572/// or an r-value type.
3573template<typename Derived>
3574QualType
3575TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003576 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003577 const ReferenceType *T = TL.getTypePtr();
3578
3579 // Note that this works with the pointee-as-written.
3580 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3581 if (PointeeType.isNull())
3582 return QualType();
3583
3584 QualType Result = TL.getType();
3585 if (getDerived().AlwaysRebuild() ||
3586 PointeeType != T->getPointeeTypeAsWritten()) {
3587 Result = getDerived().RebuildReferenceType(PointeeType,
3588 T->isSpelledAsLValue(),
3589 TL.getSigilLoc());
3590 if (Result.isNull())
3591 return QualType();
3592 }
3593
John McCallf85e1932011-06-15 23:02:42 +00003594 // Objective-C ARC can add lifetime qualifiers to the type that we're
3595 // referring to.
3596 TLB.TypeWasModifiedSafely(
3597 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3598
John McCall85737a72009-10-30 00:06:24 +00003599 // r-value references can be rebuilt as l-value references.
3600 ReferenceTypeLoc NewTL;
3601 if (isa<LValueReferenceType>(Result))
3602 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3603 else
3604 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3605 NewTL.setSigilLoc(TL.getSigilLoc());
3606
3607 return Result;
3608}
3609
Mike Stump1eb44332009-09-09 15:08:12 +00003610template<typename Derived>
3611QualType
John McCalla2becad2009-10-21 00:40:46 +00003612TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003613 LValueReferenceTypeLoc TL) {
3614 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003615}
3616
Mike Stump1eb44332009-09-09 15:08:12 +00003617template<typename Derived>
3618QualType
John McCalla2becad2009-10-21 00:40:46 +00003619TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003620 RValueReferenceTypeLoc TL) {
3621 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003622}
Mike Stump1eb44332009-09-09 15:08:12 +00003623
Douglas Gregor577f75a2009-08-04 16:50:30 +00003624template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003625QualType
John McCalla2becad2009-10-21 00:40:46 +00003626TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003627 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003628 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003629 if (PointeeType.isNull())
3630 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003631
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003632 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3633 TypeSourceInfo* NewClsTInfo = 0;
3634 if (OldClsTInfo) {
3635 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3636 if (!NewClsTInfo)
3637 return QualType();
3638 }
3639
3640 const MemberPointerType *T = TL.getTypePtr();
3641 QualType OldClsType = QualType(T->getClass(), 0);
3642 QualType NewClsType;
3643 if (NewClsTInfo)
3644 NewClsType = NewClsTInfo->getType();
3645 else {
3646 NewClsType = getDerived().TransformType(OldClsType);
3647 if (NewClsType.isNull())
3648 return QualType();
3649 }
Mike Stump1eb44332009-09-09 15:08:12 +00003650
John McCalla2becad2009-10-21 00:40:46 +00003651 QualType Result = TL.getType();
3652 if (getDerived().AlwaysRebuild() ||
3653 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003654 NewClsType != OldClsType) {
3655 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003656 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003657 if (Result.isNull())
3658 return QualType();
3659 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003660
John McCalla2becad2009-10-21 00:40:46 +00003661 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3662 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003663 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003664
3665 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003666}
3667
Mike Stump1eb44332009-09-09 15:08:12 +00003668template<typename Derived>
3669QualType
John McCalla2becad2009-10-21 00:40:46 +00003670TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003671 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003672 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003673 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003674 if (ElementType.isNull())
3675 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003676
John McCalla2becad2009-10-21 00:40:46 +00003677 QualType Result = TL.getType();
3678 if (getDerived().AlwaysRebuild() ||
3679 ElementType != T->getElementType()) {
3680 Result = getDerived().RebuildConstantArrayType(ElementType,
3681 T->getSizeModifier(),
3682 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003683 T->getIndexTypeCVRQualifiers(),
3684 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003685 if (Result.isNull())
3686 return QualType();
3687 }
Eli Friedman457a3772012-01-25 22:19:07 +00003688
3689 // We might have either a ConstantArrayType or a VariableArrayType now:
3690 // a ConstantArrayType is allowed to have an element type which is a
3691 // VariableArrayType if the type is dependent. Fortunately, all array
3692 // types have the same location layout.
3693 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003694 NewTL.setLBracketLoc(TL.getLBracketLoc());
3695 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003696
John McCalla2becad2009-10-21 00:40:46 +00003697 Expr *Size = TL.getSizeExpr();
3698 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003699 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3700 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003701 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003702 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003703 }
3704 NewTL.setSizeExpr(Size);
3705
3706 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003707}
Mike Stump1eb44332009-09-09 15:08:12 +00003708
Douglas Gregor577f75a2009-08-04 16:50:30 +00003709template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003710QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003711 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003712 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003713 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003714 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003715 if (ElementType.isNull())
3716 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003717
John McCalla2becad2009-10-21 00:40:46 +00003718 QualType Result = TL.getType();
3719 if (getDerived().AlwaysRebuild() ||
3720 ElementType != T->getElementType()) {
3721 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003722 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003723 T->getIndexTypeCVRQualifiers(),
3724 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003725 if (Result.isNull())
3726 return QualType();
3727 }
Sean Huntc3021132010-05-05 15:23:54 +00003728
John McCalla2becad2009-10-21 00:40:46 +00003729 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3730 NewTL.setLBracketLoc(TL.getLBracketLoc());
3731 NewTL.setRBracketLoc(TL.getRBracketLoc());
3732 NewTL.setSizeExpr(0);
3733
3734 return Result;
3735}
3736
3737template<typename Derived>
3738QualType
3739TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003740 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003741 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003742 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3743 if (ElementType.isNull())
3744 return QualType();
3745
John McCall60d7b3a2010-08-24 06:29:42 +00003746 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003747 = getDerived().TransformExpr(T->getSizeExpr());
3748 if (SizeResult.isInvalid())
3749 return QualType();
3750
John McCall9ae2f072010-08-23 23:25:46 +00003751 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003752
3753 QualType Result = TL.getType();
3754 if (getDerived().AlwaysRebuild() ||
3755 ElementType != T->getElementType() ||
3756 Size != T->getSizeExpr()) {
3757 Result = getDerived().RebuildVariableArrayType(ElementType,
3758 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +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 }
Sean Huntc3021132010-05-05 15:23:54 +00003765
John McCalla2becad2009-10-21 00:40:46 +00003766 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3767 NewTL.setLBracketLoc(TL.getLBracketLoc());
3768 NewTL.setRBracketLoc(TL.getRBracketLoc());
3769 NewTL.setSizeExpr(Size);
3770
3771 return Result;
3772}
3773
3774template<typename Derived>
3775QualType
3776TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003777 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003778 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003779 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3780 if (ElementType.isNull())
3781 return QualType();
3782
Richard Smithf6702a32011-12-20 02:08:33 +00003783 // Array bounds are constant expressions.
3784 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3785 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003786
John McCall3b657512011-01-19 10:06:00 +00003787 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3788 Expr *origSize = TL.getSizeExpr();
3789 if (!origSize) origSize = T->getSizeExpr();
3790
3791 ExprResult sizeResult
3792 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003793 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003794 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003795 return QualType();
3796
John McCall3b657512011-01-19 10:06:00 +00003797 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003798
3799 QualType Result = TL.getType();
3800 if (getDerived().AlwaysRebuild() ||
3801 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003802 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003803 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3804 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003805 size,
John McCalla2becad2009-10-21 00:40:46 +00003806 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003807 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003808 if (Result.isNull())
3809 return QualType();
3810 }
John McCalla2becad2009-10-21 00:40:46 +00003811
3812 // We might have any sort of array type now, but fortunately they
3813 // all have the same location layout.
3814 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3815 NewTL.setLBracketLoc(TL.getLBracketLoc());
3816 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003817 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003818
3819 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003820}
Mike Stump1eb44332009-09-09 15:08:12 +00003821
3822template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003823QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003824 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003825 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003826 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003827
3828 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003829 QualType ElementType = getDerived().TransformType(T->getElementType());
3830 if (ElementType.isNull())
3831 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003832
Richard Smithf6702a32011-12-20 02:08:33 +00003833 // Vector sizes are constant expressions.
3834 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3835 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003836
John McCall60d7b3a2010-08-24 06:29:42 +00003837 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003838 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003839 if (Size.isInvalid())
3840 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003841
John McCalla2becad2009-10-21 00:40:46 +00003842 QualType Result = TL.getType();
3843 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003844 ElementType != T->getElementType() ||
3845 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003846 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003847 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003848 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003849 if (Result.isNull())
3850 return QualType();
3851 }
John McCalla2becad2009-10-21 00:40:46 +00003852
3853 // Result might be dependent or not.
3854 if (isa<DependentSizedExtVectorType>(Result)) {
3855 DependentSizedExtVectorTypeLoc NewTL
3856 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3857 NewTL.setNameLoc(TL.getNameLoc());
3858 } else {
3859 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3860 NewTL.setNameLoc(TL.getNameLoc());
3861 }
3862
3863 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003864}
Mike Stump1eb44332009-09-09 15:08:12 +00003865
3866template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003867QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003868 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003869 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003870 QualType ElementType = getDerived().TransformType(T->getElementType());
3871 if (ElementType.isNull())
3872 return QualType();
3873
John McCalla2becad2009-10-21 00:40:46 +00003874 QualType Result = TL.getType();
3875 if (getDerived().AlwaysRebuild() ||
3876 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003877 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003878 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003879 if (Result.isNull())
3880 return QualType();
3881 }
Sean Huntc3021132010-05-05 15:23:54 +00003882
John McCalla2becad2009-10-21 00:40:46 +00003883 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3884 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003885
John McCalla2becad2009-10-21 00:40:46 +00003886 return Result;
3887}
3888
3889template<typename Derived>
3890QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003891 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003892 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003893 QualType ElementType = getDerived().TransformType(T->getElementType());
3894 if (ElementType.isNull())
3895 return QualType();
3896
3897 QualType Result = TL.getType();
3898 if (getDerived().AlwaysRebuild() ||
3899 ElementType != T->getElementType()) {
3900 Result = getDerived().RebuildExtVectorType(ElementType,
3901 T->getNumElements(),
3902 /*FIXME*/ SourceLocation());
3903 if (Result.isNull())
3904 return QualType();
3905 }
Sean Huntc3021132010-05-05 15:23:54 +00003906
John McCalla2becad2009-10-21 00:40:46 +00003907 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3908 NewTL.setNameLoc(TL.getNameLoc());
3909
3910 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003911}
Mike Stump1eb44332009-09-09 15:08:12 +00003912
3913template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003914ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003915TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003916 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003917 llvm::Optional<unsigned> NumExpansions,
3918 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003919 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003920 TypeSourceInfo *NewDI = 0;
3921
3922 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3923 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003924 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003925 TypeLoc OldTL = OldDI->getTypeLoc();
3926 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3927
3928 TypeLocBuilder TLB;
3929 TypeLoc NewTL = OldDI->getTypeLoc();
3930 TLB.reserve(NewTL.getFullDataSize());
3931
3932 QualType Result = getDerived().TransformType(TLB,
3933 OldExpansionTL.getPatternLoc());
3934 if (Result.isNull())
3935 return 0;
3936
3937 Result = RebuildPackExpansionType(Result,
3938 OldExpansionTL.getPatternLoc().getSourceRange(),
3939 OldExpansionTL.getEllipsisLoc(),
3940 NumExpansions);
3941 if (Result.isNull())
3942 return 0;
3943
3944 PackExpansionTypeLoc NewExpansionTL
3945 = TLB.push<PackExpansionTypeLoc>(Result);
3946 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3947 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3948 } else
3949 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003950 if (!NewDI)
3951 return 0;
3952
John McCallfb44de92011-05-01 22:35:37 +00003953 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003954 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003955
3956 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3957 OldParm->getDeclContext(),
3958 OldParm->getInnerLocStart(),
3959 OldParm->getLocation(),
3960 OldParm->getIdentifier(),
3961 NewDI->getType(),
3962 NewDI,
3963 OldParm->getStorageClass(),
3964 OldParm->getStorageClassAsWritten(),
3965 /* DefArg */ NULL);
3966 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3967 OldParm->getFunctionScopeIndex() + indexAdjustment);
3968 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003969}
3970
3971template<typename Derived>
3972bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003973 TransformFunctionTypeParams(SourceLocation Loc,
3974 ParmVarDecl **Params, unsigned NumParams,
3975 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003976 SmallVectorImpl<QualType> &OutParamTypes,
3977 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003978 int indexAdjustment = 0;
3979
Douglas Gregora009b592011-01-07 00:20:55 +00003980 for (unsigned i = 0; i != NumParams; ++i) {
3981 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003982 assert(OldParm->getFunctionScopeIndex() == i);
3983
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003984 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003985 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003986 if (OldParm->isParameterPack()) {
3987 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003988 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003989
Douglas Gregor603cfb42011-01-05 23:12:31 +00003990 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003991 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3992 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3993 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3994 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003995 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3996
Douglas Gregor603cfb42011-01-05 23:12:31 +00003997 // Determine whether we should expand the parameter packs.
3998 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003999 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004000 llvm::Optional<unsigned> OrigNumExpansions
4001 = ExpansionTL.getTypePtr()->getNumExpansions();
4002 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004003 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4004 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004005 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004006 ShouldExpand,
4007 RetainExpansion,
4008 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004009 return true;
4010 }
4011
4012 if (ShouldExpand) {
4013 // Expand the function parameter pack into multiple, separate
4014 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004015 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004016 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004017 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4018 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004019 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004020 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004021 OrigNumExpansions,
4022 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004023 if (!NewParm)
4024 return true;
4025
Douglas Gregora009b592011-01-07 00:20:55 +00004026 OutParamTypes.push_back(NewParm->getType());
4027 if (PVars)
4028 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004029 }
Douglas Gregord3731192011-01-10 07:32:04 +00004030
4031 // If we're supposed to retain a pack expansion, do so by temporarily
4032 // forgetting the partially-substituted parameter pack.
4033 if (RetainExpansion) {
4034 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4035 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004036 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004037 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004038 OrigNumExpansions,
4039 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004040 if (!NewParm)
4041 return true;
4042
4043 OutParamTypes.push_back(NewParm->getType());
4044 if (PVars)
4045 PVars->push_back(NewParm);
4046 }
4047
John McCallfb44de92011-05-01 22:35:37 +00004048 // The next parameter should have the same adjustment as the
4049 // last thing we pushed, but we post-incremented indexAdjustment
4050 // on every push. Also, if we push nothing, the adjustment should
4051 // go down by one.
4052 indexAdjustment--;
4053
Douglas Gregor603cfb42011-01-05 23:12:31 +00004054 // We're done with the pack expansion.
4055 continue;
4056 }
4057
4058 // We'll substitute the parameter now without expanding the pack
4059 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004060 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4061 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004062 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004063 NumExpansions,
4064 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004065 } else {
4066 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004067 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004068 llvm::Optional<unsigned>(),
4069 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004070 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004071
John McCall21ef0fa2010-03-11 09:03:00 +00004072 if (!NewParm)
4073 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004074
Douglas Gregora009b592011-01-07 00:20:55 +00004075 OutParamTypes.push_back(NewParm->getType());
4076 if (PVars)
4077 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004078 continue;
4079 }
John McCall21ef0fa2010-03-11 09:03:00 +00004080
4081 // Deal with the possibility that we don't have a parameter
4082 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004083 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004084 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004085 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004086 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004087 if (const PackExpansionType *Expansion
4088 = dyn_cast<PackExpansionType>(OldType)) {
4089 // We have a function parameter pack that may need to be expanded.
4090 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004091 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004092 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4093
4094 // Determine whether we should expand the parameter packs.
4095 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004096 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004097 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004098 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004099 ShouldExpand,
4100 RetainExpansion,
4101 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004102 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004103 }
4104
4105 if (ShouldExpand) {
4106 // Expand the function parameter pack into multiple, separate
4107 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004108 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004109 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4110 QualType NewType = getDerived().TransformType(Pattern);
4111 if (NewType.isNull())
4112 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004113
Douglas Gregora009b592011-01-07 00:20:55 +00004114 OutParamTypes.push_back(NewType);
4115 if (PVars)
4116 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004117 }
4118
4119 // We're done with the pack expansion.
4120 continue;
4121 }
4122
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004123 // If we're supposed to retain a pack expansion, do so by temporarily
4124 // forgetting the partially-substituted parameter pack.
4125 if (RetainExpansion) {
4126 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4127 QualType NewType = getDerived().TransformType(Pattern);
4128 if (NewType.isNull())
4129 return true;
4130
4131 OutParamTypes.push_back(NewType);
4132 if (PVars)
4133 PVars->push_back(0);
4134 }
Douglas Gregord3731192011-01-10 07:32:04 +00004135
Douglas Gregor603cfb42011-01-05 23:12:31 +00004136 // We'll substitute the parameter now without expanding the pack
4137 // expansion.
4138 OldType = Expansion->getPattern();
4139 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004140 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4141 NewType = getDerived().TransformType(OldType);
4142 } else {
4143 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004144 }
4145
Douglas Gregor603cfb42011-01-05 23:12:31 +00004146 if (NewType.isNull())
4147 return true;
4148
4149 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004150 NewType = getSema().Context.getPackExpansionType(NewType,
4151 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004152
Douglas Gregora009b592011-01-07 00:20:55 +00004153 OutParamTypes.push_back(NewType);
4154 if (PVars)
4155 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004156 }
4157
John McCallfb44de92011-05-01 22:35:37 +00004158#ifndef NDEBUG
4159 if (PVars) {
4160 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4161 if (ParmVarDecl *parm = (*PVars)[i])
4162 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004163 }
John McCallfb44de92011-05-01 22:35:37 +00004164#endif
4165
4166 return false;
4167}
John McCall21ef0fa2010-03-11 09:03:00 +00004168
4169template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004170QualType
John McCalla2becad2009-10-21 00:40:46 +00004171TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004172 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004173 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4174}
4175
4176template<typename Derived>
4177QualType
4178TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4179 FunctionProtoTypeLoc TL,
4180 CXXRecordDecl *ThisContext,
4181 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004182 // Transform the parameters and return type.
4183 //
4184 // We instantiate in source order, with the return type first followed by
4185 // the parameters, because users tend to expect this (even if they shouldn't
4186 // rely on it!).
4187 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00004188 // When the function has a trailing return type, we instantiate the
4189 // parameters before the return type, since the return type can then refer
4190 // to the parameters themselves (via decltype, sizeof, etc.).
4191 //
Chris Lattner686775d2011-07-20 06:58:45 +00004192 SmallVector<QualType, 4> ParamTypes;
4193 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004194 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004195
Douglas Gregordab60ad2010-10-01 18:44:50 +00004196 QualType ResultType;
4197
4198 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004199 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4200 TL.getParmArray(),
4201 TL.getNumArgs(),
4202 TL.getTypePtr()->arg_type_begin(),
4203 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004204 return QualType();
4205
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004206 {
4207 // C++11 [expr.prim.general]p3:
4208 // If a declaration declares a member function or member function
4209 // template of a class X, the expression this is a prvalue of type
4210 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
4211 // and the end of the function-definition, member-declarator, or
4212 // declarator.
4213 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
4214
4215 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4216 if (ResultType.isNull())
4217 return QualType();
4218 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004219 }
4220 else {
4221 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4222 if (ResultType.isNull())
4223 return QualType();
4224
Douglas Gregora009b592011-01-07 00:20:55 +00004225 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4226 TL.getParmArray(),
4227 TL.getNumArgs(),
4228 TL.getTypePtr()->arg_type_begin(),
4229 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004230 return QualType();
4231 }
4232
John McCalla2becad2009-10-21 00:40:46 +00004233 QualType Result = TL.getType();
4234 if (getDerived().AlwaysRebuild() ||
4235 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004236 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004237 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4238 Result = getDerived().RebuildFunctionProtoType(ResultType,
4239 ParamTypes.data(),
4240 ParamTypes.size(),
4241 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004242 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004243 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004244 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004245 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004246 if (Result.isNull())
4247 return QualType();
4248 }
Mike Stump1eb44332009-09-09 15:08:12 +00004249
John McCalla2becad2009-10-21 00:40:46 +00004250 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004251 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4252 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004253 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004254 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4255 NewTL.setArg(i, ParamDecls[i]);
4256
4257 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004258}
Mike Stump1eb44332009-09-09 15:08:12 +00004259
Douglas Gregor577f75a2009-08-04 16:50:30 +00004260template<typename Derived>
4261QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004262 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004263 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004264 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004265 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4266 if (ResultType.isNull())
4267 return QualType();
4268
4269 QualType Result = TL.getType();
4270 if (getDerived().AlwaysRebuild() ||
4271 ResultType != T->getResultType())
4272 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4273
4274 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004275 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4276 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004277 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004278
4279 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004280}
Mike Stump1eb44332009-09-09 15:08:12 +00004281
John McCalled976492009-12-04 22:46:56 +00004282template<typename Derived> QualType
4283TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004284 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004285 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004286 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004287 if (!D)
4288 return QualType();
4289
4290 QualType Result = TL.getType();
4291 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4292 Result = getDerived().RebuildUnresolvedUsingType(D);
4293 if (Result.isNull())
4294 return QualType();
4295 }
4296
4297 // We might get an arbitrary type spec type back. We should at
4298 // least always get a type spec type, though.
4299 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4300 NewTL.setNameLoc(TL.getNameLoc());
4301
4302 return Result;
4303}
4304
Douglas Gregor577f75a2009-08-04 16:50:30 +00004305template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004306QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004307 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004308 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004309 TypedefNameDecl *Typedef
4310 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4311 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004312 if (!Typedef)
4313 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004314
John McCalla2becad2009-10-21 00:40:46 +00004315 QualType Result = TL.getType();
4316 if (getDerived().AlwaysRebuild() ||
4317 Typedef != T->getDecl()) {
4318 Result = getDerived().RebuildTypedefType(Typedef);
4319 if (Result.isNull())
4320 return QualType();
4321 }
Mike Stump1eb44332009-09-09 15:08:12 +00004322
John McCalla2becad2009-10-21 00:40:46 +00004323 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4324 NewTL.setNameLoc(TL.getNameLoc());
4325
4326 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004327}
Mike Stump1eb44332009-09-09 15:08:12 +00004328
Douglas Gregor577f75a2009-08-04 16:50:30 +00004329template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004330QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004331 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004332 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004333 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004334
John McCall60d7b3a2010-08-24 06:29:42 +00004335 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004336 if (E.isInvalid())
4337 return QualType();
4338
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004339 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4340 if (E.isInvalid())
4341 return QualType();
4342
John McCalla2becad2009-10-21 00:40:46 +00004343 QualType Result = TL.getType();
4344 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004345 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004346 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004347 if (Result.isNull())
4348 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004349 }
John McCalla2becad2009-10-21 00:40:46 +00004350 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004351
John McCalla2becad2009-10-21 00:40:46 +00004352 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004353 NewTL.setTypeofLoc(TL.getTypeofLoc());
4354 NewTL.setLParenLoc(TL.getLParenLoc());
4355 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004356
4357 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004358}
Mike Stump1eb44332009-09-09 15:08:12 +00004359
4360template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004361QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004362 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004363 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4364 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4365 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004366 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004367
John McCalla2becad2009-10-21 00:40:46 +00004368 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004369 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4370 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004371 if (Result.isNull())
4372 return QualType();
4373 }
Mike Stump1eb44332009-09-09 15:08:12 +00004374
John McCalla2becad2009-10-21 00:40:46 +00004375 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004376 NewTL.setTypeofLoc(TL.getTypeofLoc());
4377 NewTL.setLParenLoc(TL.getLParenLoc());
4378 NewTL.setRParenLoc(TL.getRParenLoc());
4379 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004380
4381 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004382}
Mike Stump1eb44332009-09-09 15:08:12 +00004383
4384template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004385QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004386 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004387 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004388
Douglas Gregor670444e2009-08-04 22:27:00 +00004389 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004390 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4391 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004392
John McCall60d7b3a2010-08-24 06:29:42 +00004393 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004394 if (E.isInvalid())
4395 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004396
Richard Smith76f3f692012-02-22 02:04:18 +00004397 E = getSema().ActOnDecltypeExpression(E.take());
4398 if (E.isInvalid())
4399 return QualType();
4400
John McCalla2becad2009-10-21 00:40:46 +00004401 QualType Result = TL.getType();
4402 if (getDerived().AlwaysRebuild() ||
4403 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004404 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004405 if (Result.isNull())
4406 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004407 }
John McCalla2becad2009-10-21 00:40:46 +00004408 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004409
John McCalla2becad2009-10-21 00:40:46 +00004410 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4411 NewTL.setNameLoc(TL.getNameLoc());
4412
4413 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004414}
4415
4416template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004417QualType TreeTransform<Derived>::TransformUnaryTransformType(
4418 TypeLocBuilder &TLB,
4419 UnaryTransformTypeLoc TL) {
4420 QualType Result = TL.getType();
4421 if (Result->isDependentType()) {
4422 const UnaryTransformType *T = TL.getTypePtr();
4423 QualType NewBase =
4424 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4425 Result = getDerived().RebuildUnaryTransformType(NewBase,
4426 T->getUTTKind(),
4427 TL.getKWLoc());
4428 if (Result.isNull())
4429 return QualType();
4430 }
4431
4432 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4433 NewTL.setKWLoc(TL.getKWLoc());
4434 NewTL.setParensRange(TL.getParensRange());
4435 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4436 return Result;
4437}
4438
4439template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004440QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4441 AutoTypeLoc TL) {
4442 const AutoType *T = TL.getTypePtr();
4443 QualType OldDeduced = T->getDeducedType();
4444 QualType NewDeduced;
4445 if (!OldDeduced.isNull()) {
4446 NewDeduced = getDerived().TransformType(OldDeduced);
4447 if (NewDeduced.isNull())
4448 return QualType();
4449 }
4450
4451 QualType Result = TL.getType();
4452 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4453 Result = getDerived().RebuildAutoType(NewDeduced);
4454 if (Result.isNull())
4455 return QualType();
4456 }
4457
4458 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4459 NewTL.setNameLoc(TL.getNameLoc());
4460
4461 return Result;
4462}
4463
4464template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004465QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004466 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004467 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004468 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004469 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4470 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004471 if (!Record)
4472 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004473
John McCalla2becad2009-10-21 00:40:46 +00004474 QualType Result = TL.getType();
4475 if (getDerived().AlwaysRebuild() ||
4476 Record != T->getDecl()) {
4477 Result = getDerived().RebuildRecordType(Record);
4478 if (Result.isNull())
4479 return QualType();
4480 }
Mike Stump1eb44332009-09-09 15:08:12 +00004481
John McCalla2becad2009-10-21 00:40:46 +00004482 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4483 NewTL.setNameLoc(TL.getNameLoc());
4484
4485 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004486}
Mike Stump1eb44332009-09-09 15:08:12 +00004487
4488template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004489QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004490 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004491 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004492 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004493 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4494 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004495 if (!Enum)
4496 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004497
John McCalla2becad2009-10-21 00:40:46 +00004498 QualType Result = TL.getType();
4499 if (getDerived().AlwaysRebuild() ||
4500 Enum != T->getDecl()) {
4501 Result = getDerived().RebuildEnumType(Enum);
4502 if (Result.isNull())
4503 return QualType();
4504 }
Mike Stump1eb44332009-09-09 15:08:12 +00004505
John McCalla2becad2009-10-21 00:40:46 +00004506 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4507 NewTL.setNameLoc(TL.getNameLoc());
4508
4509 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004510}
John McCall7da24312009-09-05 00:15:47 +00004511
John McCall3cb0ebd2010-03-10 03:28:59 +00004512template<typename Derived>
4513QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4514 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004515 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004516 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4517 TL.getTypePtr()->getDecl());
4518 if (!D) return QualType();
4519
4520 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4521 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4522 return T;
4523}
4524
Douglas Gregor577f75a2009-08-04 16:50:30 +00004525template<typename Derived>
4526QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004527 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004528 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004529 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004530}
4531
Mike Stump1eb44332009-09-09 15:08:12 +00004532template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004533QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004534 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004535 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004536 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4537
4538 // Substitute into the replacement type, which itself might involve something
4539 // that needs to be transformed. This only tends to occur with default
4540 // template arguments of template template parameters.
4541 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4542 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4543 if (Replacement.isNull())
4544 return QualType();
4545
4546 // Always canonicalize the replacement type.
4547 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4548 QualType Result
4549 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4550 Replacement);
4551
4552 // Propagate type-source information.
4553 SubstTemplateTypeParmTypeLoc NewTL
4554 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4555 NewTL.setNameLoc(TL.getNameLoc());
4556 return Result;
4557
John McCall49a832b2009-10-18 09:09:24 +00004558}
4559
4560template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004561QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4562 TypeLocBuilder &TLB,
4563 SubstTemplateTypeParmPackTypeLoc TL) {
4564 return TransformTypeSpecType(TLB, TL);
4565}
4566
4567template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004568QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004569 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004570 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004571 const TemplateSpecializationType *T = TL.getTypePtr();
4572
Douglas Gregor1d752d72011-03-02 18:46:51 +00004573 // The nested-name-specifier never matters in a TemplateSpecializationType,
4574 // because we can't have a dependent nested-name-specifier anyway.
4575 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004576 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004577 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4578 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004579 if (Template.isNull())
4580 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004581
John McCall43fed0d2010-11-12 08:19:04 +00004582 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4583}
4584
Eli Friedmanb001de72011-10-06 23:00:33 +00004585template<typename Derived>
4586QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4587 AtomicTypeLoc TL) {
4588 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4589 if (ValueType.isNull())
4590 return QualType();
4591
4592 QualType Result = TL.getType();
4593 if (getDerived().AlwaysRebuild() ||
4594 ValueType != TL.getValueLoc().getType()) {
4595 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4596 if (Result.isNull())
4597 return QualType();
4598 }
4599
4600 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4601 NewTL.setKWLoc(TL.getKWLoc());
4602 NewTL.setLParenLoc(TL.getLParenLoc());
4603 NewTL.setRParenLoc(TL.getRParenLoc());
4604
4605 return Result;
4606}
4607
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004608namespace {
4609 /// \brief Simple iterator that traverses the template arguments in a
4610 /// container that provides a \c getArgLoc() member function.
4611 ///
4612 /// This iterator is intended to be used with the iterator form of
4613 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4614 template<typename ArgLocContainer>
4615 class TemplateArgumentLocContainerIterator {
4616 ArgLocContainer *Container;
4617 unsigned Index;
4618
4619 public:
4620 typedef TemplateArgumentLoc value_type;
4621 typedef TemplateArgumentLoc reference;
4622 typedef int difference_type;
4623 typedef std::input_iterator_tag iterator_category;
4624
4625 class pointer {
4626 TemplateArgumentLoc Arg;
4627
4628 public:
4629 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4630
4631 const TemplateArgumentLoc *operator->() const {
4632 return &Arg;
4633 }
4634 };
4635
4636
4637 TemplateArgumentLocContainerIterator() {}
4638
4639 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4640 unsigned Index)
4641 : Container(&Container), Index(Index) { }
4642
4643 TemplateArgumentLocContainerIterator &operator++() {
4644 ++Index;
4645 return *this;
4646 }
4647
4648 TemplateArgumentLocContainerIterator operator++(int) {
4649 TemplateArgumentLocContainerIterator Old(*this);
4650 ++(*this);
4651 return Old;
4652 }
4653
4654 TemplateArgumentLoc operator*() const {
4655 return Container->getArgLoc(Index);
4656 }
4657
4658 pointer operator->() const {
4659 return pointer(Container->getArgLoc(Index));
4660 }
4661
4662 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004663 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004664 return X.Container == Y.Container && X.Index == Y.Index;
4665 }
4666
4667 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004668 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004669 return !(X == Y);
4670 }
4671 };
4672}
4673
4674
John McCall43fed0d2010-11-12 08:19:04 +00004675template <typename Derived>
4676QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4677 TypeLocBuilder &TLB,
4678 TemplateSpecializationTypeLoc TL,
4679 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004680 TemplateArgumentListInfo NewTemplateArgs;
4681 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4682 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004683 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4684 ArgIterator;
4685 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4686 ArgIterator(TL, TL.getNumArgs()),
4687 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004688 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004689
John McCall833ca992009-10-29 08:12:44 +00004690 // FIXME: maybe don't rebuild if all the template arguments are the same.
4691
4692 QualType Result =
4693 getDerived().RebuildTemplateSpecializationType(Template,
4694 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004695 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004696
4697 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004698 // Specializations of template template parameters are represented as
4699 // TemplateSpecializationTypes, and substitution of type alias templates
4700 // within a dependent context can transform them into
4701 // DependentTemplateSpecializationTypes.
4702 if (isa<DependentTemplateSpecializationType>(Result)) {
4703 DependentTemplateSpecializationTypeLoc NewTL
4704 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004705 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004706 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004707 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004708 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004709 NewTL.setLAngleLoc(TL.getLAngleLoc());
4710 NewTL.setRAngleLoc(TL.getRAngleLoc());
4711 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4712 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4713 return Result;
4714 }
4715
John McCall833ca992009-10-29 08:12:44 +00004716 TemplateSpecializationTypeLoc NewTL
4717 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004718 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004719 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4720 NewTL.setLAngleLoc(TL.getLAngleLoc());
4721 NewTL.setRAngleLoc(TL.getRAngleLoc());
4722 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4723 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004724 }
Mike Stump1eb44332009-09-09 15:08:12 +00004725
John McCall833ca992009-10-29 08:12:44 +00004726 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004727}
Mike Stump1eb44332009-09-09 15:08:12 +00004728
Douglas Gregora88f09f2011-02-28 17:23:35 +00004729template <typename Derived>
4730QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4731 TypeLocBuilder &TLB,
4732 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004733 TemplateName Template,
4734 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004735 TemplateArgumentListInfo NewTemplateArgs;
4736 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4737 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4738 typedef TemplateArgumentLocContainerIterator<
4739 DependentTemplateSpecializationTypeLoc> ArgIterator;
4740 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4741 ArgIterator(TL, TL.getNumArgs()),
4742 NewTemplateArgs))
4743 return QualType();
4744
4745 // FIXME: maybe don't rebuild if all the template arguments are the same.
4746
4747 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4748 QualType Result
4749 = getSema().Context.getDependentTemplateSpecializationType(
4750 TL.getTypePtr()->getKeyword(),
4751 DTN->getQualifier(),
4752 DTN->getIdentifier(),
4753 NewTemplateArgs);
4754
4755 DependentTemplateSpecializationTypeLoc NewTL
4756 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004757 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004758 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004759 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004760 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004761 NewTL.setLAngleLoc(TL.getLAngleLoc());
4762 NewTL.setRAngleLoc(TL.getRAngleLoc());
4763 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4764 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4765 return Result;
4766 }
4767
4768 QualType Result
4769 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004770 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004771 NewTemplateArgs);
4772
4773 if (!Result.isNull()) {
4774 /// FIXME: Wrap this in an elaborated-type-specifier?
4775 TemplateSpecializationTypeLoc NewTL
4776 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004777 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004778 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004779 NewTL.setLAngleLoc(TL.getLAngleLoc());
4780 NewTL.setRAngleLoc(TL.getRAngleLoc());
4781 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4782 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4783 }
4784
4785 return Result;
4786}
4787
Mike Stump1eb44332009-09-09 15:08:12 +00004788template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004789QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004790TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004791 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004792 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004793
Douglas Gregor9e876872011-03-01 18:12:44 +00004794 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004795 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004796 if (TL.getQualifierLoc()) {
4797 QualifierLoc
4798 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4799 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004800 return QualType();
4801 }
Mike Stump1eb44332009-09-09 15:08:12 +00004802
John McCall43fed0d2010-11-12 08:19:04 +00004803 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4804 if (NamedT.isNull())
4805 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004806
Richard Smith3e4c6c42011-05-05 21:57:07 +00004807 // C++0x [dcl.type.elab]p2:
4808 // If the identifier resolves to a typedef-name or the simple-template-id
4809 // resolves to an alias template specialization, the
4810 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004811 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4812 if (const TemplateSpecializationType *TST =
4813 NamedT->getAs<TemplateSpecializationType>()) {
4814 TemplateName Template = TST->getTemplateName();
4815 if (TypeAliasTemplateDecl *TAT =
4816 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4817 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4818 diag::err_tag_reference_non_tag) << 4;
4819 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4820 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004821 }
4822 }
4823
John McCalla2becad2009-10-21 00:40:46 +00004824 QualType Result = TL.getType();
4825 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004826 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004827 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004828 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004829 T->getKeyword(),
4830 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004831 if (Result.isNull())
4832 return QualType();
4833 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004834
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004835 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004836 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004837 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004838 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004839}
Mike Stump1eb44332009-09-09 15:08:12 +00004840
4841template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004842QualType TreeTransform<Derived>::TransformAttributedType(
4843 TypeLocBuilder &TLB,
4844 AttributedTypeLoc TL) {
4845 const AttributedType *oldType = TL.getTypePtr();
4846 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4847 if (modifiedType.isNull())
4848 return QualType();
4849
4850 QualType result = TL.getType();
4851
4852 // FIXME: dependent operand expressions?
4853 if (getDerived().AlwaysRebuild() ||
4854 modifiedType != oldType->getModifiedType()) {
4855 // TODO: this is really lame; we should really be rebuilding the
4856 // equivalent type from first principles.
4857 QualType equivalentType
4858 = getDerived().TransformType(oldType->getEquivalentType());
4859 if (equivalentType.isNull())
4860 return QualType();
4861 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4862 modifiedType,
4863 equivalentType);
4864 }
4865
4866 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4867 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4868 if (TL.hasAttrOperand())
4869 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4870 if (TL.hasAttrExprOperand())
4871 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4872 else if (TL.hasAttrEnumOperand())
4873 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4874
4875 return result;
4876}
4877
4878template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004879QualType
4880TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4881 ParenTypeLoc TL) {
4882 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4883 if (Inner.isNull())
4884 return QualType();
4885
4886 QualType Result = TL.getType();
4887 if (getDerived().AlwaysRebuild() ||
4888 Inner != TL.getInnerLoc().getType()) {
4889 Result = getDerived().RebuildParenType(Inner);
4890 if (Result.isNull())
4891 return QualType();
4892 }
4893
4894 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4895 NewTL.setLParenLoc(TL.getLParenLoc());
4896 NewTL.setRParenLoc(TL.getRParenLoc());
4897 return Result;
4898}
4899
4900template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004901QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004902 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004903 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004904
Douglas Gregor2494dd02011-03-01 01:34:45 +00004905 NestedNameSpecifierLoc QualifierLoc
4906 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4907 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004908 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004909
John McCall33500952010-06-11 00:33:02 +00004910 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004911 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004912 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004913 QualifierLoc,
4914 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004915 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004916 if (Result.isNull())
4917 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004918
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004919 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4920 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004921 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4922
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004923 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004924 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004925 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004926 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004927 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004928 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004929 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004930 NewTL.setNameLoc(TL.getNameLoc());
4931 }
John McCalla2becad2009-10-21 00:40:46 +00004932 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004933}
Mike Stump1eb44332009-09-09 15:08:12 +00004934
Douglas Gregor577f75a2009-08-04 16:50:30 +00004935template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004936QualType TreeTransform<Derived>::
4937 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004938 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004939 NestedNameSpecifierLoc QualifierLoc;
4940 if (TL.getQualifierLoc()) {
4941 QualifierLoc
4942 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4943 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004944 return QualType();
4945 }
4946
John McCall43fed0d2010-11-12 08:19:04 +00004947 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004948 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004949}
4950
4951template<typename Derived>
4952QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004953TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4954 DependentTemplateSpecializationTypeLoc TL,
4955 NestedNameSpecifierLoc QualifierLoc) {
4956 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4957
4958 TemplateArgumentListInfo NewTemplateArgs;
4959 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4960 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4961
4962 typedef TemplateArgumentLocContainerIterator<
4963 DependentTemplateSpecializationTypeLoc> ArgIterator;
4964 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4965 ArgIterator(TL, TL.getNumArgs()),
4966 NewTemplateArgs))
4967 return QualType();
4968
4969 QualType Result
4970 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4971 QualifierLoc,
4972 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004973 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004974 NewTemplateArgs);
4975 if (Result.isNull())
4976 return QualType();
4977
4978 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4979 QualType NamedT = ElabT->getNamedType();
4980
4981 // Copy information relevant to the template specialization.
4982 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004983 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004984 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004985 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004986 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4987 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004988 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004989 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004990
4991 // Copy information relevant to the elaborated type.
4992 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004993 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004994 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004995 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4996 DependentTemplateSpecializationTypeLoc SpecTL
4997 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004998 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004999 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005000 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005001 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005002 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5003 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005004 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005005 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005006 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005007 TemplateSpecializationTypeLoc SpecTL
5008 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005009 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005010 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005011 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5012 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005013 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005014 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005015 }
5016 return Result;
5017}
5018
5019template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005020QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5021 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005022 QualType Pattern
5023 = getDerived().TransformType(TLB, TL.getPatternLoc());
5024 if (Pattern.isNull())
5025 return QualType();
5026
5027 QualType Result = TL.getType();
5028 if (getDerived().AlwaysRebuild() ||
5029 Pattern != TL.getPatternLoc().getType()) {
5030 Result = getDerived().RebuildPackExpansionType(Pattern,
5031 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005032 TL.getEllipsisLoc(),
5033 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005034 if (Result.isNull())
5035 return QualType();
5036 }
5037
5038 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5039 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5040 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005041}
5042
5043template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005044QualType
5045TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005046 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005047 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005048 TLB.pushFullCopy(TL);
5049 return TL.getType();
5050}
5051
5052template<typename Derived>
5053QualType
5054TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005055 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005056 // ObjCObjectType is never dependent.
5057 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005058 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005059}
Mike Stump1eb44332009-09-09 15:08:12 +00005060
5061template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005062QualType
5063TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005064 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005065 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005066 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005067 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005068}
5069
Douglas Gregor577f75a2009-08-04 16:50:30 +00005070//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005071// Statement transformation
5072//===----------------------------------------------------------------------===//
5073template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005074StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005075TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005076 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005077}
5078
5079template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005080StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005081TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5082 return getDerived().TransformCompoundStmt(S, false);
5083}
5084
5085template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005086StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005087TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005088 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005089 Sema::CompoundScopeRAII CompoundScope(getSema());
5090
John McCall7114cba2010-08-27 19:56:05 +00005091 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005092 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005093 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00005094 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5095 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005096 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005097 if (Result.isInvalid()) {
5098 // Immediately fail if this was a DeclStmt, since it's very
5099 // likely that this will cause problems for future statements.
5100 if (isa<DeclStmt>(*B))
5101 return StmtError();
5102
5103 // Otherwise, just keep processing substatements and fail later.
5104 SubStmtInvalid = true;
5105 continue;
5106 }
Mike Stump1eb44332009-09-09 15:08:12 +00005107
Douglas Gregor43959a92009-08-20 07:17:43 +00005108 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5109 Statements.push_back(Result.takeAs<Stmt>());
5110 }
Mike Stump1eb44332009-09-09 15:08:12 +00005111
John McCall7114cba2010-08-27 19:56:05 +00005112 if (SubStmtInvalid)
5113 return StmtError();
5114
Douglas Gregor43959a92009-08-20 07:17:43 +00005115 if (!getDerived().AlwaysRebuild() &&
5116 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005117 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005118
5119 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5120 move_arg(Statements),
5121 S->getRBracLoc(),
5122 IsStmtExpr);
5123}
Mike Stump1eb44332009-09-09 15:08:12 +00005124
Douglas Gregor43959a92009-08-20 07:17:43 +00005125template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005126StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005127TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005128 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005129 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005130 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5131 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005132
Eli Friedman264c1f82009-11-19 03:14:00 +00005133 // Transform the left-hand case value.
5134 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005135 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005136 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005137 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005138
Eli Friedman264c1f82009-11-19 03:14:00 +00005139 // Transform the right-hand case value (for the GNU case-range extension).
5140 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005141 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005142 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005143 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005144 }
Mike Stump1eb44332009-09-09 15:08:12 +00005145
Douglas Gregor43959a92009-08-20 07:17:43 +00005146 // Build the case statement.
5147 // Case statements are always rebuilt so that they will attached to their
5148 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005149 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005150 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005151 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005152 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005153 S->getColonLoc());
5154 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005155 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005156
Douglas Gregor43959a92009-08-20 07:17:43 +00005157 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005158 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005159 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005160 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005161
Douglas Gregor43959a92009-08-20 07:17:43 +00005162 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005163 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005164}
5165
5166template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005167StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005168TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005169 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005170 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005171 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005172 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005173
Douglas Gregor43959a92009-08-20 07:17:43 +00005174 // Default statements are always rebuilt
5175 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005176 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005177}
Mike Stump1eb44332009-09-09 15:08:12 +00005178
Douglas Gregor43959a92009-08-20 07:17:43 +00005179template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005180StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005181TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005182 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005183 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005184 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005185
Chris Lattner57ad3782011-02-17 20:34:02 +00005186 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5187 S->getDecl());
5188 if (!LD)
5189 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005190
5191
Douglas Gregor43959a92009-08-20 07:17:43 +00005192 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005193 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005194 cast<LabelDecl>(LD), SourceLocation(),
5195 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005196}
Mike Stump1eb44332009-09-09 15:08:12 +00005197
Douglas Gregor43959a92009-08-20 07:17:43 +00005198template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005199StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005200TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5201 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5202 if (SubStmt.isInvalid())
5203 return StmtError();
5204
5205 // TODO: transform attributes
5206 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5207 return S;
5208
5209 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5210 S->getAttrs(),
5211 SubStmt.get());
5212}
5213
5214template<typename Derived>
5215StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005216TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005217 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005218 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005219 VarDecl *ConditionVar = 0;
5220 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005221 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005222 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005223 getDerived().TransformDefinition(
5224 S->getConditionVariable()->getLocation(),
5225 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005226 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005227 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005228 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005229 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005230
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005231 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005232 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005233
5234 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005235 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005236 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5237 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005238 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005239 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005240
John McCall9ae2f072010-08-23 23:25:46 +00005241 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005242 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005243 }
Sean Huntc3021132010-05-05 15:23:54 +00005244
John McCall9ae2f072010-08-23 23:25:46 +00005245 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5246 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005247 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005248
Douglas Gregor43959a92009-08-20 07:17:43 +00005249 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005250 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005251 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005252 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005253
Douglas Gregor43959a92009-08-20 07:17:43 +00005254 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005255 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005256 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005257 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005258
Douglas Gregor43959a92009-08-20 07:17:43 +00005259 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005260 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005261 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005262 Then.get() == S->getThen() &&
5263 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005264 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005265
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005266 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005267 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005268 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005269}
5270
5271template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005272StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005273TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005274 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005275 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005276 VarDecl *ConditionVar = 0;
5277 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005278 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005279 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005280 getDerived().TransformDefinition(
5281 S->getConditionVariable()->getLocation(),
5282 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005283 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005284 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005285 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005286 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005287
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005288 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005289 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005290 }
Mike Stump1eb44332009-09-09 15:08:12 +00005291
Douglas Gregor43959a92009-08-20 07:17:43 +00005292 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005293 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005294 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005295 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005296 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005297 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005298
Douglas Gregor43959a92009-08-20 07:17:43 +00005299 // Transform the body of the switch statement.
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 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005305 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5306 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005307}
Mike Stump1eb44332009-09-09 15:08:12 +00005308
Douglas Gregor43959a92009-08-20 07:17:43 +00005309template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005310StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005311TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005312 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005313 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005314 VarDecl *ConditionVar = 0;
5315 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005316 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005317 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005318 getDerived().TransformDefinition(
5319 S->getConditionVariable()->getLocation(),
5320 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005321 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005322 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005323 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005324 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005325
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005326 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005327 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005328
5329 if (S->getCond()) {
5330 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005331 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5332 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005333 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005334 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005335 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005336 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005337 }
Mike Stump1eb44332009-09-09 15:08:12 +00005338
John McCall9ae2f072010-08-23 23:25:46 +00005339 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5340 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005341 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005342
Douglas Gregor43959a92009-08-20 07:17:43 +00005343 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005344 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005345 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005346 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005347
Douglas Gregor43959a92009-08-20 07:17:43 +00005348 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005349 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005350 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005351 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005352 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005353
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005354 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005355 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005356}
Mike Stump1eb44332009-09-09 15:08:12 +00005357
Douglas Gregor43959a92009-08-20 07:17:43 +00005358template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005359StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005360TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005361 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005362 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005363 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005364 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005365
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005366 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005367 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005368 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005369 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005370
Douglas Gregor43959a92009-08-20 07:17:43 +00005371 if (!getDerived().AlwaysRebuild() &&
5372 Cond.get() == S->getCond() &&
5373 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005374 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005375
John McCall9ae2f072010-08-23 23:25:46 +00005376 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5377 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005378 S->getRParenLoc());
5379}
Mike Stump1eb44332009-09-09 15:08:12 +00005380
Douglas Gregor43959a92009-08-20 07:17:43 +00005381template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005382StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005383TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005384 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005385 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005386 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005387 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005388
Douglas Gregor43959a92009-08-20 07:17:43 +00005389 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005390 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005391 VarDecl *ConditionVar = 0;
5392 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005393 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005394 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005395 getDerived().TransformDefinition(
5396 S->getConditionVariable()->getLocation(),
5397 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005398 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005399 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005400 } else {
5401 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005402
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005403 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005404 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005405
5406 if (S->getCond()) {
5407 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005408 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5409 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005410 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005411 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005412
John McCall9ae2f072010-08-23 23:25:46 +00005413 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005414 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005415 }
Mike Stump1eb44332009-09-09 15:08:12 +00005416
John McCall9ae2f072010-08-23 23:25:46 +00005417 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5418 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005419 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005420
Douglas Gregor43959a92009-08-20 07:17:43 +00005421 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005422 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005423 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005424 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005425
John McCall9ae2f072010-08-23 23:25:46 +00005426 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5427 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005428 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005429
Douglas Gregor43959a92009-08-20 07:17:43 +00005430 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005431 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005432 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005433 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005434
Douglas Gregor43959a92009-08-20 07:17:43 +00005435 if (!getDerived().AlwaysRebuild() &&
5436 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005437 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005438 Inc.get() == S->getInc() &&
5439 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005440 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005441
Douglas Gregor43959a92009-08-20 07:17:43 +00005442 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005443 Init.get(), FullCond, ConditionVar,
5444 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005445}
5446
5447template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005448StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005449TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005450 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5451 S->getLabel());
5452 if (!LD)
5453 return StmtError();
5454
Douglas Gregor43959a92009-08-20 07:17:43 +00005455 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005456 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005457 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005458}
5459
5460template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005461StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005462TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005463 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005464 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005465 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005466 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005467
Douglas Gregor43959a92009-08-20 07:17:43 +00005468 if (!getDerived().AlwaysRebuild() &&
5469 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005470 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005471
5472 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005473 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005474}
5475
5476template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005477StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005478TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005479 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005480}
Mike Stump1eb44332009-09-09 15:08:12 +00005481
Douglas Gregor43959a92009-08-20 07:17:43 +00005482template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005483StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005484TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005485 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005486}
Mike Stump1eb44332009-09-09 15:08:12 +00005487
Douglas Gregor43959a92009-08-20 07:17:43 +00005488template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005489StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005490TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005491 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005492 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005493 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005494
Mike Stump1eb44332009-09-09 15:08:12 +00005495 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005496 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005497 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005498}
Mike Stump1eb44332009-09-09 15:08:12 +00005499
Douglas Gregor43959a92009-08-20 07:17:43 +00005500template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005501StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005502TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005503 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005504 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005505 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5506 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005507 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5508 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005509 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005510 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005511
Douglas Gregor43959a92009-08-20 07:17:43 +00005512 if (Transformed != *D)
5513 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005514
Douglas Gregor43959a92009-08-20 07:17:43 +00005515 Decls.push_back(Transformed);
5516 }
Mike Stump1eb44332009-09-09 15:08:12 +00005517
Douglas Gregor43959a92009-08-20 07:17:43 +00005518 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005519 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005520
5521 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005522 S->getStartLoc(), S->getEndLoc());
5523}
Mike Stump1eb44332009-09-09 15:08:12 +00005524
Douglas Gregor43959a92009-08-20 07:17:43 +00005525template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005526StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005527TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005528
John McCallca0408f2010-08-23 06:44:23 +00005529 ASTOwningVector<Expr*> Constraints(getSema());
5530 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005531 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005532
John McCall60d7b3a2010-08-24 06:29:42 +00005533 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005534 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005535
5536 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005537
Anders Carlsson703e3942010-01-24 05:50:09 +00005538 // Go through the outputs.
5539 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005540 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005541
Anders Carlsson703e3942010-01-24 05:50:09 +00005542 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005543 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005544
Anders Carlsson703e3942010-01-24 05:50:09 +00005545 // Transform the output expr.
5546 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005547 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005548 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005549 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005550
Anders Carlsson703e3942010-01-24 05:50:09 +00005551 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005552
John McCall9ae2f072010-08-23 23:25:46 +00005553 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005554 }
Sean Huntc3021132010-05-05 15:23:54 +00005555
Anders Carlsson703e3942010-01-24 05:50:09 +00005556 // Go through the inputs.
5557 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005558 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005559
Anders Carlsson703e3942010-01-24 05:50:09 +00005560 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005561 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005562
Anders Carlsson703e3942010-01-24 05:50:09 +00005563 // Transform the input expr.
5564 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005565 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005566 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005567 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005568
Anders Carlsson703e3942010-01-24 05:50:09 +00005569 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005570
John McCall9ae2f072010-08-23 23:25:46 +00005571 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005572 }
Sean Huntc3021132010-05-05 15:23:54 +00005573
Anders Carlsson703e3942010-01-24 05:50:09 +00005574 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005575 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005576
5577 // Go through the clobbers.
5578 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005579 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005580
5581 // No need to transform the asm string literal.
5582 AsmString = SemaRef.Owned(S->getAsmString());
5583
5584 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5585 S->isSimple(),
5586 S->isVolatile(),
5587 S->getNumOutputs(),
5588 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005589 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005590 move_arg(Constraints),
5591 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005592 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005593 move_arg(Clobbers),
5594 S->getRParenLoc(),
5595 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005596}
5597
5598
5599template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005600StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005601TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005602 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005603 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005604 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005605 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005606
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005607 // Transform the @catch statements (if present).
5608 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005609 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005610 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005611 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005612 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005613 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005614 if (Catch.get() != S->getCatchStmt(I))
5615 AnyCatchChanged = true;
5616 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005617 }
Sean Huntc3021132010-05-05 15:23:54 +00005618
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005619 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005620 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005621 if (S->getFinallyStmt()) {
5622 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5623 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005624 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005625 }
5626
5627 // If nothing changed, just retain this statement.
5628 if (!getDerived().AlwaysRebuild() &&
5629 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005630 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005631 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005632 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005633
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005634 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005635 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5636 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005637}
Mike Stump1eb44332009-09-09 15:08:12 +00005638
Douglas Gregor43959a92009-08-20 07:17:43 +00005639template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005640StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005641TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005642 // Transform the @catch parameter, if there is one.
5643 VarDecl *Var = 0;
5644 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5645 TypeSourceInfo *TSInfo = 0;
5646 if (FromVar->getTypeSourceInfo()) {
5647 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5648 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005649 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005650 }
Sean Huntc3021132010-05-05 15:23:54 +00005651
Douglas Gregorbe270a02010-04-26 17:57:08 +00005652 QualType T;
5653 if (TSInfo)
5654 T = TSInfo->getType();
5655 else {
5656 T = getDerived().TransformType(FromVar->getType());
5657 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005658 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005659 }
Sean Huntc3021132010-05-05 15:23:54 +00005660
Douglas Gregorbe270a02010-04-26 17:57:08 +00005661 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5662 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005663 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005664 }
Sean Huntc3021132010-05-05 15:23:54 +00005665
John McCall60d7b3a2010-08-24 06:29:42 +00005666 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005667 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005668 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005669
5670 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005671 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005672 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005673}
Mike Stump1eb44332009-09-09 15:08:12 +00005674
Douglas Gregor43959a92009-08-20 07:17:43 +00005675template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005676StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005677TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005678 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005679 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005680 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005681 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005682
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005683 // If nothing changed, just retain this statement.
5684 if (!getDerived().AlwaysRebuild() &&
5685 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005686 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005687
5688 // Build a new statement.
5689 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005690 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005691}
Mike Stump1eb44332009-09-09 15:08:12 +00005692
Douglas Gregor43959a92009-08-20 07:17:43 +00005693template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005694StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005695TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005696 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005697 if (S->getThrowExpr()) {
5698 Operand = getDerived().TransformExpr(S->getThrowExpr());
5699 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005700 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005701 }
Sean Huntc3021132010-05-05 15:23:54 +00005702
Douglas Gregord1377b22010-04-22 21:44:01 +00005703 if (!getDerived().AlwaysRebuild() &&
5704 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005705 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005706
John McCall9ae2f072010-08-23 23:25:46 +00005707 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005708}
Mike Stump1eb44332009-09-09 15:08:12 +00005709
Douglas Gregor43959a92009-08-20 07:17:43 +00005710template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005711StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005712TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005713 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005714 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005715 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005716 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005717 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005718 Object =
5719 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5720 Object.get());
5721 if (Object.isInvalid())
5722 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005723
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005724 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005725 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005726 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005727 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005728
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005729 // If nothing change, just retain the current statement.
5730 if (!getDerived().AlwaysRebuild() &&
5731 Object.get() == S->getSynchExpr() &&
5732 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005733 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005734
5735 // Build a new statement.
5736 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005737 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005738}
5739
5740template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005741StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005742TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5743 ObjCAutoreleasePoolStmt *S) {
5744 // Transform the body.
5745 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5746 if (Body.isInvalid())
5747 return StmtError();
5748
5749 // If nothing changed, just retain this statement.
5750 if (!getDerived().AlwaysRebuild() &&
5751 Body.get() == S->getSubStmt())
5752 return SemaRef.Owned(S);
5753
5754 // Build a new statement.
5755 return getDerived().RebuildObjCAutoreleasePoolStmt(
5756 S->getAtLoc(), Body.get());
5757}
5758
5759template<typename Derived>
5760StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005761TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005762 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005763 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005764 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005765 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005766 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005767
Douglas Gregorc3203e72010-04-22 23:10:45 +00005768 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005769 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005770 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005771 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005772 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5773 Collection.take());
5774 if (Collection.isInvalid())
5775 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005776
Douglas Gregorc3203e72010-04-22 23:10:45 +00005777 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005778 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005779 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005780 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005781
Douglas Gregorc3203e72010-04-22 23:10:45 +00005782 // If nothing changed, just retain this statement.
5783 if (!getDerived().AlwaysRebuild() &&
5784 Element.get() == S->getElement() &&
5785 Collection.get() == S->getCollection() &&
5786 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005787 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005788
Douglas Gregorc3203e72010-04-22 23:10:45 +00005789 // Build a new statement.
5790 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5791 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005792 Element.get(),
5793 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005794 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005795 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005796}
5797
5798
5799template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005800StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005801TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5802 // Transform the exception declaration, if any.
5803 VarDecl *Var = 0;
5804 if (S->getExceptionDecl()) {
5805 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005806 TypeSourceInfo *T = getDerived().TransformType(
5807 ExceptionDecl->getTypeSourceInfo());
5808 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005809 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005810
Douglas Gregor83cb9422010-09-09 17:09:21 +00005811 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005812 ExceptionDecl->getInnerLocStart(),
5813 ExceptionDecl->getLocation(),
5814 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005815 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005816 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005817 }
Mike Stump1eb44332009-09-09 15:08:12 +00005818
Douglas Gregor43959a92009-08-20 07:17:43 +00005819 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005820 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005821 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005822 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005823
Douglas Gregor43959a92009-08-20 07:17:43 +00005824 if (!getDerived().AlwaysRebuild() &&
5825 !Var &&
5826 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005827 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005828
5829 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5830 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005831 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005832}
Mike Stump1eb44332009-09-09 15:08:12 +00005833
Douglas Gregor43959a92009-08-20 07:17:43 +00005834template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005835StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005836TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5837 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005838 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005839 = getDerived().TransformCompoundStmt(S->getTryBlock());
5840 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005841 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005842
Douglas Gregor43959a92009-08-20 07:17:43 +00005843 // Transform the handlers.
5844 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005845 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005846 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005847 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005848 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5849 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005850 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005851
Douglas Gregor43959a92009-08-20 07:17:43 +00005852 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5853 Handlers.push_back(Handler.takeAs<Stmt>());
5854 }
Mike Stump1eb44332009-09-09 15:08:12 +00005855
Douglas Gregor43959a92009-08-20 07:17:43 +00005856 if (!getDerived().AlwaysRebuild() &&
5857 TryBlock.get() == S->getTryBlock() &&
5858 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005859 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005860
John McCall9ae2f072010-08-23 23:25:46 +00005861 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005862 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005863}
Mike Stump1eb44332009-09-09 15:08:12 +00005864
Richard Smithad762fc2011-04-14 22:09:26 +00005865template<typename Derived>
5866StmtResult
5867TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5868 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5869 if (Range.isInvalid())
5870 return StmtError();
5871
5872 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5873 if (BeginEnd.isInvalid())
5874 return StmtError();
5875
5876 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5877 if (Cond.isInvalid())
5878 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005879 if (Cond.get())
5880 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5881 if (Cond.isInvalid())
5882 return StmtError();
5883 if (Cond.get())
5884 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005885
5886 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5887 if (Inc.isInvalid())
5888 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005889 if (Inc.get())
5890 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005891
5892 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5893 if (LoopVar.isInvalid())
5894 return StmtError();
5895
5896 StmtResult NewStmt = S;
5897 if (getDerived().AlwaysRebuild() ||
5898 Range.get() != S->getRangeStmt() ||
5899 BeginEnd.get() != S->getBeginEndStmt() ||
5900 Cond.get() != S->getCond() ||
5901 Inc.get() != S->getInc() ||
5902 LoopVar.get() != S->getLoopVarStmt())
5903 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5904 S->getColonLoc(), Range.get(),
5905 BeginEnd.get(), Cond.get(),
5906 Inc.get(), LoopVar.get(),
5907 S->getRParenLoc());
5908
5909 StmtResult Body = getDerived().TransformStmt(S->getBody());
5910 if (Body.isInvalid())
5911 return StmtError();
5912
5913 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5914 // it now so we have a new statement to attach the body to.
5915 if (Body.get() != S->getBody() && NewStmt.get() == S)
5916 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5917 S->getColonLoc(), Range.get(),
5918 BeginEnd.get(), Cond.get(),
5919 Inc.get(), LoopVar.get(),
5920 S->getRParenLoc());
5921
5922 if (NewStmt.get() == S)
5923 return SemaRef.Owned(S);
5924
5925 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5926}
5927
John Wiegley28bbe4b2011-04-28 01:08:34 +00005928template<typename Derived>
5929StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005930TreeTransform<Derived>::TransformMSDependentExistsStmt(
5931 MSDependentExistsStmt *S) {
5932 // Transform the nested-name-specifier, if any.
5933 NestedNameSpecifierLoc QualifierLoc;
5934 if (S->getQualifierLoc()) {
5935 QualifierLoc
5936 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5937 if (!QualifierLoc)
5938 return StmtError();
5939 }
5940
5941 // Transform the declaration name.
5942 DeclarationNameInfo NameInfo = S->getNameInfo();
5943 if (NameInfo.getName()) {
5944 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5945 if (!NameInfo.getName())
5946 return StmtError();
5947 }
5948
5949 // Check whether anything changed.
5950 if (!getDerived().AlwaysRebuild() &&
5951 QualifierLoc == S->getQualifierLoc() &&
5952 NameInfo.getName() == S->getNameInfo().getName())
5953 return S;
5954
5955 // Determine whether this name exists, if we can.
5956 CXXScopeSpec SS;
5957 SS.Adopt(QualifierLoc);
5958 bool Dependent = false;
5959 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5960 case Sema::IER_Exists:
5961 if (S->isIfExists())
5962 break;
5963
5964 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5965
5966 case Sema::IER_DoesNotExist:
5967 if (S->isIfNotExists())
5968 break;
5969
5970 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5971
5972 case Sema::IER_Dependent:
5973 Dependent = true;
5974 break;
Douglas Gregor65019ac2011-10-25 03:44:56 +00005975
5976 case Sema::IER_Error:
5977 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005978 }
5979
5980 // We need to continue with the instantiation, so do so now.
5981 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5982 if (SubStmt.isInvalid())
5983 return StmtError();
5984
5985 // If we have resolved the name, just transform to the substatement.
5986 if (!Dependent)
5987 return SubStmt;
5988
5989 // The name is still dependent, so build a dependent expression again.
5990 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5991 S->isIfExists(),
5992 QualifierLoc,
5993 NameInfo,
5994 SubStmt.get());
5995}
5996
5997template<typename Derived>
5998StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00005999TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6000 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6001 if(TryBlock.isInvalid()) return StmtError();
6002
6003 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6004 if(!getDerived().AlwaysRebuild() &&
6005 TryBlock.get() == S->getTryBlock() &&
6006 Handler.get() == S->getHandler())
6007 return SemaRef.Owned(S);
6008
6009 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6010 S->getTryLoc(),
6011 TryBlock.take(),
6012 Handler.take());
6013}
6014
6015template<typename Derived>
6016StmtResult
6017TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6018 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6019 if(Block.isInvalid()) return StmtError();
6020
6021 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6022 Block.take());
6023}
6024
6025template<typename Derived>
6026StmtResult
6027TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6028 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6029 if(FilterExpr.isInvalid()) return StmtError();
6030
6031 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6032 if(Block.isInvalid()) return StmtError();
6033
6034 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6035 FilterExpr.take(),
6036 Block.take());
6037}
6038
6039template<typename Derived>
6040StmtResult
6041TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6042 if(isa<SEHFinallyStmt>(Handler))
6043 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6044 else
6045 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6046}
6047
Douglas Gregor43959a92009-08-20 07:17:43 +00006048//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006049// Expression transformation
6050//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006051template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006052ExprResult
John McCall454feb92009-12-08 09:21:05 +00006053TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006054 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006055}
Mike Stump1eb44332009-09-09 15:08:12 +00006056
6057template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006058ExprResult
John McCall454feb92009-12-08 09:21:05 +00006059TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006060 NestedNameSpecifierLoc QualifierLoc;
6061 if (E->getQualifierLoc()) {
6062 QualifierLoc
6063 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6064 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006065 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006066 }
John McCalldbd872f2009-12-08 09:08:17 +00006067
6068 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006069 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6070 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006071 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006072 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006073
John McCallec8045d2010-08-17 21:27:17 +00006074 DeclarationNameInfo NameInfo = E->getNameInfo();
6075 if (NameInfo.getName()) {
6076 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6077 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006078 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006079 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006080
6081 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006082 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006083 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006084 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006085 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006086
6087 // Mark it referenced in the new context regardless.
6088 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006089 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006090
John McCall3fa5cae2010-10-26 07:05:15 +00006091 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006092 }
John McCalldbd872f2009-12-08 09:08:17 +00006093
6094 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006095 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006096 TemplateArgs = &TransArgs;
6097 TransArgs.setLAngleLoc(E->getLAngleLoc());
6098 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006099 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6100 E->getNumTemplateArgs(),
6101 TransArgs))
6102 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006103 }
6104
Douglas Gregor40d96a62011-02-28 21:54:11 +00006105 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
6106 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006107}
Mike Stump1eb44332009-09-09 15:08:12 +00006108
Douglas Gregorb98b1992009-08-11 05:31:07 +00006109template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006110ExprResult
John McCall454feb92009-12-08 09:21:05 +00006111TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006112 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006113}
Mike Stump1eb44332009-09-09 15:08:12 +00006114
Douglas Gregorb98b1992009-08-11 05:31:07 +00006115template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006116ExprResult
John McCall454feb92009-12-08 09:21:05 +00006117TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006118 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006119}
Mike Stump1eb44332009-09-09 15:08:12 +00006120
Douglas Gregorb98b1992009-08-11 05:31:07 +00006121template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006122ExprResult
John McCall454feb92009-12-08 09:21:05 +00006123TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006124 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006125}
Mike Stump1eb44332009-09-09 15:08:12 +00006126
Douglas Gregorb98b1992009-08-11 05:31:07 +00006127template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006128ExprResult
John McCall454feb92009-12-08 09:21:05 +00006129TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006130 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006131}
Mike Stump1eb44332009-09-09 15:08:12 +00006132
Douglas Gregorb98b1992009-08-11 05:31:07 +00006133template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006134ExprResult
John McCall454feb92009-12-08 09:21:05 +00006135TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006136 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006137}
6138
6139template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006140ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006141TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6142 return SemaRef.MaybeBindToTemporary(E);
6143}
6144
6145template<typename Derived>
6146ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006147TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6148 ExprResult ControllingExpr =
6149 getDerived().TransformExpr(E->getControllingExpr());
6150 if (ControllingExpr.isInvalid())
6151 return ExprError();
6152
Chris Lattner686775d2011-07-20 06:58:45 +00006153 SmallVector<Expr *, 4> AssocExprs;
6154 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006155 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6156 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6157 if (TS) {
6158 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6159 if (!AssocType)
6160 return ExprError();
6161 AssocTypes.push_back(AssocType);
6162 } else {
6163 AssocTypes.push_back(0);
6164 }
6165
6166 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6167 if (AssocExpr.isInvalid())
6168 return ExprError();
6169 AssocExprs.push_back(AssocExpr.release());
6170 }
6171
6172 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6173 E->getDefaultLoc(),
6174 E->getRParenLoc(),
6175 ControllingExpr.release(),
6176 AssocTypes.data(),
6177 AssocExprs.data(),
6178 E->getNumAssocs());
6179}
6180
6181template<typename Derived>
6182ExprResult
John McCall454feb92009-12-08 09:21:05 +00006183TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006184 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006185 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006186 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006187
Douglas Gregorb98b1992009-08-11 05:31:07 +00006188 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006189 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006190
John McCall9ae2f072010-08-23 23:25:46 +00006191 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006192 E->getRParen());
6193}
6194
Mike Stump1eb44332009-09-09 15:08:12 +00006195template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006196ExprResult
John McCall454feb92009-12-08 09:21:05 +00006197TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006198 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006199 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006200 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006201
Douglas Gregorb98b1992009-08-11 05:31:07 +00006202 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006203 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006204
Douglas Gregorb98b1992009-08-11 05:31:07 +00006205 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6206 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006207 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006208}
Mike Stump1eb44332009-09-09 15:08:12 +00006209
Douglas Gregorb98b1992009-08-11 05:31:07 +00006210template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006211ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006212TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6213 // Transform the type.
6214 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6215 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006216 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006217
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006218 // Transform all of the components into components similar to what the
6219 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00006220 // FIXME: It would be slightly more efficient in the non-dependent case to
6221 // just map FieldDecls, rather than requiring the rebuilder to look for
6222 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006223 // template code that we don't care.
6224 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006225 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006226 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006227 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006228 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6229 const Node &ON = E->getComponent(I);
6230 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006231 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006232 Comp.LocStart = ON.getSourceRange().getBegin();
6233 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006234 switch (ON.getKind()) {
6235 case Node::Array: {
6236 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006237 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006238 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006239 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006240
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006241 ExprChanged = ExprChanged || Index.get() != FromIndex;
6242 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006243 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006244 break;
6245 }
Sean Huntc3021132010-05-05 15:23:54 +00006246
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006247 case Node::Field:
6248 case Node::Identifier:
6249 Comp.isBrackets = false;
6250 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006251 if (!Comp.U.IdentInfo)
6252 continue;
Sean Huntc3021132010-05-05 15:23:54 +00006253
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006254 break;
Sean Huntc3021132010-05-05 15:23:54 +00006255
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006256 case Node::Base:
6257 // Will be recomputed during the rebuild.
6258 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006259 }
Sean Huntc3021132010-05-05 15:23:54 +00006260
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006261 Components.push_back(Comp);
6262 }
Sean Huntc3021132010-05-05 15:23:54 +00006263
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006264 // If nothing changed, retain the existing expression.
6265 if (!getDerived().AlwaysRebuild() &&
6266 Type == E->getTypeSourceInfo() &&
6267 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006268 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006269
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006270 // Build a new offsetof expression.
6271 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6272 Components.data(), Components.size(),
6273 E->getRParenLoc());
6274}
6275
6276template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006277ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006278TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6279 assert(getDerived().AlreadyTransformed(E->getType()) &&
6280 "opaque value expression requires transformation");
6281 return SemaRef.Owned(E);
6282}
6283
6284template<typename Derived>
6285ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006286TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006287 // Rebuild the syntactic form. The original syntactic form has
6288 // opaque-value expressions in it, so strip those away and rebuild
6289 // the result. This is a really awful way of doing this, but the
6290 // better solution (rebuilding the semantic expressions and
6291 // rebinding OVEs as necessary) doesn't work; we'd need
6292 // TreeTransform to not strip away implicit conversions.
6293 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6294 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006295 if (result.isInvalid()) return ExprError();
6296
6297 // If that gives us a pseudo-object result back, the pseudo-object
6298 // expression must have been an lvalue-to-rvalue conversion which we
6299 // should reapply.
6300 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6301 result = SemaRef.checkPseudoObjectRValue(result.take());
6302
6303 return result;
6304}
6305
6306template<typename Derived>
6307ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006308TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6309 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006310 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006311 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006312
John McCalla93c9342009-12-07 02:54:59 +00006313 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006314 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006315 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006316
John McCall5ab75172009-11-04 07:28:41 +00006317 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006318 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006319
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006320 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6321 E->getKind(),
6322 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006323 }
Mike Stump1eb44332009-09-09 15:08:12 +00006324
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006325 // C++0x [expr.sizeof]p1:
6326 // The operand is either an expression, which is an unevaluated operand
6327 // [...]
6328 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006329
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006330 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6331 if (SubExpr.isInvalid())
6332 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006333
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006334 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6335 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006336
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006337 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6338 E->getOperatorLoc(),
6339 E->getKind(),
6340 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006341}
Mike Stump1eb44332009-09-09 15:08:12 +00006342
Douglas Gregorb98b1992009-08-11 05:31:07 +00006343template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006344ExprResult
John McCall454feb92009-12-08 09:21:05 +00006345TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006346 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006347 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006348 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006349
John McCall60d7b3a2010-08-24 06:29:42 +00006350 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006351 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006352 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006353
6354
Douglas Gregorb98b1992009-08-11 05:31:07 +00006355 if (!getDerived().AlwaysRebuild() &&
6356 LHS.get() == E->getLHS() &&
6357 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006358 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006359
John McCall9ae2f072010-08-23 23:25:46 +00006360 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006361 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006362 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006363 E->getRBracketLoc());
6364}
Mike Stump1eb44332009-09-09 15:08:12 +00006365
6366template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006367ExprResult
John McCall454feb92009-12-08 09:21:05 +00006368TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006369 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006370 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006371 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006372 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006373
6374 // Transform arguments.
6375 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006376 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006377 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6378 &ArgChanged))
6379 return ExprError();
6380
Douglas Gregorb98b1992009-08-11 05:31:07 +00006381 if (!getDerived().AlwaysRebuild() &&
6382 Callee.get() == E->getCallee() &&
6383 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006384 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006385
Douglas Gregorb98b1992009-08-11 05:31:07 +00006386 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006387 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006388 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006389 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006390 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006391 E->getRParenLoc());
6392}
Mike Stump1eb44332009-09-09 15:08:12 +00006393
6394template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006395ExprResult
John McCall454feb92009-12-08 09:21:05 +00006396TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006397 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006398 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006399 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006400
Douglas Gregor40d96a62011-02-28 21:54:11 +00006401 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006402 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006403 QualifierLoc
6404 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6405
6406 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006407 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006408 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006409 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006410
Eli Friedmanf595cc42009-12-04 06:40:45 +00006411 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006412 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6413 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006414 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006415 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006416
John McCall6bb80172010-03-30 21:47:33 +00006417 NamedDecl *FoundDecl = E->getFoundDecl();
6418 if (FoundDecl == E->getMemberDecl()) {
6419 FoundDecl = Member;
6420 } else {
6421 FoundDecl = cast_or_null<NamedDecl>(
6422 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6423 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006424 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006425 }
6426
Douglas Gregorb98b1992009-08-11 05:31:07 +00006427 if (!getDerived().AlwaysRebuild() &&
6428 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006429 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006430 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006431 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006432 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006433
Anders Carlsson1f240322009-12-22 05:24:09 +00006434 // Mark it referenced in the new context regardless.
6435 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006436 SemaRef.MarkMemberReferenced(E);
6437
John McCall3fa5cae2010-10-26 07:05:15 +00006438 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006439 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006440
John McCalld5532b62009-11-23 01:53:49 +00006441 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006442 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006443 TransArgs.setLAngleLoc(E->getLAngleLoc());
6444 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006445 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6446 E->getNumTemplateArgs(),
6447 TransArgs))
6448 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006449 }
Sean Huntc3021132010-05-05 15:23:54 +00006450
Douglas Gregorb98b1992009-08-11 05:31:07 +00006451 // FIXME: Bogus source location for the operator
6452 SourceLocation FakeOperatorLoc
6453 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6454
John McCallc2233c52010-01-15 08:34:02 +00006455 // FIXME: to do this check properly, we will need to preserve the
6456 // first-qualifier-in-scope here, just in case we had a dependent
6457 // base (and therefore couldn't do the check) and a
6458 // nested-name-qualifier (and therefore could do the lookup).
6459 NamedDecl *FirstQualifierInScope = 0;
6460
John McCall9ae2f072010-08-23 23:25:46 +00006461 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006462 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006463 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006464 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006465 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006466 Member,
John McCall6bb80172010-03-30 21:47:33 +00006467 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006468 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006469 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006470 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006471}
Mike Stump1eb44332009-09-09 15:08:12 +00006472
Douglas Gregorb98b1992009-08-11 05:31:07 +00006473template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006474ExprResult
John McCall454feb92009-12-08 09:21:05 +00006475TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006476 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006477 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006478 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006479
John McCall60d7b3a2010-08-24 06:29:42 +00006480 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006481 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006482 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006483
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484 if (!getDerived().AlwaysRebuild() &&
6485 LHS.get() == E->getLHS() &&
6486 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006487 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006488
Douglas Gregorb98b1992009-08-11 05:31:07 +00006489 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006490 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006491}
6492
Mike Stump1eb44332009-09-09 15:08:12 +00006493template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006494ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006495TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006496 CompoundAssignOperator *E) {
6497 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006498}
Mike Stump1eb44332009-09-09 15:08:12 +00006499
Douglas Gregorb98b1992009-08-11 05:31:07 +00006500template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006501ExprResult TreeTransform<Derived>::
6502TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6503 // Just rebuild the common and RHS expressions and see whether we
6504 // get any changes.
6505
6506 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6507 if (commonExpr.isInvalid())
6508 return ExprError();
6509
6510 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6511 if (rhs.isInvalid())
6512 return ExprError();
6513
6514 if (!getDerived().AlwaysRebuild() &&
6515 commonExpr.get() == e->getCommon() &&
6516 rhs.get() == e->getFalseExpr())
6517 return SemaRef.Owned(e);
6518
6519 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6520 e->getQuestionLoc(),
6521 0,
6522 e->getColonLoc(),
6523 rhs.get());
6524}
6525
6526template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006527ExprResult
John McCall454feb92009-12-08 09:21:05 +00006528TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006529 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006530 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006531 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006532
John McCall60d7b3a2010-08-24 06:29:42 +00006533 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006534 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006535 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006536
John McCall60d7b3a2010-08-24 06:29:42 +00006537 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006538 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006539 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006540
Douglas Gregorb98b1992009-08-11 05:31:07 +00006541 if (!getDerived().AlwaysRebuild() &&
6542 Cond.get() == E->getCond() &&
6543 LHS.get() == E->getLHS() &&
6544 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006545 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006546
John McCall9ae2f072010-08-23 23:25:46 +00006547 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006548 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006549 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006550 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006551 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006552}
Mike Stump1eb44332009-09-09 15:08:12 +00006553
6554template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006555ExprResult
John McCall454feb92009-12-08 09:21:05 +00006556TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006557 // Implicit casts are eliminated during transformation, since they
6558 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006559 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006560}
Mike Stump1eb44332009-09-09 15:08:12 +00006561
Douglas Gregorb98b1992009-08-11 05:31:07 +00006562template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006563ExprResult
John McCall454feb92009-12-08 09:21:05 +00006564TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006565 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6566 if (!Type)
6567 return ExprError();
6568
John McCall60d7b3a2010-08-24 06:29:42 +00006569 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006570 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006571 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006572 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006573
Douglas Gregorb98b1992009-08-11 05:31:07 +00006574 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006575 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006576 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006577 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006578
John McCall9d125032010-01-15 18:39:57 +00006579 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006580 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006581 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006582 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006583}
Mike Stump1eb44332009-09-09 15:08:12 +00006584
Douglas Gregorb98b1992009-08-11 05:31:07 +00006585template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006586ExprResult
John McCall454feb92009-12-08 09:21:05 +00006587TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006588 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6589 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6590 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006591 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006592
John McCall60d7b3a2010-08-24 06:29:42 +00006593 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006594 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006595 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006596
Douglas Gregorb98b1992009-08-11 05:31:07 +00006597 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006598 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006599 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006600 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006601
John McCall1d7d8d62010-01-19 22:33:45 +00006602 // Note: the expression type doesn't necessarily match the
6603 // type-as-written, but that's okay, because it should always be
6604 // derivable from the initializer.
6605
John McCall42f56b52010-01-18 19:35:47 +00006606 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006607 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006608 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006609}
Mike Stump1eb44332009-09-09 15:08:12 +00006610
Douglas Gregorb98b1992009-08-11 05:31:07 +00006611template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006612ExprResult
John McCall454feb92009-12-08 09:21:05 +00006613TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006614 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006615 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006616 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006617
Douglas Gregorb98b1992009-08-11 05:31:07 +00006618 if (!getDerived().AlwaysRebuild() &&
6619 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006620 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006621
Douglas Gregorb98b1992009-08-11 05:31:07 +00006622 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006623 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006624 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006625 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006626 E->getAccessorLoc(),
6627 E->getAccessor());
6628}
Mike Stump1eb44332009-09-09 15:08:12 +00006629
Douglas Gregorb98b1992009-08-11 05:31:07 +00006630template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006631ExprResult
John McCall454feb92009-12-08 09:21:05 +00006632TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006634
John McCallca0408f2010-08-23 06:44:23 +00006635 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006636 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6637 Inits, &InitChanged))
6638 return ExprError();
6639
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006641 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006642
Douglas Gregorb98b1992009-08-11 05:31:07 +00006643 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006644 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006645}
Mike Stump1eb44332009-09-09 15:08:12 +00006646
Douglas Gregorb98b1992009-08-11 05:31:07 +00006647template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006648ExprResult
John McCall454feb92009-12-08 09:21:05 +00006649TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006650 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006651
Douglas Gregor43959a92009-08-20 07:17:43 +00006652 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006653 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006655 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006656
Douglas Gregor43959a92009-08-20 07:17:43 +00006657 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006658 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006659 bool ExprChanged = false;
6660 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6661 DEnd = E->designators_end();
6662 D != DEnd; ++D) {
6663 if (D->isFieldDesignator()) {
6664 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6665 D->getDotLoc(),
6666 D->getFieldLoc()));
6667 continue;
6668 }
Mike Stump1eb44332009-09-09 15:08:12 +00006669
Douglas Gregorb98b1992009-08-11 05:31:07 +00006670 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006671 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006672 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006673 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006674
6675 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006676 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006677
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6679 ArrayExprs.push_back(Index.release());
6680 continue;
6681 }
Mike Stump1eb44332009-09-09 15:08:12 +00006682
Douglas Gregorb98b1992009-08-11 05:31:07 +00006683 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006684 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006685 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6686 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006687 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006688
John McCall60d7b3a2010-08-24 06:29:42 +00006689 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006690 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006691 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006692
6693 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006694 End.get(),
6695 D->getLBracketLoc(),
6696 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006697
Douglas Gregorb98b1992009-08-11 05:31:07 +00006698 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6699 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006700
Douglas Gregorb98b1992009-08-11 05:31:07 +00006701 ArrayExprs.push_back(Start.release());
6702 ArrayExprs.push_back(End.release());
6703 }
Mike Stump1eb44332009-09-09 15:08:12 +00006704
Douglas Gregorb98b1992009-08-11 05:31:07 +00006705 if (!getDerived().AlwaysRebuild() &&
6706 Init.get() == E->getInit() &&
6707 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006708 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006709
Douglas Gregorb98b1992009-08-11 05:31:07 +00006710 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6711 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006712 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006713}
Mike Stump1eb44332009-09-09 15:08:12 +00006714
Douglas Gregorb98b1992009-08-11 05:31:07 +00006715template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006716ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006717TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006718 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006719 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006720
Douglas Gregor5557b252009-10-28 00:29:27 +00006721 // FIXME: Will we ever have proper type location here? Will we actually
6722 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006723 QualType T = getDerived().TransformType(E->getType());
6724 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006725 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006726
Douglas Gregorb98b1992009-08-11 05:31:07 +00006727 if (!getDerived().AlwaysRebuild() &&
6728 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006729 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006730
Douglas Gregorb98b1992009-08-11 05:31:07 +00006731 return getDerived().RebuildImplicitValueInitExpr(T);
6732}
Mike Stump1eb44332009-09-09 15:08:12 +00006733
Douglas Gregorb98b1992009-08-11 05:31:07 +00006734template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006735ExprResult
John McCall454feb92009-12-08 09:21:05 +00006736TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006737 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6738 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006739 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006740
John McCall60d7b3a2010-08-24 06:29:42 +00006741 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006742 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006743 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006744
Douglas Gregorb98b1992009-08-11 05:31:07 +00006745 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006746 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006748 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006749
John McCall9ae2f072010-08-23 23:25:46 +00006750 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006751 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006752}
6753
6754template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006755ExprResult
John McCall454feb92009-12-08 09:21:05 +00006756TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006757 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006758 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006759 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6760 &ArgumentChanged))
6761 return ExprError();
6762
Douglas Gregorb98b1992009-08-11 05:31:07 +00006763 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6764 move_arg(Inits),
6765 E->getRParenLoc());
6766}
Mike Stump1eb44332009-09-09 15:08:12 +00006767
Douglas Gregorb98b1992009-08-11 05:31:07 +00006768/// \brief Transform an address-of-label expression.
6769///
6770/// By default, the transformation of an address-of-label expression always
6771/// rebuilds the expression, so that the label identifier can be resolved to
6772/// the corresponding label statement by semantic analysis.
6773template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006774ExprResult
John McCall454feb92009-12-08 09:21:05 +00006775TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006776 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6777 E->getLabel());
6778 if (!LD)
6779 return ExprError();
6780
Douglas Gregorb98b1992009-08-11 05:31:07 +00006781 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006782 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006783}
Mike Stump1eb44332009-09-09 15:08:12 +00006784
6785template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006786ExprResult
John McCall454feb92009-12-08 09:21:05 +00006787TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006788 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006789 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006790 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006791 if (SubStmt.isInvalid()) {
6792 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006793 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006794 }
Mike Stump1eb44332009-09-09 15:08:12 +00006795
Douglas Gregorb98b1992009-08-11 05:31:07 +00006796 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006797 SubStmt.get() == E->getSubStmt()) {
6798 // Calling this an 'error' is unintuitive, but it does the right thing.
6799 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006800 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006801 }
Mike Stump1eb44332009-09-09 15:08:12 +00006802
6803 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006804 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006805 E->getRParenLoc());
6806}
Mike Stump1eb44332009-09-09 15:08:12 +00006807
Douglas Gregorb98b1992009-08-11 05:31:07 +00006808template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006809ExprResult
John McCall454feb92009-12-08 09:21:05 +00006810TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006811 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006812 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006813 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006814
John McCall60d7b3a2010-08-24 06:29:42 +00006815 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006816 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006817 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006818
John McCall60d7b3a2010-08-24 06:29:42 +00006819 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006820 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006821 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006822
Douglas Gregorb98b1992009-08-11 05:31:07 +00006823 if (!getDerived().AlwaysRebuild() &&
6824 Cond.get() == E->getCond() &&
6825 LHS.get() == E->getLHS() &&
6826 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006827 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006828
Douglas Gregorb98b1992009-08-11 05:31:07 +00006829 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006830 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006831 E->getRParenLoc());
6832}
Mike Stump1eb44332009-09-09 15:08:12 +00006833
Douglas Gregorb98b1992009-08-11 05:31:07 +00006834template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006835ExprResult
John McCall454feb92009-12-08 09:21:05 +00006836TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006837 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006838}
6839
6840template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006841ExprResult
John McCall454feb92009-12-08 09:21:05 +00006842TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006843 switch (E->getOperator()) {
6844 case OO_New:
6845 case OO_Delete:
6846 case OO_Array_New:
6847 case OO_Array_Delete:
6848 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Sean Huntc3021132010-05-05 15:23:54 +00006849
Douglas Gregor668d6d92009-12-13 20:44:55 +00006850 case OO_Call: {
6851 // This is a call to an object's operator().
6852 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6853
6854 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006855 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006856 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006857 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006858
6859 // FIXME: Poor location information
6860 SourceLocation FakeLParenLoc
6861 = SemaRef.PP.getLocForEndOfToken(
6862 static_cast<Expr *>(Object.get())->getLocEnd());
6863
6864 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006865 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006866 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6867 Args))
6868 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006869
John McCall9ae2f072010-08-23 23:25:46 +00006870 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006871 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006872 E->getLocEnd());
6873 }
6874
6875#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6876 case OO_##Name:
6877#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6878#include "clang/Basic/OperatorKinds.def"
6879 case OO_Subscript:
6880 // Handled below.
6881 break;
6882
6883 case OO_Conditional:
6884 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006885
6886 case OO_None:
6887 case NUM_OVERLOADED_OPERATORS:
6888 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006889 }
6890
John McCall60d7b3a2010-08-24 06:29:42 +00006891 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006892 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006893 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006894
John McCall60d7b3a2010-08-24 06:29:42 +00006895 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006896 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006897 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006898
John McCall60d7b3a2010-08-24 06:29:42 +00006899 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006900 if (E->getNumArgs() == 2) {
6901 Second = getDerived().TransformExpr(E->getArg(1));
6902 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006903 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006904 }
Mike Stump1eb44332009-09-09 15:08:12 +00006905
Douglas Gregorb98b1992009-08-11 05:31:07 +00006906 if (!getDerived().AlwaysRebuild() &&
6907 Callee.get() == E->getCallee() &&
6908 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006909 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006910 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006911
Douglas Gregorb98b1992009-08-11 05:31:07 +00006912 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6913 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006914 Callee.get(),
6915 First.get(),
6916 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006917}
Mike Stump1eb44332009-09-09 15:08:12 +00006918
Douglas Gregorb98b1992009-08-11 05:31:07 +00006919template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006920ExprResult
John McCall454feb92009-12-08 09:21:05 +00006921TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6922 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006923}
Mike Stump1eb44332009-09-09 15:08:12 +00006924
Douglas Gregorb98b1992009-08-11 05:31:07 +00006925template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006926ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006927TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6928 // Transform the callee.
6929 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6930 if (Callee.isInvalid())
6931 return ExprError();
6932
6933 // Transform exec config.
6934 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6935 if (EC.isInvalid())
6936 return ExprError();
6937
6938 // Transform arguments.
6939 bool ArgChanged = false;
6940 ASTOwningVector<Expr*> Args(SemaRef);
6941 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6942 &ArgChanged))
6943 return ExprError();
6944
6945 if (!getDerived().AlwaysRebuild() &&
6946 Callee.get() == E->getCallee() &&
6947 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006948 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006949
6950 // FIXME: Wrong source location information for the '('.
6951 SourceLocation FakeLParenLoc
6952 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6953 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6954 move_arg(Args),
6955 E->getRParenLoc(), EC.get());
6956}
6957
6958template<typename Derived>
6959ExprResult
John McCall454feb92009-12-08 09:21:05 +00006960TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006961 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6962 if (!Type)
6963 return ExprError();
6964
John McCall60d7b3a2010-08-24 06:29:42 +00006965 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006966 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006967 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006968 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006969
Douglas Gregorb98b1992009-08-11 05:31:07 +00006970 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006971 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006972 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006973 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006974
Douglas Gregorb98b1992009-08-11 05:31:07 +00006975 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006976 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006977 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6978 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6979 SourceLocation FakeRParenLoc
6980 = SemaRef.PP.getLocForEndOfToken(
6981 E->getSubExpr()->getSourceRange().getEnd());
6982 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006983 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006984 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006985 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006986 FakeRAngleLoc,
6987 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006988 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006989 FakeRParenLoc);
6990}
Mike Stump1eb44332009-09-09 15:08:12 +00006991
Douglas Gregorb98b1992009-08-11 05:31:07 +00006992template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006993ExprResult
John McCall454feb92009-12-08 09:21:05 +00006994TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6995 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006996}
Mike Stump1eb44332009-09-09 15:08:12 +00006997
6998template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006999ExprResult
John McCall454feb92009-12-08 09:21:05 +00007000TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7001 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007002}
7003
Douglas Gregorb98b1992009-08-11 05:31:07 +00007004template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007005ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007006TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007007 CXXReinterpretCastExpr *E) {
7008 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007009}
Mike Stump1eb44332009-09-09 15:08:12 +00007010
Douglas Gregorb98b1992009-08-11 05:31:07 +00007011template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007012ExprResult
John McCall454feb92009-12-08 09:21:05 +00007013TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7014 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007015}
Mike Stump1eb44332009-09-09 15:08:12 +00007016
Douglas Gregorb98b1992009-08-11 05:31:07 +00007017template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007018ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007019TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007020 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007021 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7022 if (!Type)
7023 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007024
John McCall60d7b3a2010-08-24 06:29:42 +00007025 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007026 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007027 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007028 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007029
Douglas Gregorb98b1992009-08-11 05:31:07 +00007030 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007031 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007032 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007033 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007034
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007035 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007036 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007037 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007038 E->getRParenLoc());
7039}
Mike Stump1eb44332009-09-09 15:08:12 +00007040
Douglas Gregorb98b1992009-08-11 05:31:07 +00007041template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007042ExprResult
John McCall454feb92009-12-08 09:21:05 +00007043TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007044 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007045 TypeSourceInfo *TInfo
7046 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7047 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007048 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007049
Douglas Gregorb98b1992009-08-11 05:31:07 +00007050 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007051 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007052 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007053
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007054 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7055 E->getLocStart(),
7056 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007057 E->getLocEnd());
7058 }
Mike Stump1eb44332009-09-09 15:08:12 +00007059
Eli Friedmanef331b72012-01-20 01:26:23 +00007060 // We don't know whether the subexpression is potentially evaluated until
7061 // after we perform semantic analysis. We speculatively assume it is
7062 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007063 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00007064 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00007065
John McCall60d7b3a2010-08-24 06:29:42 +00007066 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007067 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007068 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007069
Douglas Gregorb98b1992009-08-11 05:31:07 +00007070 if (!getDerived().AlwaysRebuild() &&
7071 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007072 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007073
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007074 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7075 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007076 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007077 E->getLocEnd());
7078}
7079
7080template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007081ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007082TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7083 if (E->isTypeOperand()) {
7084 TypeSourceInfo *TInfo
7085 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7086 if (!TInfo)
7087 return ExprError();
7088
7089 if (!getDerived().AlwaysRebuild() &&
7090 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007091 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007092
Douglas Gregor3c52a212011-03-06 17:40:41 +00007093 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007094 E->getLocStart(),
7095 TInfo,
7096 E->getLocEnd());
7097 }
7098
Francois Pichet01b7c302010-09-08 12:20:18 +00007099 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7100
7101 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7102 if (SubExpr.isInvalid())
7103 return ExprError();
7104
7105 if (!getDerived().AlwaysRebuild() &&
7106 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007107 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007108
7109 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7110 E->getLocStart(),
7111 SubExpr.get(),
7112 E->getLocEnd());
7113}
7114
7115template<typename Derived>
7116ExprResult
John McCall454feb92009-12-08 09:21:05 +00007117TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007118 return SemaRef.Owned(E);
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
Douglas Gregorb98b1992009-08-11 05:31:07 +00007123TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007124 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007125 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007126}
Mike Stump1eb44332009-09-09 15:08:12 +00007127
Douglas Gregorb98b1992009-08-11 05:31:07 +00007128template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007129ExprResult
John McCall454feb92009-12-08 09:21:05 +00007130TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007131 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007132 QualType T;
7133 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7134 T = MD->getThisType(getSema().Context);
7135 else
7136 T = getSema().Context.getPointerType(
7137 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007138
Douglas Gregorec79d872012-02-24 17:41:38 +00007139 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7140 // Make sure that we capture 'this'.
7141 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007142 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007143 }
7144
Douglas Gregor828a1972010-01-07 23:12:05 +00007145 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007146}
Mike Stump1eb44332009-09-09 15:08:12 +00007147
Douglas Gregorb98b1992009-08-11 05:31:07 +00007148template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007149ExprResult
John McCall454feb92009-12-08 09:21:05 +00007150TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007151 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007152 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007153 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007154
Douglas Gregorb98b1992009-08-11 05:31:07 +00007155 if (!getDerived().AlwaysRebuild() &&
7156 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007157 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007158
Douglas Gregorbca01b42011-07-06 22:04:06 +00007159 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7160 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007161}
Mike Stump1eb44332009-09-09 15:08:12 +00007162
Douglas Gregorb98b1992009-08-11 05:31:07 +00007163template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007164ExprResult
John McCall454feb92009-12-08 09:21:05 +00007165TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007166 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007167 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7168 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007169 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007170 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007171
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007172 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007173 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007174 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007175
Douglas Gregor036aed12009-12-23 23:03:06 +00007176 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007177}
Mike Stump1eb44332009-09-09 15:08:12 +00007178
Douglas Gregorb98b1992009-08-11 05:31:07 +00007179template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007180ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007181TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7182 CXXScalarValueInitExpr *E) {
7183 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7184 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007185 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00007186
Douglas Gregorb98b1992009-08-11 05:31:07 +00007187 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007188 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007189 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007190
Douglas Gregorab6677e2010-09-08 00:15:04 +00007191 return getDerived().RebuildCXXScalarValueInitExpr(T,
7192 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007193 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007194}
Mike Stump1eb44332009-09-09 15:08:12 +00007195
Douglas Gregorb98b1992009-08-11 05:31:07 +00007196template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007197ExprResult
John McCall454feb92009-12-08 09:21:05 +00007198TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007199 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007200 TypeSourceInfo *AllocTypeInfo
7201 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7202 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007203 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007204
Douglas Gregorb98b1992009-08-11 05:31:07 +00007205 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007206 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007207 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007208 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007209
Douglas Gregorb98b1992009-08-11 05:31:07 +00007210 // Transform the placement arguments (if any).
7211 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007212 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007213 if (getDerived().TransformExprs(E->getPlacementArgs(),
7214 E->getNumPlacementArgs(), true,
7215 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007216 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007217
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007218 // Transform the initializer (if any).
7219 Expr *OldInit = E->getInitializer();
7220 ExprResult NewInit;
7221 if (OldInit)
7222 NewInit = getDerived().TransformExpr(OldInit);
7223 if (NewInit.isInvalid())
7224 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007225
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007226 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007227 FunctionDecl *OperatorNew = 0;
7228 if (E->getOperatorNew()) {
7229 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007230 getDerived().TransformDecl(E->getLocStart(),
7231 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007232 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007233 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007234 }
7235
7236 FunctionDecl *OperatorDelete = 0;
7237 if (E->getOperatorDelete()) {
7238 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007239 getDerived().TransformDecl(E->getLocStart(),
7240 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007241 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007242 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007243 }
Sean Huntc3021132010-05-05 15:23:54 +00007244
Douglas Gregorb98b1992009-08-11 05:31:07 +00007245 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007246 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007247 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007248 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007249 OperatorNew == E->getOperatorNew() &&
7250 OperatorDelete == E->getOperatorDelete() &&
7251 !ArgumentChanged) {
7252 // Mark any declarations we need as referenced.
7253 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007254 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007255 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007256 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007257 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007258
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007259 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007260 QualType ElementType
7261 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7262 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7263 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7264 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007265 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007266 }
7267 }
7268 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007269
John McCall3fa5cae2010-10-26 07:05:15 +00007270 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007271 }
Mike Stump1eb44332009-09-09 15:08:12 +00007272
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007273 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007274 if (!ArraySize.get()) {
7275 // If no array size was specified, but the new expression was
7276 // instantiated with an array type (e.g., "new T" where T is
7277 // instantiated with "int[4]"), extract the outer bound from the
7278 // array type as our array size. We do this with constant and
7279 // dependently-sized array types.
7280 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7281 if (!ArrayT) {
7282 // Do nothing
7283 } else if (const ConstantArrayType *ConsArrayT
7284 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007285 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007286 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7287 ConsArrayT->getSize(),
7288 SemaRef.Context.getSizeType(),
7289 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007290 AllocType = ConsArrayT->getElementType();
7291 } else if (const DependentSizedArrayType *DepArrayT
7292 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7293 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007294 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007295 AllocType = DepArrayT->getElementType();
7296 }
7297 }
7298 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007299
Douglas Gregorb98b1992009-08-11 05:31:07 +00007300 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7301 E->isGlobalNew(),
7302 /*FIXME:*/E->getLocStart(),
7303 move_arg(PlacementArgs),
7304 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007305 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007306 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007307 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007308 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007309 E->getDirectInitRange(),
7310 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007311}
Mike Stump1eb44332009-09-09 15:08:12 +00007312
Douglas Gregorb98b1992009-08-11 05:31:07 +00007313template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007314ExprResult
John McCall454feb92009-12-08 09:21:05 +00007315TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007316 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007317 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007318 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007319
Douglas Gregor1af74512010-02-26 00:38:10 +00007320 // Transform the delete operator, if known.
7321 FunctionDecl *OperatorDelete = 0;
7322 if (E->getOperatorDelete()) {
7323 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007324 getDerived().TransformDecl(E->getLocStart(),
7325 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007326 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007327 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007328 }
Sean Huntc3021132010-05-05 15:23:54 +00007329
Douglas Gregorb98b1992009-08-11 05:31:07 +00007330 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007331 Operand.get() == E->getArgument() &&
7332 OperatorDelete == E->getOperatorDelete()) {
7333 // Mark any declarations we need as referenced.
7334 // FIXME: instantiation-specific.
7335 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007336 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007337
7338 if (!E->getArgument()->isTypeDependent()) {
7339 QualType Destroyed = SemaRef.Context.getBaseElementType(
7340 E->getDestroyedType());
7341 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7342 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Eli Friedman5f2987c2012-02-02 03:46:19 +00007343 SemaRef.MarkFunctionReferenced(E->getLocStart(),
7344 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007345 }
7346 }
7347
John McCall3fa5cae2010-10-26 07:05:15 +00007348 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007349 }
Mike Stump1eb44332009-09-09 15:08:12 +00007350
Douglas Gregorb98b1992009-08-11 05:31:07 +00007351 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7352 E->isGlobalDelete(),
7353 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007354 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007355}
Mike Stump1eb44332009-09-09 15:08:12 +00007356
Douglas Gregorb98b1992009-08-11 05:31:07 +00007357template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007358ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007359TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007360 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007361 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007362 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007363 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007364
John McCallb3d87482010-08-24 05:47:05 +00007365 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007366 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007367 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007368 E->getOperatorLoc(),
7369 E->isArrow()? tok::arrow : tok::period,
7370 ObjectTypePtr,
7371 MayBePseudoDestructor);
7372 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007373 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007374
John McCallb3d87482010-08-24 05:47:05 +00007375 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007376 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7377 if (QualifierLoc) {
7378 QualifierLoc
7379 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7380 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007381 return ExprError();
7382 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007383 CXXScopeSpec SS;
7384 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007385
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007386 PseudoDestructorTypeStorage Destroyed;
7387 if (E->getDestroyedTypeInfo()) {
7388 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007389 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007390 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007391 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007392 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007393 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007394 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007395 // We aren't likely to be able to resolve the identifier down to a type
7396 // now anyway, so just retain the identifier.
7397 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7398 E->getDestroyedTypeLoc());
7399 } else {
7400 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007401 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007402 *E->getDestroyedTypeIdentifier(),
7403 E->getDestroyedTypeLoc(),
7404 /*Scope=*/0,
7405 SS, ObjectTypePtr,
7406 false);
7407 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007408 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007409
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007410 Destroyed
7411 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7412 E->getDestroyedTypeLoc());
7413 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007414
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007415 TypeSourceInfo *ScopeTypeInfo = 0;
7416 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007417 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007418 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007419 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007420 }
Sean Huntc3021132010-05-05 15:23:54 +00007421
John McCall9ae2f072010-08-23 23:25:46 +00007422 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007423 E->getOperatorLoc(),
7424 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007425 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007426 ScopeTypeInfo,
7427 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007428 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007429 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007430}
Mike Stump1eb44332009-09-09 15:08:12 +00007431
Douglas Gregora71d8192009-09-04 17:36:40 +00007432template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007433ExprResult
John McCallba135432009-11-21 08:51:07 +00007434TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007435 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007436 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7437 Sema::LookupOrdinaryName);
7438
7439 // Transform all the decls.
7440 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7441 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007442 NamedDecl *InstD = static_cast<NamedDecl*>(
7443 getDerived().TransformDecl(Old->getNameLoc(),
7444 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007445 if (!InstD) {
7446 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7447 // This can happen because of dependent hiding.
7448 if (isa<UsingShadowDecl>(*I))
7449 continue;
7450 else
John McCallf312b1e2010-08-26 23:41:50 +00007451 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007452 }
John McCallf7a1a742009-11-24 19:00:30 +00007453
7454 // Expand using declarations.
7455 if (isa<UsingDecl>(InstD)) {
7456 UsingDecl *UD = cast<UsingDecl>(InstD);
7457 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7458 E = UD->shadow_end(); I != E; ++I)
7459 R.addDecl(*I);
7460 continue;
7461 }
7462
7463 R.addDecl(InstD);
7464 }
7465
7466 // Resolve a kind, but don't do any further analysis. If it's
7467 // ambiguous, the callee needs to deal with it.
7468 R.resolveKind();
7469
7470 // Rebuild the nested-name qualifier, if present.
7471 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007472 if (Old->getQualifierLoc()) {
7473 NestedNameSpecifierLoc QualifierLoc
7474 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7475 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007476 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007477
Douglas Gregor4c9be892011-02-28 20:01:57 +00007478 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007479 }
7480
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007481 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007482 CXXRecordDecl *NamingClass
7483 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7484 Old->getNameLoc(),
7485 Old->getNamingClass()));
7486 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007487 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007488
Douglas Gregor66c45152010-04-27 16:10:10 +00007489 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007490 }
7491
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007492 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7493
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007494 // If we have neither explicit template arguments, nor the template keyword,
7495 // it's a normal declaration name.
7496 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007497 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7498
7499 // If we have template arguments, rebuild them, then rebuild the
7500 // templateid expression.
7501 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007502 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7503 Old->getNumTemplateArgs(),
7504 TransArgs))
7505 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007506
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007507 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007508 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007509}
Mike Stump1eb44332009-09-09 15:08:12 +00007510
Douglas Gregorb98b1992009-08-11 05:31:07 +00007511template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007512ExprResult
John McCall454feb92009-12-08 09:21:05 +00007513TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007514 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7515 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007516 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007517
Douglas Gregorb98b1992009-08-11 05:31:07 +00007518 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007519 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007520 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007521
Mike Stump1eb44332009-09-09 15:08:12 +00007522 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007523 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007524 T,
7525 E->getLocEnd());
7526}
Mike Stump1eb44332009-09-09 15:08:12 +00007527
Douglas Gregorb98b1992009-08-11 05:31:07 +00007528template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007529ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007530TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7531 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7532 if (!LhsT)
7533 return ExprError();
7534
7535 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7536 if (!RhsT)
7537 return ExprError();
7538
7539 if (!getDerived().AlwaysRebuild() &&
7540 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7541 return SemaRef.Owned(E);
7542
7543 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7544 E->getLocStart(),
7545 LhsT, RhsT,
7546 E->getLocEnd());
7547}
7548
7549template<typename Derived>
7550ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007551TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7552 bool ArgChanged = false;
7553 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7554 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7555 TypeSourceInfo *From = E->getArg(I);
7556 TypeLoc FromTL = From->getTypeLoc();
7557 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7558 TypeLocBuilder TLB;
7559 TLB.reserve(FromTL.getFullDataSize());
7560 QualType To = getDerived().TransformType(TLB, FromTL);
7561 if (To.isNull())
7562 return ExprError();
7563
7564 if (To == From->getType())
7565 Args.push_back(From);
7566 else {
7567 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7568 ArgChanged = true;
7569 }
7570 continue;
7571 }
7572
7573 ArgChanged = true;
7574
7575 // We have a pack expansion. Instantiate it.
7576 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
7577 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7578 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7579 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
7580
7581 // Determine whether the set of unexpanded parameter packs can and should
7582 // be expanded.
7583 bool Expand = true;
7584 bool RetainExpansion = false;
7585 llvm::Optional<unsigned> OrigNumExpansions
7586 = ExpansionTL.getTypePtr()->getNumExpansions();
7587 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7588 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7589 PatternTL.getSourceRange(),
7590 Unexpanded,
7591 Expand, RetainExpansion,
7592 NumExpansions))
7593 return ExprError();
7594
7595 if (!Expand) {
7596 // The transform has determined that we should perform a simple
7597 // transformation on the pack expansion, producing another pack
7598 // expansion.
7599 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7600
7601 TypeLocBuilder TLB;
7602 TLB.reserve(From->getTypeLoc().getFullDataSize());
7603
7604 QualType To = getDerived().TransformType(TLB, PatternTL);
7605 if (To.isNull())
7606 return ExprError();
7607
7608 To = getDerived().RebuildPackExpansionType(To,
7609 PatternTL.getSourceRange(),
7610 ExpansionTL.getEllipsisLoc(),
7611 NumExpansions);
7612 if (To.isNull())
7613 return ExprError();
7614
7615 PackExpansionTypeLoc ToExpansionTL
7616 = TLB.push<PackExpansionTypeLoc>(To);
7617 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7618 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7619 continue;
7620 }
7621
7622 // Expand the pack expansion by substituting for each argument in the
7623 // pack(s).
7624 for (unsigned I = 0; I != *NumExpansions; ++I) {
7625 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7626 TypeLocBuilder TLB;
7627 TLB.reserve(PatternTL.getFullDataSize());
7628 QualType To = getDerived().TransformType(TLB, PatternTL);
7629 if (To.isNull())
7630 return ExprError();
7631
7632 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7633 }
7634
7635 if (!RetainExpansion)
7636 continue;
7637
7638 // If we're supposed to retain a pack expansion, do so by temporarily
7639 // forgetting the partially-substituted parameter pack.
7640 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7641
7642 TypeLocBuilder TLB;
7643 TLB.reserve(From->getTypeLoc().getFullDataSize());
7644
7645 QualType To = getDerived().TransformType(TLB, PatternTL);
7646 if (To.isNull())
7647 return ExprError();
7648
7649 To = getDerived().RebuildPackExpansionType(To,
7650 PatternTL.getSourceRange(),
7651 ExpansionTL.getEllipsisLoc(),
7652 NumExpansions);
7653 if (To.isNull())
7654 return ExprError();
7655
7656 PackExpansionTypeLoc ToExpansionTL
7657 = TLB.push<PackExpansionTypeLoc>(To);
7658 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7659 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7660 }
7661
7662 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7663 return SemaRef.Owned(E);
7664
7665 return getDerived().RebuildTypeTrait(E->getTrait(),
7666 E->getLocStart(),
7667 Args,
7668 E->getLocEnd());
7669}
7670
7671template<typename Derived>
7672ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007673TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7674 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7675 if (!T)
7676 return ExprError();
7677
7678 if (!getDerived().AlwaysRebuild() &&
7679 T == E->getQueriedTypeSourceInfo())
7680 return SemaRef.Owned(E);
7681
7682 ExprResult SubExpr;
7683 {
7684 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7685 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7686 if (SubExpr.isInvalid())
7687 return ExprError();
7688
7689 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7690 return SemaRef.Owned(E);
7691 }
7692
7693 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7694 E->getLocStart(),
7695 T,
7696 SubExpr.get(),
7697 E->getLocEnd());
7698}
7699
7700template<typename Derived>
7701ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007702TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7703 ExprResult SubExpr;
7704 {
7705 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7706 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7707 if (SubExpr.isInvalid())
7708 return ExprError();
7709
7710 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7711 return SemaRef.Owned(E);
7712 }
7713
7714 return getDerived().RebuildExpressionTrait(
7715 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7716}
7717
7718template<typename Derived>
7719ExprResult
John McCall865d4472009-11-19 22:55:06 +00007720TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007721 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007722 NestedNameSpecifierLoc QualifierLoc
7723 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7724 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007725 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007726 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007727
John McCall43fed0d2010-11-12 08:19:04 +00007728 // TODO: If this is a conversion-function-id, verify that the
7729 // destination type name (if present) resolves the same way after
7730 // instantiation as it did in the local scope.
7731
Abramo Bagnara25777432010-08-11 22:01:17 +00007732 DeclarationNameInfo NameInfo
7733 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7734 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007735 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007736
John McCallf7a1a742009-11-24 19:00:30 +00007737 if (!E->hasExplicitTemplateArgs()) {
7738 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007739 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007740 // Note: it is sufficient to compare the Name component of NameInfo:
7741 // if name has not changed, DNLoc has not changed either.
7742 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007743 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007744
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007745 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007746 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007747 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007748 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007749 }
John McCalld5532b62009-11-23 01:53:49 +00007750
7751 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007752 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7753 E->getNumTemplateArgs(),
7754 TransArgs))
7755 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007756
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007757 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007758 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007759 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007760 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007761}
7762
7763template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007764ExprResult
John McCall454feb92009-12-08 09:21:05 +00007765TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007766 // CXXConstructExprs are always implicit, so when we have a
7767 // 1-argument construction we just transform that argument.
7768 if (E->getNumArgs() == 1 ||
7769 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7770 return getDerived().TransformExpr(E->getArg(0));
7771
Douglas Gregorb98b1992009-08-11 05:31:07 +00007772 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7773
7774 QualType T = getDerived().TransformType(E->getType());
7775 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007776 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007777
7778 CXXConstructorDecl *Constructor
7779 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007780 getDerived().TransformDecl(E->getLocStart(),
7781 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007782 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007783 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007784
Douglas Gregorb98b1992009-08-11 05:31:07 +00007785 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007786 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007787 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7788 &ArgumentChanged))
7789 return ExprError();
7790
Douglas Gregorb98b1992009-08-11 05:31:07 +00007791 if (!getDerived().AlwaysRebuild() &&
7792 T == E->getType() &&
7793 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007794 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007795 // Mark the constructor as referenced.
7796 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007797 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007798 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007799 }
Mike Stump1eb44332009-09-09 15:08:12 +00007800
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007801 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7802 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007803 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007804 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007805 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007806 E->getConstructionKind(),
7807 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007808}
Mike Stump1eb44332009-09-09 15:08:12 +00007809
Douglas Gregorb98b1992009-08-11 05:31:07 +00007810/// \brief Transform a C++ temporary-binding expression.
7811///
Douglas Gregor51326552009-12-24 18:51:59 +00007812/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7813/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007814template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007815ExprResult
John McCall454feb92009-12-08 09:21:05 +00007816TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007817 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007818}
Mike Stump1eb44332009-09-09 15:08:12 +00007819
John McCall4765fa02010-12-06 08:20:24 +00007820/// \brief Transform a C++ expression that contains cleanups that should
7821/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007822///
John McCall4765fa02010-12-06 08:20:24 +00007823/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007824/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007825template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007826ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007827TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007828 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007829}
Mike Stump1eb44332009-09-09 15:08:12 +00007830
Douglas Gregorb98b1992009-08-11 05:31:07 +00007831template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007832ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007833TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007834 CXXTemporaryObjectExpr *E) {
7835 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7836 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007837 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007838
Douglas Gregorb98b1992009-08-11 05:31:07 +00007839 CXXConstructorDecl *Constructor
7840 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007841 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007842 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007843 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007844 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007845
Douglas Gregorb98b1992009-08-11 05:31:07 +00007846 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007847 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007848 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007849 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7850 &ArgumentChanged))
7851 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007852
Douglas Gregorb98b1992009-08-11 05:31:07 +00007853 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007854 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007855 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007856 !ArgumentChanged) {
7857 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007858 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007859 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007860 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007861
7862 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7863 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007864 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007865 E->getLocEnd());
7866}
Mike Stump1eb44332009-09-09 15:08:12 +00007867
Douglas Gregorb98b1992009-08-11 05:31:07 +00007868template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007869ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007870TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007871 // Create the local class that will describe the lambda.
7872 CXXRecordDecl *Class
Douglas Gregorf54486a2012-04-04 17:40:10 +00007873 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7874 /*KnownDependent=*/false);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007875 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7876
7877 // Transform the type of the lambda parameters and start the definition of
7878 // the lambda itself.
7879 TypeSourceInfo *MethodTy
7880 = TransformType(E->getCallOperator()->getTypeSourceInfo());
7881 if (!MethodTy)
7882 return ExprError();
7883
Douglas Gregorc6889e72012-02-14 22:28:59 +00007884 // Transform lambda parameters.
7885 bool Invalid = false;
7886 llvm::SmallVector<QualType, 4> ParamTypes;
7887 llvm::SmallVector<ParmVarDecl *, 4> Params;
7888 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7889 E->getCallOperator()->param_begin(),
7890 E->getCallOperator()->param_size(),
7891 0, ParamTypes, &Params))
7892 Invalid = true;
7893
Douglas Gregordfca6f52012-02-13 22:00:16 +00007894 // Build the call operator.
Douglas Gregorf54486a2012-04-04 17:40:10 +00007895 // Note: Once a lambda mangling number and context declaration have been
7896 // assigned, they never change.
7897 unsigned ManglingNumber = E->getLambdaClass()->getLambdaManglingNumber();
7898 Decl *ContextDecl = E->getLambdaClass()->getLambdaContextDecl();
Douglas Gregordfca6f52012-02-13 22:00:16 +00007899 CXXMethodDecl *CallOperator
7900 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
7901 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007902 E->getCallOperator()->getLocEnd(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00007903 Params, ManglingNumber, ContextDecl);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007904 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
7905
Douglas Gregord5387e82012-02-14 00:00:48 +00007906 // FIXME: Instantiation-specific.
7907 CallOperator->setInstantiationOfMemberFunction(E->getCallOperator(),
7908 TSK_ImplicitInstantiation);
7909
7910 // Introduce the context of the call operator.
7911 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7912
Douglas Gregordfca6f52012-02-13 22:00:16 +00007913 // Enter the scope of the lambda.
7914 sema::LambdaScopeInfo *LSI
7915 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7916 E->getCaptureDefault(),
7917 E->hasExplicitParameters(),
7918 E->hasExplicitResultType(),
7919 E->isMutable());
7920
7921 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00007922 bool FinishedExplicitCaptures = false;
7923 for (LambdaExpr::capture_iterator C = E->capture_begin(),
7924 CEnd = E->capture_end();
7925 C != CEnd; ++C) {
7926 // When we hit the first implicit capture, tell Sema that we've finished
7927 // the list of explicit captures.
7928 if (!FinishedExplicitCaptures && C->isImplicit()) {
7929 getSema().finishLambdaExplicitCaptures(LSI);
7930 FinishedExplicitCaptures = true;
7931 }
7932
7933 // Capturing 'this' is trivial.
7934 if (C->capturesThis()) {
7935 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7936 continue;
7937 }
7938
Douglas Gregora7365242012-02-14 19:27:52 +00007939 // Determine the capture kind for Sema.
7940 Sema::TryCaptureKind Kind
7941 = C->isImplicit()? Sema::TryCapture_Implicit
7942 : C->getCaptureKind() == LCK_ByCopy
7943 ? Sema::TryCapture_ExplicitByVal
7944 : Sema::TryCapture_ExplicitByRef;
7945 SourceLocation EllipsisLoc;
7946 if (C->isPackExpansion()) {
7947 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7948 bool ShouldExpand = false;
7949 bool RetainExpansion = false;
7950 llvm::Optional<unsigned> NumExpansions;
7951 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7952 C->getLocation(),
7953 Unexpanded,
7954 ShouldExpand, RetainExpansion,
7955 NumExpansions))
7956 return ExprError();
7957
7958 if (ShouldExpand) {
7959 // The transform has determined that we should perform an expansion;
7960 // transform and capture each of the arguments.
7961 // expansion of the pattern. Do so.
7962 VarDecl *Pack = C->getCapturedVar();
7963 for (unsigned I = 0; I != *NumExpansions; ++I) {
7964 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7965 VarDecl *CapturedVar
7966 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7967 Pack));
7968 if (!CapturedVar) {
7969 Invalid = true;
7970 continue;
7971 }
7972
7973 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007974 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregora7365242012-02-14 19:27:52 +00007975 }
7976 continue;
7977 }
7978
7979 EllipsisLoc = C->getEllipsisLoc();
7980 }
7981
Douglas Gregordfca6f52012-02-13 22:00:16 +00007982 // Transform the captured variable.
7983 VarDecl *CapturedVar
7984 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7985 C->getCapturedVar()));
7986 if (!CapturedVar) {
7987 Invalid = true;
7988 continue;
7989 }
Douglas Gregora7365242012-02-14 19:27:52 +00007990
Douglas Gregordfca6f52012-02-13 22:00:16 +00007991 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007992 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007993 }
7994 if (!FinishedExplicitCaptures)
7995 getSema().finishLambdaExplicitCaptures(LSI);
7996
Douglas Gregordfca6f52012-02-13 22:00:16 +00007997
7998 // Enter a new evaluation context to insulate the lambda from any
7999 // cleanups from the enclosing full-expression.
8000 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
8001
8002 if (Invalid) {
8003 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
8004 /*IsInstantiation=*/true);
8005 return ExprError();
8006 }
8007
8008 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008009 StmtResult Body = getDerived().TransformStmt(E->getBody());
8010 if (Body.isInvalid()) {
8011 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
8012 /*IsInstantiation=*/true);
8013 return ExprError();
8014 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008015
Douglas Gregordfca6f52012-02-13 22:00:16 +00008016 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008017 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008018}
8019
8020template<typename Derived>
8021ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008022TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008023 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008024 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8025 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008026 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008027
Douglas Gregorb98b1992009-08-11 05:31:07 +00008028 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008029 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008030 Args.reserve(E->arg_size());
8031 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
8032 &ArgumentChanged))
8033 return ExprError();
8034
Douglas Gregorb98b1992009-08-11 05:31:07 +00008035 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008036 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008037 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008038 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008039
Douglas Gregorb98b1992009-08-11 05:31:07 +00008040 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008041 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008042 E->getLParenLoc(),
8043 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00008044 E->getRParenLoc());
8045}
Mike Stump1eb44332009-09-09 15:08:12 +00008046
Douglas Gregorb98b1992009-08-11 05:31:07 +00008047template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008048ExprResult
John McCall865d4472009-11-19 22:55:06 +00008049TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008050 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008051 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008052 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008053 Expr *OldBase;
8054 QualType BaseType;
8055 QualType ObjectType;
8056 if (!E->isImplicitAccess()) {
8057 OldBase = E->getBase();
8058 Base = getDerived().TransformExpr(OldBase);
8059 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008060 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008061
John McCallaa81e162009-12-01 22:10:20 +00008062 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008063 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008064 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008065 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008066 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008067 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008068 ObjectTy,
8069 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008070 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008071 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008072
John McCallb3d87482010-08-24 05:47:05 +00008073 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008074 BaseType = ((Expr*) Base.get())->getType();
8075 } else {
8076 OldBase = 0;
8077 BaseType = getDerived().TransformType(E->getBaseType());
8078 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8079 }
Mike Stump1eb44332009-09-09 15:08:12 +00008080
Douglas Gregor6cd21982009-10-20 05:58:46 +00008081 // Transform the first part of the nested-name-specifier that qualifies
8082 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008083 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008084 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008085 E->getFirstQualifierFoundInScope(),
8086 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008087
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008088 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008089 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008090 QualifierLoc
8091 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8092 ObjectType,
8093 FirstQualifierInScope);
8094 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008095 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008096 }
Mike Stump1eb44332009-09-09 15:08:12 +00008097
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008098 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8099
John McCall43fed0d2010-11-12 08:19:04 +00008100 // TODO: If this is a conversion-function-id, verify that the
8101 // destination type name (if present) resolves the same way after
8102 // instantiation as it did in the local scope.
8103
Abramo Bagnara25777432010-08-11 22:01:17 +00008104 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008105 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008106 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008107 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008108
John McCallaa81e162009-12-01 22:10:20 +00008109 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008110 // This is a reference to a member without an explicitly-specified
8111 // template argument list. Optimize for this common case.
8112 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008113 Base.get() == OldBase &&
8114 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008115 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008116 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008117 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008118 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008119
John McCall9ae2f072010-08-23 23:25:46 +00008120 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008121 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008122 E->isArrow(),
8123 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008124 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008125 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008126 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008127 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008128 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008129 }
8130
John McCalld5532b62009-11-23 01:53:49 +00008131 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008132 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8133 E->getNumTemplateArgs(),
8134 TransArgs))
8135 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008136
John McCall9ae2f072010-08-23 23:25:46 +00008137 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008138 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008139 E->isArrow(),
8140 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008141 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008142 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008143 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008144 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008145 &TransArgs);
8146}
8147
8148template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008149ExprResult
John McCall454feb92009-12-08 09:21:05 +00008150TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008151 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008152 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008153 QualType BaseType;
8154 if (!Old->isImplicitAccess()) {
8155 Base = getDerived().TransformExpr(Old->getBase());
8156 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008157 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008158 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8159 Old->isArrow());
8160 if (Base.isInvalid())
8161 return ExprError();
8162 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008163 } else {
8164 BaseType = getDerived().TransformType(Old->getBaseType());
8165 }
John McCall129e2df2009-11-30 22:42:35 +00008166
Douglas Gregor4c9be892011-02-28 20:01:57 +00008167 NestedNameSpecifierLoc QualifierLoc;
8168 if (Old->getQualifierLoc()) {
8169 QualifierLoc
8170 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8171 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008172 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008173 }
8174
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008175 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8176
Abramo Bagnara25777432010-08-11 22:01:17 +00008177 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008178 Sema::LookupOrdinaryName);
8179
8180 // Transform all the decls.
8181 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8182 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008183 NamedDecl *InstD = static_cast<NamedDecl*>(
8184 getDerived().TransformDecl(Old->getMemberLoc(),
8185 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008186 if (!InstD) {
8187 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8188 // This can happen because of dependent hiding.
8189 if (isa<UsingShadowDecl>(*I))
8190 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008191 else {
8192 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008193 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008194 }
John McCall9f54ad42009-12-10 09:41:52 +00008195 }
John McCall129e2df2009-11-30 22:42:35 +00008196
8197 // Expand using declarations.
8198 if (isa<UsingDecl>(InstD)) {
8199 UsingDecl *UD = cast<UsingDecl>(InstD);
8200 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8201 E = UD->shadow_end(); I != E; ++I)
8202 R.addDecl(*I);
8203 continue;
8204 }
8205
8206 R.addDecl(InstD);
8207 }
8208
8209 R.resolveKind();
8210
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008211 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008212 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00008213 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008214 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008215 Old->getMemberLoc(),
8216 Old->getNamingClass()));
8217 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008218 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008219
Douglas Gregor66c45152010-04-27 16:10:10 +00008220 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008221 }
Sean Huntc3021132010-05-05 15:23:54 +00008222
John McCall129e2df2009-11-30 22:42:35 +00008223 TemplateArgumentListInfo TransArgs;
8224 if (Old->hasExplicitTemplateArgs()) {
8225 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8226 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008227 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8228 Old->getNumTemplateArgs(),
8229 TransArgs))
8230 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008231 }
John McCallc2233c52010-01-15 08:34:02 +00008232
8233 // FIXME: to do this check properly, we will need to preserve the
8234 // first-qualifier-in-scope here, just in case we had a dependent
8235 // base (and therefore couldn't do the check) and a
8236 // nested-name-qualifier (and therefore could do the lookup).
8237 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00008238
John McCall9ae2f072010-08-23 23:25:46 +00008239 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008240 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008241 Old->getOperatorLoc(),
8242 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008243 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008244 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008245 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008246 R,
8247 (Old->hasExplicitTemplateArgs()
8248 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008249}
8250
8251template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008252ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008253TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008254 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008255 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8256 if (SubExpr.isInvalid())
8257 return ExprError();
8258
8259 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008260 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008261
8262 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8263}
8264
8265template<typename Derived>
8266ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008267TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008268 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8269 if (Pattern.isInvalid())
8270 return ExprError();
8271
8272 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8273 return SemaRef.Owned(E);
8274
Douglas Gregor67fd1252011-01-14 21:20:45 +00008275 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8276 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008277}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008278
8279template<typename Derived>
8280ExprResult
8281TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8282 // If E is not value-dependent, then nothing will change when we transform it.
8283 // Note: This is an instantiation-centric view.
8284 if (!E->isValueDependent())
8285 return SemaRef.Owned(E);
8286
8287 // Note: None of the implementations of TryExpandParameterPacks can ever
8288 // produce a diagnostic when given only a single unexpanded parameter pack,
8289 // so
8290 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8291 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008292 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008293 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00008294 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008295 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008296 ShouldExpand, RetainExpansion,
8297 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008298 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00008299
Douglas Gregor089e8932011-10-10 18:59:29 +00008300 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008301 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00008302
8303 NamedDecl *Pack = E->getPack();
8304 if (!ShouldExpand) {
8305 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
8306 Pack));
8307 if (!Pack)
8308 return ExprError();
8309 }
8310
Douglas Gregoree8aff02011-01-04 17:33:58 +00008311
8312 // We now know the length of the parameter pack, so build a new expression
8313 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00008314 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00008315 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008316 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008317}
8318
Douglas Gregorbe230c32011-01-03 17:17:50 +00008319template<typename Derived>
8320ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008321TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8322 SubstNonTypeTemplateParmPackExpr *E) {
8323 // Default behavior is to do nothing with this transformation.
8324 return SemaRef.Owned(E);
8325}
8326
8327template<typename Derived>
8328ExprResult
John McCall91a57552011-07-15 05:09:51 +00008329TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8330 SubstNonTypeTemplateParmExpr *E) {
8331 // Default behavior is to do nothing with this transformation.
8332 return SemaRef.Owned(E);
8333}
8334
8335template<typename Derived>
8336ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008337TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8338 MaterializeTemporaryExpr *E) {
8339 return getDerived().TransformExpr(E->GetTemporaryExpr());
8340}
8341
8342template<typename Derived>
8343ExprResult
John McCall454feb92009-12-08 09:21:05 +00008344TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008345 return SemaRef.MaybeBindToTemporary(E);
8346}
8347
8348template<typename Derived>
8349ExprResult
8350TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008351 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008352}
8353
8354template<typename Derived>
8355ExprResult
8356TreeTransform<Derived>::TransformObjCNumericLiteral(ObjCNumericLiteral *E) {
8357 return SemaRef.MaybeBindToTemporary(E);
8358}
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;
8366 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
8367 /*IsCall=*/false, Elements, &ArgChanged))
8368 return ExprError();
8369
8370 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8371 return SemaRef.MaybeBindToTemporary(E);
8372
8373 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8374 Elements.data(),
8375 Elements.size());
8376}
8377
8378template<typename Derived>
8379ExprResult
8380TreeTransform<Derived>::TransformObjCDictionaryLiteral(
8381 ObjCDictionaryLiteral *E) {
8382 // 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);
8387
8388 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
8412 // transformation on the pack expansion, producing another pack
8413 // 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();
8425
8426 if (Value.get() != OrigElement.Value)
8427 ArgChanged = true;
8428
8429 ObjCDictionaryElement Expansion = {
8430 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;
8439
8440 // 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
8452 ObjCDictionaryElement Element = {
8453 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;
8461
8462 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();
8473
8474 if (Key.get() != OrigElement.Key)
8475 ArgChanged = true;
8476
8477 // Transform and check value.
8478 ExprResult Value
8479 = getDerived().TransformExpr(OrigElement.Value);
8480 if (Value.isInvalid())
8481 return ExprError();
8482
8483 if (Value.get() != OrigElement.Value)
8484 ArgChanged = true;
8485
8486 ObjCDictionaryElement Element = {
8487 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8488 };
8489 Elements.push_back(Element);
8490 }
8491
8492 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) {
8535 TypeSourceInfo *TSInfo
8536 = getDerived().TransformType(E->getTypeInfoAsWritten());
8537 if (!TSInfo)
8538 return ExprError();
8539
8540 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
8541 if (Result.isInvalid())
8542 return ExprError();
8543
8544 if (!getDerived().AlwaysRebuild() &&
8545 TSInfo == E->getTypeInfoAsWritten() &&
8546 Result.get() == E->getSubExpr())
8547 return SemaRef.Owned(E);
8548
8549 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
8550 E->getBridgeKeywordLoc(), TSInfo,
8551 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;
John McCallca0408f2010-08-23 06:44:23 +00008559 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008560 Args.reserve(E->getNumArgs());
8561 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
8562 &ArgChanged))
8563 return ExprError();
8564
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();
Sean Huntc3021132010-05-05 15:23:54 +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(),
8585 move_arg(Args),
8586 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);
Sean Huntc3021132010-05-05 15:23:54 +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(),
8610 move_arg(Args),
8611 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.
Sean Huntc3021132010-05-05 15:23:54 +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);
Sean Huntc3021132010-05-05 15:23:54 +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);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +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();
Sean Huntc3021132010-05-05 15:23:54 +00008658
Douglas Gregore3303542010-04-26 20:47:02 +00008659 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +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
8696 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
8697 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();
Sean Huntc3021132010-05-05 15:23:54 +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);
Sean Huntc3021132010-05-05 15:23:54 +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;
John McCallca0408f2010-08-23 06:44:23 +00008723 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008724 SubExprs.reserve(E->getNumSubExprs());
8725 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8726 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(),
8734 move_arg(SubExprs),
8735 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();
Fariborz Jahaniana729da22010-07-09 18:44:02 +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());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008749
Chris Lattner686775d2011-07-20 06:58:45 +00008750 SmallVector<ParmVarDecl*, 4> params;
8751 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008752
8753 // 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()) {
John McCallc6ac9c32011-02-04 18:33:18 +00008768 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008769 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 }
Douglas Gregora779d9c2011-01-19 21:32:01 +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;
8837 ASTOwningVector<Expr*> SubExprs(SemaRef);
8838 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
8847 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8848 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008849}
Tanya Lattner61eee0c2011-06-04 00:47:47 +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());
Sean Huntc3021132010-05-05 15:23:54 +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}
Sean Huntc3021132010-05-05 15:23:54 +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
Douglas Gregorb98b1992009-08-11 05:31:07 +00009168 return move(Result);
9169 }
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 {
John McCall9ae2f072010-08-23 23:25:46 +00009183 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00009184 }
Mike Stump1eb44332009-09-09 15:08:12 +00009185
Douglas Gregorb98b1992009-08-11 05:31:07 +00009186 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009187 Expr *Args[2] = { First, Second };
9188 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009189
Douglas Gregorb98b1992009-08-11 05:31:07 +00009190 // Create the overloaded operator invocation for unary operators.
9191 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009192 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009193 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009194 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009195 }
Mike Stump1eb44332009-09-09 15:08:12 +00009196
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009197 if (Op == OO_Subscript) {
9198 SourceLocation LBrace;
9199 SourceLocation RBrace;
9200
9201 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9202 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9203 LBrace = SourceLocation::getFromRawEncoding(
9204 NameLoc.CXXOperatorName.BeginOpNameLoc);
9205 RBrace = SourceLocation::getFromRawEncoding(
9206 NameLoc.CXXOperatorName.EndOpNameLoc);
9207 } else {
9208 LBrace = Callee->getLocStart();
9209 RBrace = OpLoc;
9210 }
9211
9212 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9213 First, Second);
9214 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009215
Douglas Gregorb98b1992009-08-11 05:31:07 +00009216 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009217 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009218 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009219 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9220 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009221 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009222
Mike Stump1eb44332009-09-09 15:08:12 +00009223 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009224}
Mike Stump1eb44332009-09-09 15:08:12 +00009225
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009226template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009227ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009228TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009229 SourceLocation OperatorLoc,
9230 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009231 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009232 TypeSourceInfo *ScopeType,
9233 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009234 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009235 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009236 QualType BaseType = Base->getType();
9237 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009238 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00009239 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009240 !BaseType->getAs<PointerType>()->getPointeeType()
9241 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009242 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009243 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009244 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009245 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009246 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009247 /*FIXME?*/true);
9248 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009249
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009250 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009251 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9252 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9253 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9254 NameInfo.setNamedTypeInfo(DestroyedType);
9255
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009256 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00009257
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009258 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009259 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009260 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009261 SS, TemplateKWLoc,
9262 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009263 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009264 /*TemplateArgs*/ 0);
9265}
9266
Douglas Gregor577f75a2009-08-04 16:50:30 +00009267} // end namespace clang
9268
9269#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H