blob: 7387eac667ba25db736dbbd4e1c781e5c15f630d [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
Patrick Beardeb382ec2012-04-19 00:25:12 +00002228 /// \brief Build a new Objective-C boxed expression.
2229 ///
2230 /// By default, performs semantic analysis to build the new expression.
2231 /// Subclasses may override this routine to provide different behavior.
2232 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2233 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2234 }
2235
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002236 /// \brief Build a new Objective-C array literal.
2237 ///
2238 /// By default, performs semantic analysis to build the new expression.
2239 /// Subclasses may override this routine to provide different behavior.
2240 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2241 Expr **Elements, unsigned NumElements) {
2242 return getSema().BuildObjCArrayLiteral(Range,
2243 MultiExprArg(Elements, NumElements));
2244 }
2245
2246 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
2247 Expr *Base, Expr *Key,
2248 ObjCMethodDecl *getterMethod,
2249 ObjCMethodDecl *setterMethod) {
2250 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2251 getterMethod, setterMethod);
2252 }
2253
2254 /// \brief Build a new Objective-C dictionary literal.
2255 ///
2256 /// By default, performs semantic analysis to build the new expression.
2257 /// Subclasses may override this routine to provide different behavior.
2258 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2259 ObjCDictionaryElement *Elements,
2260 unsigned NumElements) {
2261 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2262 }
2263
Douglas Gregorb98b1992009-08-11 05:31:07 +00002264 /// \brief Build a new Objective-C @encode expression.
2265 ///
2266 /// By default, performs semantic analysis to build the new expression.
2267 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002268 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002269 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002270 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002271 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002272 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002273 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002274
Douglas Gregor92e986e2010-04-22 16:44:27 +00002275 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002276 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002277 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002278 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002279 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002280 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002281 MultiExprArg Args,
2282 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002283 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2284 ReceiverTypeInfo->getType(),
2285 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002286 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002287 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002288 }
2289
2290 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002291 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002292 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002293 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002294 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002295 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002296 MultiExprArg Args,
2297 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002298 return SemaRef.BuildInstanceMessage(Receiver,
2299 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002300 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002301 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002302 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002303 }
2304
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002305 /// \brief Build a new Objective-C ivar reference expression.
2306 ///
2307 /// By default, performs semantic analysis to build the new expression.
2308 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002309 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002310 SourceLocation IvarLoc,
2311 bool IsArrow, bool IsFreeIvar) {
2312 // FIXME: We lose track of the IsFreeIvar bit.
2313 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002314 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002315 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2316 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002317 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002318 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002319 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002320 false);
John Wiegley429bb272011-04-08 18:41:53 +00002321 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002322 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002323
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002324 if (Result.get())
2325 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002326
John Wiegley429bb272011-04-08 18:41:53 +00002327 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002328 /*FIXME:*/IvarLoc, IsArrow,
2329 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002330 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002331 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002332 /*TemplateArgs=*/0);
2333 }
Douglas Gregore3303542010-04-26 20:47:02 +00002334
2335 /// \brief Build a new Objective-C property reference expression.
2336 ///
2337 /// By default, performs semantic analysis to build the new expression.
2338 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002339 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002340 ObjCPropertyDecl *Property,
2341 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002342 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002343 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002344 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2345 Sema::LookupMemberName);
2346 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002347 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002348 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002349 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002350 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002351 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002352
Douglas Gregore3303542010-04-26 20:47:02 +00002353 if (Result.get())
2354 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002355
John Wiegley429bb272011-04-08 18:41:53 +00002356 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002357 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002358 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002359 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002360 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002361 /*TemplateArgs=*/0);
2362 }
Sean Huntc3021132010-05-05 15:23:54 +00002363
John McCall12f78a62010-12-02 01:19:52 +00002364 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002365 ///
2366 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002367 /// Subclasses may override this routine to provide different behavior.
2368 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2369 ObjCMethodDecl *Getter,
2370 ObjCMethodDecl *Setter,
2371 SourceLocation PropertyLoc) {
2372 // Since these expressions can only be value-dependent, we do not
2373 // need to perform semantic analysis again.
2374 return Owned(
2375 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2376 VK_LValue, OK_ObjCProperty,
2377 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002378 }
2379
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002380 /// \brief Build a new Objective-C "isa" expression.
2381 ///
2382 /// By default, performs semantic analysis to build the new expression.
2383 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002384 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002385 bool IsArrow) {
2386 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002387 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002388 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2389 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002390 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002391 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002392 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002393 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002394 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002395
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002396 if (Result.get())
2397 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002398
John Wiegley429bb272011-04-08 18:41:53 +00002399 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002400 /*FIXME:*/IsaLoc, IsArrow,
2401 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002402 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002403 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002404 /*TemplateArgs=*/0);
2405 }
Sean Huntc3021132010-05-05 15:23:54 +00002406
Douglas Gregorb98b1992009-08-11 05:31:07 +00002407 /// \brief Build a new shuffle vector expression.
2408 ///
2409 /// By default, performs semantic analysis to build the new expression.
2410 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002411 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002412 MultiExprArg SubExprs,
2413 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002414 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002415 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002416 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2417 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2418 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2419 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002420
Douglas Gregorb98b1992009-08-11 05:31:07 +00002421 // Build a reference to the __builtin_shufflevector builtin
2422 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002423 ExprResult Callee
John McCallf4b88a42012-03-10 09:33:50 +00002424 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false,
2425 Builtin->getType(),
John Wiegley429bb272011-04-08 18:41:53 +00002426 VK_LValue, BuiltinLoc));
2427 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2428 if (Callee.isInvalid())
2429 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002430
2431 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002432 unsigned NumSubExprs = SubExprs.size();
2433 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002434 ExprResult TheCall = SemaRef.Owned(
2435 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002436 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002437 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002438 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002439 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002440
Douglas Gregorb98b1992009-08-11 05:31:07 +00002441 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002442 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002443 }
John McCall43fed0d2010-11-12 08:19:04 +00002444
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002445 /// \brief Build a new template argument pack expansion.
2446 ///
2447 /// By default, performs semantic analysis to build a new pack expansion
2448 /// for a template argument. Subclasses may override this routine to provide
2449 /// different behavior.
2450 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002451 SourceLocation EllipsisLoc,
2452 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002453 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002454 case TemplateArgument::Expression: {
2455 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002456 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2457 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002458 if (Result.isInvalid())
2459 return TemplateArgumentLoc();
2460
2461 return TemplateArgumentLoc(Result.get(), Result.get());
2462 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002463
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002464 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002465 return TemplateArgumentLoc(TemplateArgument(
2466 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002467 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002468 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002469 Pattern.getTemplateNameLoc(),
2470 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002471
2472 case TemplateArgument::Null:
2473 case TemplateArgument::Integral:
2474 case TemplateArgument::Declaration:
2475 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002476 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002477 llvm_unreachable("Pack expansion pattern has no parameter packs");
2478
2479 case TemplateArgument::Type:
2480 if (TypeSourceInfo *Expansion
2481 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002482 EllipsisLoc,
2483 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002484 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2485 Expansion);
2486 break;
2487 }
2488
2489 return TemplateArgumentLoc();
2490 }
2491
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002492 /// \brief Build a new expression pack expansion.
2493 ///
2494 /// By default, performs semantic analysis to build a new pack expansion
2495 /// for an expression. Subclasses may override this routine to provide
2496 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002497 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2498 llvm::Optional<unsigned> NumExpansions) {
2499 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002500 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002501
2502 /// \brief Build a new atomic operation expression.
2503 ///
2504 /// By default, performs semantic analysis to build the new expression.
2505 /// Subclasses may override this routine to provide different behavior.
2506 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2507 MultiExprArg SubExprs,
2508 QualType RetTy,
2509 AtomicExpr::AtomicOp Op,
2510 SourceLocation RParenLoc) {
2511 // Just create the expression; there is not any interesting semantic
2512 // analysis here because we can't actually build an AtomicExpr until
2513 // we are sure it is semantically sound.
2514 unsigned NumSubExprs = SubExprs.size();
2515 Expr **Subs = (Expr **)SubExprs.release();
2516 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2517 NumSubExprs, RetTy, Op,
2518 RParenLoc);
2519 }
2520
John McCall43fed0d2010-11-12 08:19:04 +00002521private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002522 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2523 QualType ObjectType,
2524 NamedDecl *FirstQualifierInScope,
2525 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002526
2527 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2528 QualType ObjectType,
2529 NamedDecl *FirstQualifierInScope,
2530 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002531};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002532
Douglas Gregor43959a92009-08-20 07:17:43 +00002533template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002534StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002535 if (!S)
2536 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002537
Douglas Gregor43959a92009-08-20 07:17:43 +00002538 switch (S->getStmtClass()) {
2539 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002540
Douglas Gregor43959a92009-08-20 07:17:43 +00002541 // Transform individual statement nodes
2542#define STMT(Node, Parent) \
2543 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002544#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002545#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002546#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002547
Douglas Gregor43959a92009-08-20 07:17:43 +00002548 // Transform expressions by calling TransformExpr.
2549#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002550#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002551#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002552#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002553 {
John McCall60d7b3a2010-08-24 06:29:42 +00002554 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002555 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002556 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002557
John McCall9ae2f072010-08-23 23:25:46 +00002558 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002559 }
Mike Stump1eb44332009-09-09 15:08:12 +00002560 }
2561
John McCall3fa5cae2010-10-26 07:05:15 +00002562 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002563}
Mike Stump1eb44332009-09-09 15:08:12 +00002564
2565
Douglas Gregor670444e2009-08-04 22:27:00 +00002566template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002567ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002568 if (!E)
2569 return SemaRef.Owned(E);
2570
2571 switch (E->getStmtClass()) {
2572 case Stmt::NoStmtClass: break;
2573#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002574#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002575#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002576 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002577#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002578 }
2579
John McCall3fa5cae2010-10-26 07:05:15 +00002580 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002581}
2582
2583template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002584bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2585 unsigned NumInputs,
2586 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002587 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002588 bool *ArgChanged) {
2589 for (unsigned I = 0; I != NumInputs; ++I) {
2590 // If requested, drop call arguments that need to be dropped.
2591 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2592 if (ArgChanged)
2593 *ArgChanged = true;
2594
2595 break;
2596 }
2597
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002598 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2599 Expr *Pattern = Expansion->getPattern();
2600
Chris Lattner686775d2011-07-20 06:58:45 +00002601 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002602 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2603 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2604
2605 // Determine whether the set of unexpanded parameter packs can and should
2606 // be expanded.
2607 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002608 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002609 llvm::Optional<unsigned> OrigNumExpansions
2610 = Expansion->getNumExpansions();
2611 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002612 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2613 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002614 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002615 Expand, RetainExpansion,
2616 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002617 return true;
2618
2619 if (!Expand) {
2620 // The transform has determined that we should perform a simple
2621 // transformation on the pack expansion, producing another pack
2622 // expansion.
2623 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2624 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2625 if (OutPattern.isInvalid())
2626 return true;
2627
2628 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002629 Expansion->getEllipsisLoc(),
2630 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002631 if (Out.isInvalid())
2632 return true;
2633
2634 if (ArgChanged)
2635 *ArgChanged = true;
2636 Outputs.push_back(Out.get());
2637 continue;
2638 }
John McCallc8fc90a2011-07-06 07:30:07 +00002639
2640 // Record right away that the argument was changed. This needs
2641 // to happen even if the array expands to nothing.
2642 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002643
2644 // The transform has determined that we should perform an elementwise
2645 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002646 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002647 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2648 ExprResult Out = getDerived().TransformExpr(Pattern);
2649 if (Out.isInvalid())
2650 return true;
2651
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002652 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002653 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2654 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002655 if (Out.isInvalid())
2656 return true;
2657 }
2658
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002659 Outputs.push_back(Out.get());
2660 }
2661
2662 continue;
2663 }
2664
Douglas Gregoraa165f82011-01-03 19:04:46 +00002665 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2666 if (Result.isInvalid())
2667 return true;
2668
2669 if (Result.get() != Inputs[I] && ArgChanged)
2670 *ArgChanged = true;
2671
2672 Outputs.push_back(Result.get());
2673 }
2674
2675 return false;
2676}
2677
2678template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002679NestedNameSpecifierLoc
2680TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2681 NestedNameSpecifierLoc NNS,
2682 QualType ObjectType,
2683 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002684 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002685 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2686 Qualifier = Qualifier.getPrefix())
2687 Qualifiers.push_back(Qualifier);
2688
2689 CXXScopeSpec SS;
2690 while (!Qualifiers.empty()) {
2691 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2692 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2693
2694 switch (QNNS->getKind()) {
2695 case NestedNameSpecifier::Identifier:
2696 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2697 *QNNS->getAsIdentifier(),
2698 Q.getLocalBeginLoc(),
2699 Q.getLocalEndLoc(),
2700 ObjectType, false, SS,
2701 FirstQualifierInScope, false))
2702 return NestedNameSpecifierLoc();
2703
2704 break;
2705
2706 case NestedNameSpecifier::Namespace: {
2707 NamespaceDecl *NS
2708 = cast_or_null<NamespaceDecl>(
2709 getDerived().TransformDecl(
2710 Q.getLocalBeginLoc(),
2711 QNNS->getAsNamespace()));
2712 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2713 break;
2714 }
2715
2716 case NestedNameSpecifier::NamespaceAlias: {
2717 NamespaceAliasDecl *Alias
2718 = cast_or_null<NamespaceAliasDecl>(
2719 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2720 QNNS->getAsNamespaceAlias()));
2721 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2722 Q.getLocalEndLoc());
2723 break;
2724 }
2725
2726 case NestedNameSpecifier::Global:
2727 // There is no meaningful transformation that one could perform on the
2728 // global scope.
2729 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2730 break;
2731
2732 case NestedNameSpecifier::TypeSpecWithTemplate:
2733 case NestedNameSpecifier::TypeSpec: {
2734 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2735 FirstQualifierInScope, SS);
2736
2737 if (!TL)
2738 return NestedNameSpecifierLoc();
2739
2740 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
David Blaikie4e4d0842012-03-11 07:00:24 +00002741 (SemaRef.getLangOpts().CPlusPlus0x &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002742 TL.getType()->isEnumeralType())) {
2743 assert(!TL.getType().hasLocalQualifiers() &&
2744 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002745 if (TL.getType()->isEnumeralType())
2746 SemaRef.Diag(TL.getBeginLoc(),
2747 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002748 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2749 Q.getLocalEndLoc());
2750 break;
2751 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002752 // If the nested-name-specifier is an invalid type def, don't emit an
2753 // error because a previous error should have already been emitted.
2754 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2755 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2756 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2757 << TL.getType() << SS.getRange();
2758 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002759 return NestedNameSpecifierLoc();
2760 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002761 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002762
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002763 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002764 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002765 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002766 }
2767
2768 // Don't rebuild the nested-name-specifier if we don't have to.
2769 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2770 !getDerived().AlwaysRebuild())
2771 return NNS;
2772
2773 // If we can re-use the source-location data from the original
2774 // nested-name-specifier, do so.
2775 if (SS.location_size() == NNS.getDataLength() &&
2776 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2777 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2778
2779 // Allocate new nested-name-specifier location information.
2780 return SS.getWithLocInContext(SemaRef.Context);
2781}
2782
2783template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002784DeclarationNameInfo
2785TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002786::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002787 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002788 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002789 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002790
2791 switch (Name.getNameKind()) {
2792 case DeclarationName::Identifier:
2793 case DeclarationName::ObjCZeroArgSelector:
2794 case DeclarationName::ObjCOneArgSelector:
2795 case DeclarationName::ObjCMultiArgSelector:
2796 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002797 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002798 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002799 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002800
Douglas Gregor81499bb2009-09-03 22:13:48 +00002801 case DeclarationName::CXXConstructorName:
2802 case DeclarationName::CXXDestructorName:
2803 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002804 TypeSourceInfo *NewTInfo;
2805 CanQualType NewCanTy;
2806 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002807 NewTInfo = getDerived().TransformType(OldTInfo);
2808 if (!NewTInfo)
2809 return DeclarationNameInfo();
2810 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002811 }
2812 else {
2813 NewTInfo = 0;
2814 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002815 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002816 if (NewT.isNull())
2817 return DeclarationNameInfo();
2818 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2819 }
Mike Stump1eb44332009-09-09 15:08:12 +00002820
Abramo Bagnara25777432010-08-11 22:01:17 +00002821 DeclarationName NewName
2822 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2823 NewCanTy);
2824 DeclarationNameInfo NewNameInfo(NameInfo);
2825 NewNameInfo.setName(NewName);
2826 NewNameInfo.setNamedTypeInfo(NewTInfo);
2827 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002828 }
Mike Stump1eb44332009-09-09 15:08:12 +00002829 }
2830
David Blaikieb219cfc2011-09-23 05:06:16 +00002831 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002832}
2833
2834template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002835TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002836TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2837 TemplateName Name,
2838 SourceLocation NameLoc,
2839 QualType ObjectType,
2840 NamedDecl *FirstQualifierInScope) {
2841 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2842 TemplateDecl *Template = QTN->getTemplateDecl();
2843 assert(Template && "qualified template name must refer to a template");
2844
2845 TemplateDecl *TransTemplate
2846 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2847 Template));
2848 if (!TransTemplate)
2849 return TemplateName();
2850
2851 if (!getDerived().AlwaysRebuild() &&
2852 SS.getScopeRep() == QTN->getQualifier() &&
2853 TransTemplate == Template)
2854 return Name;
2855
2856 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2857 TransTemplate);
2858 }
2859
2860 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2861 if (SS.getScopeRep()) {
2862 // These apply to the scope specifier, not the template.
2863 ObjectType = QualType();
2864 FirstQualifierInScope = 0;
2865 }
2866
2867 if (!getDerived().AlwaysRebuild() &&
2868 SS.getScopeRep() == DTN->getQualifier() &&
2869 ObjectType.isNull())
2870 return Name;
2871
2872 if (DTN->isIdentifier()) {
2873 return getDerived().RebuildTemplateName(SS,
2874 *DTN->getIdentifier(),
2875 NameLoc,
2876 ObjectType,
2877 FirstQualifierInScope);
2878 }
2879
2880 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2881 ObjectType);
2882 }
2883
2884 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2885 TemplateDecl *TransTemplate
2886 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2887 Template));
2888 if (!TransTemplate)
2889 return TemplateName();
2890
2891 if (!getDerived().AlwaysRebuild() &&
2892 TransTemplate == Template)
2893 return Name;
2894
2895 return TemplateName(TransTemplate);
2896 }
2897
2898 if (SubstTemplateTemplateParmPackStorage *SubstPack
2899 = Name.getAsSubstTemplateTemplateParmPack()) {
2900 TemplateTemplateParmDecl *TransParam
2901 = cast_or_null<TemplateTemplateParmDecl>(
2902 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2903 if (!TransParam)
2904 return TemplateName();
2905
2906 if (!getDerived().AlwaysRebuild() &&
2907 TransParam == SubstPack->getParameterPack())
2908 return Name;
2909
2910 return getDerived().RebuildTemplateName(TransParam,
2911 SubstPack->getArgumentPack());
2912 }
2913
2914 // These should be getting filtered out before they reach the AST.
2915 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002916}
2917
2918template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002919void TreeTransform<Derived>::InventTemplateArgumentLoc(
2920 const TemplateArgument &Arg,
2921 TemplateArgumentLoc &Output) {
2922 SourceLocation Loc = getDerived().getBaseLocation();
2923 switch (Arg.getKind()) {
2924 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002925 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002926 break;
2927
2928 case TemplateArgument::Type:
2929 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002930 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002931
John McCall833ca992009-10-29 08:12:44 +00002932 break;
2933
Douglas Gregor788cd062009-11-11 01:00:40 +00002934 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002935 case TemplateArgument::TemplateExpansion: {
2936 NestedNameSpecifierLocBuilder Builder;
2937 TemplateName Template = Arg.getAsTemplate();
2938 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2939 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2940 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2941 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2942
2943 if (Arg.getKind() == TemplateArgument::Template)
2944 Output = TemplateArgumentLoc(Arg,
2945 Builder.getWithLocInContext(SemaRef.Context),
2946 Loc);
2947 else
2948 Output = TemplateArgumentLoc(Arg,
2949 Builder.getWithLocInContext(SemaRef.Context),
2950 Loc, Loc);
2951
Douglas Gregor788cd062009-11-11 01:00:40 +00002952 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002953 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002954
John McCall833ca992009-10-29 08:12:44 +00002955 case TemplateArgument::Expression:
2956 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2957 break;
2958
2959 case TemplateArgument::Declaration:
2960 case TemplateArgument::Integral:
2961 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002962 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002963 break;
2964 }
2965}
2966
2967template<typename Derived>
2968bool TreeTransform<Derived>::TransformTemplateArgument(
2969 const TemplateArgumentLoc &Input,
2970 TemplateArgumentLoc &Output) {
2971 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002972 switch (Arg.getKind()) {
2973 case TemplateArgument::Null:
2974 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002975 Output = Input;
2976 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002977
Douglas Gregor670444e2009-08-04 22:27:00 +00002978 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002979 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002980 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002981 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002982
2983 DI = getDerived().TransformType(DI);
2984 if (!DI) return true;
2985
2986 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2987 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002988 }
Mike Stump1eb44332009-09-09 15:08:12 +00002989
Douglas Gregor670444e2009-08-04 22:27:00 +00002990 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002991 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002992 DeclarationName Name;
2993 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2994 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002995 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002996 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002997 if (!D) return true;
2998
John McCall828bff22009-10-29 18:45:58 +00002999 Expr *SourceExpr = Input.getSourceDeclExpression();
3000 if (SourceExpr) {
3001 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003002 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00003003 ExprResult E = getDerived().TransformExpr(SourceExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003004 E = SemaRef.ActOnConstantExpression(E);
John McCall9ae2f072010-08-23 23:25:46 +00003005 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00003006 }
3007
3008 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00003009 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003010 }
Mike Stump1eb44332009-09-09 15:08:12 +00003011
Douglas Gregor788cd062009-11-11 01:00:40 +00003012 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003013 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3014 if (QualifierLoc) {
3015 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3016 if (!QualifierLoc)
3017 return true;
3018 }
3019
Douglas Gregor1d752d72011-03-02 18:46:51 +00003020 CXXScopeSpec SS;
3021 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003022 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003023 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3024 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003025 if (Template.isNull())
3026 return true;
Sean Huntc3021132010-05-05 15:23:54 +00003027
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003028 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003029 Input.getTemplateNameLoc());
3030 return false;
3031 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003032
3033 case TemplateArgument::TemplateExpansion:
3034 llvm_unreachable("Caller should expand pack expansions");
3035
Douglas Gregor670444e2009-08-04 22:27:00 +00003036 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003037 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003038 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003039 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003040
John McCall833ca992009-10-29 08:12:44 +00003041 Expr *InputExpr = Input.getSourceExpression();
3042 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3043
Chris Lattner223de242011-04-25 20:37:58 +00003044 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003045 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003046 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003047 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003048 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003049 }
Mike Stump1eb44332009-09-09 15:08:12 +00003050
Douglas Gregor670444e2009-08-04 22:27:00 +00003051 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00003052 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00003053 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00003054 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00003055 AEnd = Arg.pack_end();
3056 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00003057
John McCall833ca992009-10-29 08:12:44 +00003058 // FIXME: preserve source information here when we start
3059 // caring about parameter packs.
3060
John McCall828bff22009-10-29 18:45:58 +00003061 TemplateArgumentLoc InputArg;
3062 TemplateArgumentLoc OutputArg;
3063 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3064 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00003065 return true;
3066
John McCall828bff22009-10-29 18:45:58 +00003067 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00003068 }
Douglas Gregor910f8002010-11-07 23:05:16 +00003069
3070 TemplateArgument *TransformedArgsPtr
3071 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3072 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3073 TransformedArgsPtr);
3074 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3075 TransformedArgs.size()),
3076 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003077 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003078 }
3079 }
Mike Stump1eb44332009-09-09 15:08:12 +00003080
Douglas Gregor670444e2009-08-04 22:27:00 +00003081 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003082 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003083}
3084
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003085/// \brief Iterator adaptor that invents template argument location information
3086/// for each of the template arguments in its underlying iterator.
3087template<typename Derived, typename InputIterator>
3088class TemplateArgumentLocInventIterator {
3089 TreeTransform<Derived> &Self;
3090 InputIterator Iter;
3091
3092public:
3093 typedef TemplateArgumentLoc value_type;
3094 typedef TemplateArgumentLoc reference;
3095 typedef typename std::iterator_traits<InputIterator>::difference_type
3096 difference_type;
3097 typedef std::input_iterator_tag iterator_category;
3098
3099 class pointer {
3100 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003101
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003102 public:
3103 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3104
3105 const TemplateArgumentLoc *operator->() const { return &Arg; }
3106 };
3107
3108 TemplateArgumentLocInventIterator() { }
3109
3110 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3111 InputIterator Iter)
3112 : Self(Self), Iter(Iter) { }
3113
3114 TemplateArgumentLocInventIterator &operator++() {
3115 ++Iter;
3116 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003117 }
3118
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003119 TemplateArgumentLocInventIterator operator++(int) {
3120 TemplateArgumentLocInventIterator Old(*this);
3121 ++(*this);
3122 return Old;
3123 }
3124
3125 reference operator*() const {
3126 TemplateArgumentLoc Result;
3127 Self.InventTemplateArgumentLoc(*Iter, Result);
3128 return Result;
3129 }
3130
3131 pointer operator->() const { return pointer(**this); }
3132
3133 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3134 const TemplateArgumentLocInventIterator &Y) {
3135 return X.Iter == Y.Iter;
3136 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003137
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003138 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3139 const TemplateArgumentLocInventIterator &Y) {
3140 return X.Iter != Y.Iter;
3141 }
3142};
3143
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003144template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003145template<typename InputIterator>
3146bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3147 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003148 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003149 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003150 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003151 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003152
3153 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3154 // Unpack argument packs, which we translate them into separate
3155 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003156 // FIXME: We could do much better if we could guarantee that the
3157 // TemplateArgumentLocInfo for the pack expansion would be usable for
3158 // all of the template arguments in the argument pack.
3159 typedef TemplateArgumentLocInventIterator<Derived,
3160 TemplateArgument::pack_iterator>
3161 PackLocIterator;
3162 if (TransformTemplateArguments(PackLocIterator(*this,
3163 In.getArgument().pack_begin()),
3164 PackLocIterator(*this,
3165 In.getArgument().pack_end()),
3166 Outputs))
3167 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003168
3169 continue;
3170 }
3171
3172 if (In.getArgument().isPackExpansion()) {
3173 // We have a pack expansion, for which we will be substituting into
3174 // the pattern.
3175 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003176 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003177 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003178 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3179 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003180
Chris Lattner686775d2011-07-20 06:58:45 +00003181 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003182 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3183 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3184
3185 // Determine whether the set of unexpanded parameter packs can and should
3186 // be expanded.
3187 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003188 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003189 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003190 if (getDerived().TryExpandParameterPacks(Ellipsis,
3191 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003192 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003193 Expand,
3194 RetainExpansion,
3195 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003196 return true;
3197
3198 if (!Expand) {
3199 // The transform has determined that we should perform a simple
3200 // transformation on the pack expansion, producing another pack
3201 // expansion.
3202 TemplateArgumentLoc OutPattern;
3203 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3204 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3205 return true;
3206
Douglas Gregorcded4f62011-01-14 17:04:44 +00003207 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3208 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003209 if (Out.getArgument().isNull())
3210 return true;
3211
3212 Outputs.addArgument(Out);
3213 continue;
3214 }
3215
3216 // The transform has determined that we should perform an elementwise
3217 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003218 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003219 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3220
3221 if (getDerived().TransformTemplateArgument(Pattern, Out))
3222 return true;
3223
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003224 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003225 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3226 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003227 if (Out.getArgument().isNull())
3228 return true;
3229 }
3230
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003231 Outputs.addArgument(Out);
3232 }
3233
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003234 // If we're supposed to retain a pack expansion, do so by temporarily
3235 // forgetting the partially-substituted parameter pack.
3236 if (RetainExpansion) {
3237 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3238
3239 if (getDerived().TransformTemplateArgument(Pattern, Out))
3240 return true;
3241
Douglas Gregorcded4f62011-01-14 17:04:44 +00003242 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3243 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003244 if (Out.getArgument().isNull())
3245 return true;
3246
3247 Outputs.addArgument(Out);
3248 }
Douglas Gregord3731192011-01-10 07:32:04 +00003249
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003250 continue;
3251 }
3252
3253 // The simple case:
3254 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003255 return true;
3256
3257 Outputs.addArgument(Out);
3258 }
3259
3260 return false;
3261
3262}
3263
Douglas Gregor577f75a2009-08-04 16:50:30 +00003264//===----------------------------------------------------------------------===//
3265// Type transformation
3266//===----------------------------------------------------------------------===//
3267
3268template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003269QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003270 if (getDerived().AlreadyTransformed(T))
3271 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003272
John McCalla2becad2009-10-21 00:40:46 +00003273 // Temporary workaround. All of these transformations should
3274 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003275 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3276 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003277
John McCall43fed0d2010-11-12 08:19:04 +00003278 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003279
John McCalla2becad2009-10-21 00:40:46 +00003280 if (!NewDI)
3281 return QualType();
3282
3283 return NewDI->getType();
3284}
3285
3286template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003287TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003288 // Refine the base location to the type's location.
3289 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3290 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003291 if (getDerived().AlreadyTransformed(DI->getType()))
3292 return DI;
3293
3294 TypeLocBuilder TLB;
3295
3296 TypeLoc TL = DI->getTypeLoc();
3297 TLB.reserve(TL.getFullDataSize());
3298
John McCall43fed0d2010-11-12 08:19:04 +00003299 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003300 if (Result.isNull())
3301 return 0;
3302
John McCalla93c9342009-12-07 02:54:59 +00003303 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003304}
3305
3306template<typename Derived>
3307QualType
John McCall43fed0d2010-11-12 08:19:04 +00003308TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003309 switch (T.getTypeLocClass()) {
3310#define ABSTRACT_TYPELOC(CLASS, PARENT)
3311#define TYPELOC(CLASS, PARENT) \
3312 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003313 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003314#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003315 }
Mike Stump1eb44332009-09-09 15:08:12 +00003316
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003317 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003318}
3319
3320/// FIXME: By default, this routine adds type qualifiers only to types
3321/// that can have qualifiers, and silently suppresses those qualifiers
3322/// that are not permitted (e.g., qualifiers on reference or function
3323/// types). This is the right thing for template instantiation, but
3324/// probably not for other clients.
3325template<typename Derived>
3326QualType
3327TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003328 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003329 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003330
John McCall43fed0d2010-11-12 08:19:04 +00003331 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003332 if (Result.isNull())
3333 return QualType();
3334
3335 // Silently suppress qualifiers if the result type can't be qualified.
3336 // FIXME: this is the right thing for template instantiation, but
3337 // probably not for other clients.
3338 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003339 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003340
John McCallf85e1932011-06-15 23:02:42 +00003341 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003342 // resulting type.
3343 if (Quals.hasObjCLifetime()) {
3344 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3345 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003346 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003347 // Objective-C ARC:
3348 // A lifetime qualifier applied to a substituted template parameter
3349 // overrides the lifetime qualifier from the template argument.
3350 if (const SubstTemplateTypeParmType *SubstTypeParam
3351 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3352 QualType Replacement = SubstTypeParam->getReplacementType();
3353 Qualifiers Qs = Replacement.getQualifiers();
3354 Qs.removeObjCLifetime();
3355 Replacement
3356 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3357 Qs);
3358 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3359 SubstTypeParam->getReplacedParameter(),
3360 Replacement);
3361 TLB.TypeWasModifiedSafely(Result);
3362 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003363 // Otherwise, complain about the addition of a qualifier to an
3364 // already-qualified type.
3365 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003366 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003367 << Result << R;
3368
Douglas Gregore559ca12011-06-17 22:11:49 +00003369 Quals.removeObjCLifetime();
3370 }
3371 }
3372 }
John McCall28654742010-06-05 06:41:15 +00003373 if (!Quals.empty()) {
3374 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3375 TLB.push<QualifiedTypeLoc>(Result);
3376 // No location information to preserve.
3377 }
John McCalla2becad2009-10-21 00:40:46 +00003378
3379 return Result;
3380}
3381
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003382template<typename Derived>
3383TypeLoc
3384TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3385 QualType ObjectType,
3386 NamedDecl *UnqualLookup,
3387 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003388 QualType T = TL.getType();
3389 if (getDerived().AlreadyTransformed(T))
3390 return TL;
3391
3392 TypeLocBuilder TLB;
3393 QualType Result;
3394
3395 if (isa<TemplateSpecializationType>(T)) {
3396 TemplateSpecializationTypeLoc SpecTL
3397 = cast<TemplateSpecializationTypeLoc>(TL);
3398
3399 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003400 getDerived().TransformTemplateName(SS,
3401 SpecTL.getTypePtr()->getTemplateName(),
3402 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003403 ObjectType, UnqualLookup);
3404 if (Template.isNull())
3405 return TypeLoc();
3406
3407 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3408 Template);
3409 } else if (isa<DependentTemplateSpecializationType>(T)) {
3410 DependentTemplateSpecializationTypeLoc SpecTL
3411 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3412
Douglas Gregora88f09f2011-02-28 17:23:35 +00003413 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003414 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003415 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003416 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003417 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003418 if (Template.isNull())
3419 return TypeLoc();
3420
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003421 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003422 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003423 Template,
3424 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003425 } else {
3426 // Nothing special needs to be done for these.
3427 Result = getDerived().TransformType(TLB, TL);
3428 }
3429
3430 if (Result.isNull())
3431 return TypeLoc();
3432
3433 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3434}
3435
Douglas Gregorb71d8212011-03-02 18:32:08 +00003436template<typename Derived>
3437TypeSourceInfo *
3438TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3439 QualType ObjectType,
3440 NamedDecl *UnqualLookup,
3441 CXXScopeSpec &SS) {
3442 // FIXME: Painfully copy-paste from the above!
3443
3444 QualType T = TSInfo->getType();
3445 if (getDerived().AlreadyTransformed(T))
3446 return TSInfo;
3447
3448 TypeLocBuilder TLB;
3449 QualType Result;
3450
3451 TypeLoc TL = TSInfo->getTypeLoc();
3452 if (isa<TemplateSpecializationType>(T)) {
3453 TemplateSpecializationTypeLoc SpecTL
3454 = cast<TemplateSpecializationTypeLoc>(TL);
3455
3456 TemplateName Template
3457 = getDerived().TransformTemplateName(SS,
3458 SpecTL.getTypePtr()->getTemplateName(),
3459 SpecTL.getTemplateNameLoc(),
3460 ObjectType, UnqualLookup);
3461 if (Template.isNull())
3462 return 0;
3463
3464 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3465 Template);
3466 } else if (isa<DependentTemplateSpecializationType>(T)) {
3467 DependentTemplateSpecializationTypeLoc SpecTL
3468 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3469
3470 TemplateName Template
3471 = getDerived().RebuildTemplateName(SS,
3472 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003473 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003474 ObjectType, UnqualLookup);
3475 if (Template.isNull())
3476 return 0;
3477
3478 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3479 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003480 Template,
3481 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003482 } else {
3483 // Nothing special needs to be done for these.
3484 Result = getDerived().TransformType(TLB, TL);
3485 }
3486
3487 if (Result.isNull())
3488 return 0;
3489
3490 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3491}
3492
John McCalla2becad2009-10-21 00:40:46 +00003493template <class TyLoc> static inline
3494QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3495 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3496 NewT.setNameLoc(T.getNameLoc());
3497 return T.getType();
3498}
3499
John McCalla2becad2009-10-21 00:40:46 +00003500template<typename Derived>
3501QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003502 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003503 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3504 NewT.setBuiltinLoc(T.getBuiltinLoc());
3505 if (T.needsExtraLocalData())
3506 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3507 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003508}
Mike Stump1eb44332009-09-09 15:08:12 +00003509
Douglas Gregor577f75a2009-08-04 16:50:30 +00003510template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003511QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003512 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003513 // FIXME: recurse?
3514 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003515}
Mike Stump1eb44332009-09-09 15:08:12 +00003516
Douglas Gregor577f75a2009-08-04 16:50:30 +00003517template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003518QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003519 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003520 QualType PointeeType
3521 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003522 if (PointeeType.isNull())
3523 return QualType();
3524
3525 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003526 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003527 // A dependent pointer type 'T *' has is being transformed such
3528 // that an Objective-C class type is being replaced for 'T'. The
3529 // resulting pointer type is an ObjCObjectPointerType, not a
3530 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003531 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003532
John McCallc12c5bb2010-05-15 11:32:37 +00003533 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3534 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003535 return Result;
3536 }
John McCall43fed0d2010-11-12 08:19:04 +00003537
Douglas Gregor92e986e2010-04-22 16:44:27 +00003538 if (getDerived().AlwaysRebuild() ||
3539 PointeeType != TL.getPointeeLoc().getType()) {
3540 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3541 if (Result.isNull())
3542 return QualType();
3543 }
John McCallf85e1932011-06-15 23:02:42 +00003544
3545 // Objective-C ARC can add lifetime qualifiers to the type that we're
3546 // pointing to.
3547 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3548
Douglas Gregor92e986e2010-04-22 16:44:27 +00003549 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3550 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003551 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003552}
Mike Stump1eb44332009-09-09 15:08:12 +00003553
3554template<typename Derived>
3555QualType
John McCalla2becad2009-10-21 00:40:46 +00003556TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003557 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003558 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003559 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3560 if (PointeeType.isNull())
3561 return QualType();
3562
3563 QualType Result = TL.getType();
3564 if (getDerived().AlwaysRebuild() ||
3565 PointeeType != TL.getPointeeLoc().getType()) {
3566 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003567 TL.getSigilLoc());
3568 if (Result.isNull())
3569 return QualType();
3570 }
3571
Douglas Gregor39968ad2010-04-22 16:50:51 +00003572 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003573 NewT.setSigilLoc(TL.getSigilLoc());
3574 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003575}
3576
John McCall85737a72009-10-30 00:06:24 +00003577/// Transforms a reference type. Note that somewhat paradoxically we
3578/// don't care whether the type itself is an l-value type or an r-value
3579/// type; we only care if the type was *written* as an l-value type
3580/// or an r-value type.
3581template<typename Derived>
3582QualType
3583TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003584 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003585 const ReferenceType *T = TL.getTypePtr();
3586
3587 // Note that this works with the pointee-as-written.
3588 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3589 if (PointeeType.isNull())
3590 return QualType();
3591
3592 QualType Result = TL.getType();
3593 if (getDerived().AlwaysRebuild() ||
3594 PointeeType != T->getPointeeTypeAsWritten()) {
3595 Result = getDerived().RebuildReferenceType(PointeeType,
3596 T->isSpelledAsLValue(),
3597 TL.getSigilLoc());
3598 if (Result.isNull())
3599 return QualType();
3600 }
3601
John McCallf85e1932011-06-15 23:02:42 +00003602 // Objective-C ARC can add lifetime qualifiers to the type that we're
3603 // referring to.
3604 TLB.TypeWasModifiedSafely(
3605 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3606
John McCall85737a72009-10-30 00:06:24 +00003607 // r-value references can be rebuilt as l-value references.
3608 ReferenceTypeLoc NewTL;
3609 if (isa<LValueReferenceType>(Result))
3610 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3611 else
3612 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3613 NewTL.setSigilLoc(TL.getSigilLoc());
3614
3615 return Result;
3616}
3617
Mike Stump1eb44332009-09-09 15:08:12 +00003618template<typename Derived>
3619QualType
John McCalla2becad2009-10-21 00:40:46 +00003620TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003621 LValueReferenceTypeLoc TL) {
3622 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003623}
3624
Mike Stump1eb44332009-09-09 15:08:12 +00003625template<typename Derived>
3626QualType
John McCalla2becad2009-10-21 00:40:46 +00003627TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003628 RValueReferenceTypeLoc TL) {
3629 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003630}
Mike Stump1eb44332009-09-09 15:08:12 +00003631
Douglas Gregor577f75a2009-08-04 16:50:30 +00003632template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003633QualType
John McCalla2becad2009-10-21 00:40:46 +00003634TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003635 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003636 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003637 if (PointeeType.isNull())
3638 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003639
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003640 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3641 TypeSourceInfo* NewClsTInfo = 0;
3642 if (OldClsTInfo) {
3643 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3644 if (!NewClsTInfo)
3645 return QualType();
3646 }
3647
3648 const MemberPointerType *T = TL.getTypePtr();
3649 QualType OldClsType = QualType(T->getClass(), 0);
3650 QualType NewClsType;
3651 if (NewClsTInfo)
3652 NewClsType = NewClsTInfo->getType();
3653 else {
3654 NewClsType = getDerived().TransformType(OldClsType);
3655 if (NewClsType.isNull())
3656 return QualType();
3657 }
Mike Stump1eb44332009-09-09 15:08:12 +00003658
John McCalla2becad2009-10-21 00:40:46 +00003659 QualType Result = TL.getType();
3660 if (getDerived().AlwaysRebuild() ||
3661 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003662 NewClsType != OldClsType) {
3663 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003664 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003665 if (Result.isNull())
3666 return QualType();
3667 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003668
John McCalla2becad2009-10-21 00:40:46 +00003669 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3670 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003671 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003672
3673 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003674}
3675
Mike Stump1eb44332009-09-09 15:08:12 +00003676template<typename Derived>
3677QualType
John McCalla2becad2009-10-21 00:40:46 +00003678TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003679 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003680 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003681 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003682 if (ElementType.isNull())
3683 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003684
John McCalla2becad2009-10-21 00:40:46 +00003685 QualType Result = TL.getType();
3686 if (getDerived().AlwaysRebuild() ||
3687 ElementType != T->getElementType()) {
3688 Result = getDerived().RebuildConstantArrayType(ElementType,
3689 T->getSizeModifier(),
3690 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003691 T->getIndexTypeCVRQualifiers(),
3692 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003693 if (Result.isNull())
3694 return QualType();
3695 }
Eli Friedman457a3772012-01-25 22:19:07 +00003696
3697 // We might have either a ConstantArrayType or a VariableArrayType now:
3698 // a ConstantArrayType is allowed to have an element type which is a
3699 // VariableArrayType if the type is dependent. Fortunately, all array
3700 // types have the same location layout.
3701 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003702 NewTL.setLBracketLoc(TL.getLBracketLoc());
3703 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003704
John McCalla2becad2009-10-21 00:40:46 +00003705 Expr *Size = TL.getSizeExpr();
3706 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003707 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3708 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003709 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003710 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003711 }
3712 NewTL.setSizeExpr(Size);
3713
3714 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003715}
Mike Stump1eb44332009-09-09 15:08:12 +00003716
Douglas Gregor577f75a2009-08-04 16:50:30 +00003717template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003718QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003719 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003720 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003721 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003722 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003723 if (ElementType.isNull())
3724 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003725
John McCalla2becad2009-10-21 00:40:46 +00003726 QualType Result = TL.getType();
3727 if (getDerived().AlwaysRebuild() ||
3728 ElementType != T->getElementType()) {
3729 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003730 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003731 T->getIndexTypeCVRQualifiers(),
3732 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003733 if (Result.isNull())
3734 return QualType();
3735 }
Sean Huntc3021132010-05-05 15:23:54 +00003736
John McCalla2becad2009-10-21 00:40:46 +00003737 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3738 NewTL.setLBracketLoc(TL.getLBracketLoc());
3739 NewTL.setRBracketLoc(TL.getRBracketLoc());
3740 NewTL.setSizeExpr(0);
3741
3742 return Result;
3743}
3744
3745template<typename Derived>
3746QualType
3747TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003748 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003749 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003750 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3751 if (ElementType.isNull())
3752 return QualType();
3753
John McCall60d7b3a2010-08-24 06:29:42 +00003754 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003755 = getDerived().TransformExpr(T->getSizeExpr());
3756 if (SizeResult.isInvalid())
3757 return QualType();
3758
John McCall9ae2f072010-08-23 23:25:46 +00003759 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003760
3761 QualType Result = TL.getType();
3762 if (getDerived().AlwaysRebuild() ||
3763 ElementType != T->getElementType() ||
3764 Size != T->getSizeExpr()) {
3765 Result = getDerived().RebuildVariableArrayType(ElementType,
3766 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003767 Size,
John McCalla2becad2009-10-21 00:40:46 +00003768 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003769 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003770 if (Result.isNull())
3771 return QualType();
3772 }
Sean Huntc3021132010-05-05 15:23:54 +00003773
John McCalla2becad2009-10-21 00:40:46 +00003774 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3775 NewTL.setLBracketLoc(TL.getLBracketLoc());
3776 NewTL.setRBracketLoc(TL.getRBracketLoc());
3777 NewTL.setSizeExpr(Size);
3778
3779 return Result;
3780}
3781
3782template<typename Derived>
3783QualType
3784TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003785 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003786 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003787 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3788 if (ElementType.isNull())
3789 return QualType();
3790
Richard Smithf6702a32011-12-20 02:08:33 +00003791 // Array bounds are constant expressions.
3792 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3793 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003794
John McCall3b657512011-01-19 10:06:00 +00003795 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3796 Expr *origSize = TL.getSizeExpr();
3797 if (!origSize) origSize = T->getSizeExpr();
3798
3799 ExprResult sizeResult
3800 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003801 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003802 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003803 return QualType();
3804
John McCall3b657512011-01-19 10:06:00 +00003805 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003806
3807 QualType Result = TL.getType();
3808 if (getDerived().AlwaysRebuild() ||
3809 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003810 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003811 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3812 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003813 size,
John McCalla2becad2009-10-21 00:40:46 +00003814 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003815 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003816 if (Result.isNull())
3817 return QualType();
3818 }
John McCalla2becad2009-10-21 00:40:46 +00003819
3820 // We might have any sort of array type now, but fortunately they
3821 // all have the same location layout.
3822 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3823 NewTL.setLBracketLoc(TL.getLBracketLoc());
3824 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003825 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003826
3827 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003828}
Mike Stump1eb44332009-09-09 15:08:12 +00003829
3830template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003831QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003832 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003833 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003834 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003835
3836 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003837 QualType ElementType = getDerived().TransformType(T->getElementType());
3838 if (ElementType.isNull())
3839 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003840
Richard Smithf6702a32011-12-20 02:08:33 +00003841 // Vector sizes are constant expressions.
3842 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3843 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003844
John McCall60d7b3a2010-08-24 06:29:42 +00003845 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003846 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003847 if (Size.isInvalid())
3848 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003849
John McCalla2becad2009-10-21 00:40:46 +00003850 QualType Result = TL.getType();
3851 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003852 ElementType != T->getElementType() ||
3853 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003854 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003855 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003856 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003857 if (Result.isNull())
3858 return QualType();
3859 }
John McCalla2becad2009-10-21 00:40:46 +00003860
3861 // Result might be dependent or not.
3862 if (isa<DependentSizedExtVectorType>(Result)) {
3863 DependentSizedExtVectorTypeLoc NewTL
3864 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3865 NewTL.setNameLoc(TL.getNameLoc());
3866 } else {
3867 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3868 NewTL.setNameLoc(TL.getNameLoc());
3869 }
3870
3871 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003872}
Mike Stump1eb44332009-09-09 15:08:12 +00003873
3874template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003875QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003876 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003877 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003878 QualType ElementType = getDerived().TransformType(T->getElementType());
3879 if (ElementType.isNull())
3880 return QualType();
3881
John McCalla2becad2009-10-21 00:40:46 +00003882 QualType Result = TL.getType();
3883 if (getDerived().AlwaysRebuild() ||
3884 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003885 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003886 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003887 if (Result.isNull())
3888 return QualType();
3889 }
Sean Huntc3021132010-05-05 15:23:54 +00003890
John McCalla2becad2009-10-21 00:40:46 +00003891 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3892 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003893
John McCalla2becad2009-10-21 00:40:46 +00003894 return Result;
3895}
3896
3897template<typename Derived>
3898QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003899 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003900 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003901 QualType ElementType = getDerived().TransformType(T->getElementType());
3902 if (ElementType.isNull())
3903 return QualType();
3904
3905 QualType Result = TL.getType();
3906 if (getDerived().AlwaysRebuild() ||
3907 ElementType != T->getElementType()) {
3908 Result = getDerived().RebuildExtVectorType(ElementType,
3909 T->getNumElements(),
3910 /*FIXME*/ SourceLocation());
3911 if (Result.isNull())
3912 return QualType();
3913 }
Sean Huntc3021132010-05-05 15:23:54 +00003914
John McCalla2becad2009-10-21 00:40:46 +00003915 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3916 NewTL.setNameLoc(TL.getNameLoc());
3917
3918 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003919}
Mike Stump1eb44332009-09-09 15:08:12 +00003920
3921template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003922ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003923TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003924 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003925 llvm::Optional<unsigned> NumExpansions,
3926 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003927 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003928 TypeSourceInfo *NewDI = 0;
3929
3930 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3931 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003932 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003933 TypeLoc OldTL = OldDI->getTypeLoc();
3934 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3935
3936 TypeLocBuilder TLB;
3937 TypeLoc NewTL = OldDI->getTypeLoc();
3938 TLB.reserve(NewTL.getFullDataSize());
3939
3940 QualType Result = getDerived().TransformType(TLB,
3941 OldExpansionTL.getPatternLoc());
3942 if (Result.isNull())
3943 return 0;
3944
3945 Result = RebuildPackExpansionType(Result,
3946 OldExpansionTL.getPatternLoc().getSourceRange(),
3947 OldExpansionTL.getEllipsisLoc(),
3948 NumExpansions);
3949 if (Result.isNull())
3950 return 0;
3951
3952 PackExpansionTypeLoc NewExpansionTL
3953 = TLB.push<PackExpansionTypeLoc>(Result);
3954 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3955 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3956 } else
3957 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003958 if (!NewDI)
3959 return 0;
3960
John McCallfb44de92011-05-01 22:35:37 +00003961 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003962 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003963
3964 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3965 OldParm->getDeclContext(),
3966 OldParm->getInnerLocStart(),
3967 OldParm->getLocation(),
3968 OldParm->getIdentifier(),
3969 NewDI->getType(),
3970 NewDI,
3971 OldParm->getStorageClass(),
3972 OldParm->getStorageClassAsWritten(),
3973 /* DefArg */ NULL);
3974 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3975 OldParm->getFunctionScopeIndex() + indexAdjustment);
3976 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003977}
3978
3979template<typename Derived>
3980bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003981 TransformFunctionTypeParams(SourceLocation Loc,
3982 ParmVarDecl **Params, unsigned NumParams,
3983 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003984 SmallVectorImpl<QualType> &OutParamTypes,
3985 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003986 int indexAdjustment = 0;
3987
Douglas Gregora009b592011-01-07 00:20:55 +00003988 for (unsigned i = 0; i != NumParams; ++i) {
3989 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003990 assert(OldParm->getFunctionScopeIndex() == i);
3991
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003992 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003993 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003994 if (OldParm->isParameterPack()) {
3995 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003996 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003997
Douglas Gregor603cfb42011-01-05 23:12:31 +00003998 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003999 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4000 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
4001 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4002 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004003 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4004
Douglas Gregor603cfb42011-01-05 23:12:31 +00004005 // Determine whether we should expand the parameter packs.
4006 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004007 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004008 llvm::Optional<unsigned> OrigNumExpansions
4009 = ExpansionTL.getTypePtr()->getNumExpansions();
4010 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004011 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4012 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004013 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004014 ShouldExpand,
4015 RetainExpansion,
4016 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004017 return true;
4018 }
4019
4020 if (ShouldExpand) {
4021 // Expand the function parameter pack into multiple, separate
4022 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004023 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004024 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004025 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4026 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004027 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004028 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004029 OrigNumExpansions,
4030 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004031 if (!NewParm)
4032 return true;
4033
Douglas Gregora009b592011-01-07 00:20:55 +00004034 OutParamTypes.push_back(NewParm->getType());
4035 if (PVars)
4036 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004037 }
Douglas Gregord3731192011-01-10 07:32:04 +00004038
4039 // If we're supposed to retain a pack expansion, do so by temporarily
4040 // forgetting the partially-substituted parameter pack.
4041 if (RetainExpansion) {
4042 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4043 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004044 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004045 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004046 OrigNumExpansions,
4047 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004048 if (!NewParm)
4049 return true;
4050
4051 OutParamTypes.push_back(NewParm->getType());
4052 if (PVars)
4053 PVars->push_back(NewParm);
4054 }
4055
John McCallfb44de92011-05-01 22:35:37 +00004056 // The next parameter should have the same adjustment as the
4057 // last thing we pushed, but we post-incremented indexAdjustment
4058 // on every push. Also, if we push nothing, the adjustment should
4059 // go down by one.
4060 indexAdjustment--;
4061
Douglas Gregor603cfb42011-01-05 23:12:31 +00004062 // We're done with the pack expansion.
4063 continue;
4064 }
4065
4066 // We'll substitute the parameter now without expanding the pack
4067 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004068 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4069 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004070 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004071 NumExpansions,
4072 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004073 } else {
4074 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004075 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004076 llvm::Optional<unsigned>(),
4077 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004078 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004079
John McCall21ef0fa2010-03-11 09:03:00 +00004080 if (!NewParm)
4081 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004082
Douglas Gregora009b592011-01-07 00:20:55 +00004083 OutParamTypes.push_back(NewParm->getType());
4084 if (PVars)
4085 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004086 continue;
4087 }
John McCall21ef0fa2010-03-11 09:03:00 +00004088
4089 // Deal with the possibility that we don't have a parameter
4090 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004091 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004092 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004093 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004094 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004095 if (const PackExpansionType *Expansion
4096 = dyn_cast<PackExpansionType>(OldType)) {
4097 // We have a function parameter pack that may need to be expanded.
4098 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004099 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004100 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4101
4102 // Determine whether we should expand the parameter packs.
4103 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004104 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004105 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004106 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004107 ShouldExpand,
4108 RetainExpansion,
4109 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004110 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004111 }
4112
4113 if (ShouldExpand) {
4114 // Expand the function parameter pack into multiple, separate
4115 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004116 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004117 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4118 QualType NewType = getDerived().TransformType(Pattern);
4119 if (NewType.isNull())
4120 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004121
Douglas Gregora009b592011-01-07 00:20:55 +00004122 OutParamTypes.push_back(NewType);
4123 if (PVars)
4124 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004125 }
4126
4127 // We're done with the pack expansion.
4128 continue;
4129 }
4130
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004131 // If we're supposed to retain a pack expansion, do so by temporarily
4132 // forgetting the partially-substituted parameter pack.
4133 if (RetainExpansion) {
4134 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4135 QualType NewType = getDerived().TransformType(Pattern);
4136 if (NewType.isNull())
4137 return true;
4138
4139 OutParamTypes.push_back(NewType);
4140 if (PVars)
4141 PVars->push_back(0);
4142 }
Douglas Gregord3731192011-01-10 07:32:04 +00004143
Douglas Gregor603cfb42011-01-05 23:12:31 +00004144 // We'll substitute the parameter now without expanding the pack
4145 // expansion.
4146 OldType = Expansion->getPattern();
4147 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004148 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4149 NewType = getDerived().TransformType(OldType);
4150 } else {
4151 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004152 }
4153
Douglas Gregor603cfb42011-01-05 23:12:31 +00004154 if (NewType.isNull())
4155 return true;
4156
4157 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004158 NewType = getSema().Context.getPackExpansionType(NewType,
4159 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004160
Douglas Gregora009b592011-01-07 00:20:55 +00004161 OutParamTypes.push_back(NewType);
4162 if (PVars)
4163 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004164 }
4165
John McCallfb44de92011-05-01 22:35:37 +00004166#ifndef NDEBUG
4167 if (PVars) {
4168 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4169 if (ParmVarDecl *parm = (*PVars)[i])
4170 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004171 }
John McCallfb44de92011-05-01 22:35:37 +00004172#endif
4173
4174 return false;
4175}
John McCall21ef0fa2010-03-11 09:03:00 +00004176
4177template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004178QualType
John McCalla2becad2009-10-21 00:40:46 +00004179TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004180 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004181 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4182}
4183
4184template<typename Derived>
4185QualType
4186TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4187 FunctionProtoTypeLoc TL,
4188 CXXRecordDecl *ThisContext,
4189 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004190 // Transform the parameters and return type.
4191 //
Richard Smithe6975e92012-04-17 00:58:00 +00004192 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004193 // When the function has a trailing return type, we instantiate the
4194 // parameters before the return type, since the return type can then refer
4195 // to the parameters themselves (via decltype, sizeof, etc.).
4196 //
Chris Lattner686775d2011-07-20 06:58:45 +00004197 SmallVector<QualType, 4> ParamTypes;
4198 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004199 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004200
Douglas Gregordab60ad2010-10-01 18:44:50 +00004201 QualType ResultType;
4202
4203 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004204 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4205 TL.getParmArray(),
4206 TL.getNumArgs(),
4207 TL.getTypePtr()->arg_type_begin(),
4208 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004209 return QualType();
4210
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004211 {
4212 // C++11 [expr.prim.general]p3:
4213 // If a declaration declares a member function or member function
4214 // template of a class X, the expression this is a prvalue of type
4215 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
4216 // and the end of the function-definition, member-declarator, or
4217 // declarator.
4218 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
4219
4220 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4221 if (ResultType.isNull())
4222 return QualType();
4223 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004224 }
4225 else {
4226 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4227 if (ResultType.isNull())
4228 return QualType();
4229
Douglas Gregora009b592011-01-07 00:20:55 +00004230 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4231 TL.getParmArray(),
4232 TL.getNumArgs(),
4233 TL.getTypePtr()->arg_type_begin(),
4234 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004235 return QualType();
4236 }
4237
Richard Smithe6975e92012-04-17 00:58:00 +00004238 // FIXME: Need to transform the exception-specification too.
4239
John McCalla2becad2009-10-21 00:40:46 +00004240 QualType Result = TL.getType();
4241 if (getDerived().AlwaysRebuild() ||
4242 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004243 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004244 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4245 Result = getDerived().RebuildFunctionProtoType(ResultType,
4246 ParamTypes.data(),
4247 ParamTypes.size(),
4248 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004249 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004250 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004251 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004252 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004253 if (Result.isNull())
4254 return QualType();
4255 }
Mike Stump1eb44332009-09-09 15:08:12 +00004256
John McCalla2becad2009-10-21 00:40:46 +00004257 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004258 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4259 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004260 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004261 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4262 NewTL.setArg(i, ParamDecls[i]);
4263
4264 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004265}
Mike Stump1eb44332009-09-09 15:08:12 +00004266
Douglas Gregor577f75a2009-08-04 16:50:30 +00004267template<typename Derived>
4268QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004269 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004270 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004271 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004272 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4273 if (ResultType.isNull())
4274 return QualType();
4275
4276 QualType Result = TL.getType();
4277 if (getDerived().AlwaysRebuild() ||
4278 ResultType != T->getResultType())
4279 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4280
4281 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004282 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4283 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004284 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004285
4286 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004287}
Mike Stump1eb44332009-09-09 15:08:12 +00004288
John McCalled976492009-12-04 22:46:56 +00004289template<typename Derived> QualType
4290TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004291 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004292 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004293 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004294 if (!D)
4295 return QualType();
4296
4297 QualType Result = TL.getType();
4298 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4299 Result = getDerived().RebuildUnresolvedUsingType(D);
4300 if (Result.isNull())
4301 return QualType();
4302 }
4303
4304 // We might get an arbitrary type spec type back. We should at
4305 // least always get a type spec type, though.
4306 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4307 NewTL.setNameLoc(TL.getNameLoc());
4308
4309 return Result;
4310}
4311
Douglas Gregor577f75a2009-08-04 16:50:30 +00004312template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004313QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004314 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004315 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004316 TypedefNameDecl *Typedef
4317 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4318 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004319 if (!Typedef)
4320 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004321
John McCalla2becad2009-10-21 00:40:46 +00004322 QualType Result = TL.getType();
4323 if (getDerived().AlwaysRebuild() ||
4324 Typedef != T->getDecl()) {
4325 Result = getDerived().RebuildTypedefType(Typedef);
4326 if (Result.isNull())
4327 return QualType();
4328 }
Mike Stump1eb44332009-09-09 15:08:12 +00004329
John McCalla2becad2009-10-21 00:40:46 +00004330 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4331 NewTL.setNameLoc(TL.getNameLoc());
4332
4333 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004334}
Mike Stump1eb44332009-09-09 15:08:12 +00004335
Douglas Gregor577f75a2009-08-04 16:50:30 +00004336template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004337QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004338 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004339 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004340 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004341
John McCall60d7b3a2010-08-24 06:29:42 +00004342 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004343 if (E.isInvalid())
4344 return QualType();
4345
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004346 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4347 if (E.isInvalid())
4348 return QualType();
4349
John McCalla2becad2009-10-21 00:40:46 +00004350 QualType Result = TL.getType();
4351 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004352 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004353 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004354 if (Result.isNull())
4355 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004356 }
John McCalla2becad2009-10-21 00:40:46 +00004357 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004358
John McCalla2becad2009-10-21 00:40:46 +00004359 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004360 NewTL.setTypeofLoc(TL.getTypeofLoc());
4361 NewTL.setLParenLoc(TL.getLParenLoc());
4362 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004363
4364 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004365}
Mike Stump1eb44332009-09-09 15:08:12 +00004366
4367template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004368QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004369 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004370 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4371 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4372 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004373 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004374
John McCalla2becad2009-10-21 00:40:46 +00004375 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004376 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4377 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004378 if (Result.isNull())
4379 return QualType();
4380 }
Mike Stump1eb44332009-09-09 15:08:12 +00004381
John McCalla2becad2009-10-21 00:40:46 +00004382 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004383 NewTL.setTypeofLoc(TL.getTypeofLoc());
4384 NewTL.setLParenLoc(TL.getLParenLoc());
4385 NewTL.setRParenLoc(TL.getRParenLoc());
4386 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004387
4388 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004389}
Mike Stump1eb44332009-09-09 15:08:12 +00004390
4391template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004392QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004393 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004394 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004395
Douglas Gregor670444e2009-08-04 22:27:00 +00004396 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004397 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4398 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004399
John McCall60d7b3a2010-08-24 06:29:42 +00004400 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004401 if (E.isInvalid())
4402 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004403
Richard Smith76f3f692012-02-22 02:04:18 +00004404 E = getSema().ActOnDecltypeExpression(E.take());
4405 if (E.isInvalid())
4406 return QualType();
4407
John McCalla2becad2009-10-21 00:40:46 +00004408 QualType Result = TL.getType();
4409 if (getDerived().AlwaysRebuild() ||
4410 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004411 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004412 if (Result.isNull())
4413 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004414 }
John McCalla2becad2009-10-21 00:40:46 +00004415 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004416
John McCalla2becad2009-10-21 00:40:46 +00004417 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4418 NewTL.setNameLoc(TL.getNameLoc());
4419
4420 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004421}
4422
4423template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004424QualType TreeTransform<Derived>::TransformUnaryTransformType(
4425 TypeLocBuilder &TLB,
4426 UnaryTransformTypeLoc TL) {
4427 QualType Result = TL.getType();
4428 if (Result->isDependentType()) {
4429 const UnaryTransformType *T = TL.getTypePtr();
4430 QualType NewBase =
4431 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4432 Result = getDerived().RebuildUnaryTransformType(NewBase,
4433 T->getUTTKind(),
4434 TL.getKWLoc());
4435 if (Result.isNull())
4436 return QualType();
4437 }
4438
4439 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4440 NewTL.setKWLoc(TL.getKWLoc());
4441 NewTL.setParensRange(TL.getParensRange());
4442 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4443 return Result;
4444}
4445
4446template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004447QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4448 AutoTypeLoc TL) {
4449 const AutoType *T = TL.getTypePtr();
4450 QualType OldDeduced = T->getDeducedType();
4451 QualType NewDeduced;
4452 if (!OldDeduced.isNull()) {
4453 NewDeduced = getDerived().TransformType(OldDeduced);
4454 if (NewDeduced.isNull())
4455 return QualType();
4456 }
4457
4458 QualType Result = TL.getType();
4459 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4460 Result = getDerived().RebuildAutoType(NewDeduced);
4461 if (Result.isNull())
4462 return QualType();
4463 }
4464
4465 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4466 NewTL.setNameLoc(TL.getNameLoc());
4467
4468 return Result;
4469}
4470
4471template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004472QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004473 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004474 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004475 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004476 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4477 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004478 if (!Record)
4479 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004480
John McCalla2becad2009-10-21 00:40:46 +00004481 QualType Result = TL.getType();
4482 if (getDerived().AlwaysRebuild() ||
4483 Record != T->getDecl()) {
4484 Result = getDerived().RebuildRecordType(Record);
4485 if (Result.isNull())
4486 return QualType();
4487 }
Mike Stump1eb44332009-09-09 15:08:12 +00004488
John McCalla2becad2009-10-21 00:40:46 +00004489 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4490 NewTL.setNameLoc(TL.getNameLoc());
4491
4492 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004493}
Mike Stump1eb44332009-09-09 15:08:12 +00004494
4495template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004496QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004497 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004498 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004499 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004500 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4501 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004502 if (!Enum)
4503 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004504
John McCalla2becad2009-10-21 00:40:46 +00004505 QualType Result = TL.getType();
4506 if (getDerived().AlwaysRebuild() ||
4507 Enum != T->getDecl()) {
4508 Result = getDerived().RebuildEnumType(Enum);
4509 if (Result.isNull())
4510 return QualType();
4511 }
Mike Stump1eb44332009-09-09 15:08:12 +00004512
John McCalla2becad2009-10-21 00:40:46 +00004513 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4514 NewTL.setNameLoc(TL.getNameLoc());
4515
4516 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004517}
John McCall7da24312009-09-05 00:15:47 +00004518
John McCall3cb0ebd2010-03-10 03:28:59 +00004519template<typename Derived>
4520QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4521 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004522 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004523 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4524 TL.getTypePtr()->getDecl());
4525 if (!D) return QualType();
4526
4527 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4528 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4529 return T;
4530}
4531
Douglas Gregor577f75a2009-08-04 16:50:30 +00004532template<typename Derived>
4533QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004534 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004535 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004536 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004537}
4538
Mike Stump1eb44332009-09-09 15:08:12 +00004539template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004540QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004541 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004542 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004543 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4544
4545 // Substitute into the replacement type, which itself might involve something
4546 // that needs to be transformed. This only tends to occur with default
4547 // template arguments of template template parameters.
4548 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4549 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4550 if (Replacement.isNull())
4551 return QualType();
4552
4553 // Always canonicalize the replacement type.
4554 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4555 QualType Result
4556 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4557 Replacement);
4558
4559 // Propagate type-source information.
4560 SubstTemplateTypeParmTypeLoc NewTL
4561 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4562 NewTL.setNameLoc(TL.getNameLoc());
4563 return Result;
4564
John McCall49a832b2009-10-18 09:09:24 +00004565}
4566
4567template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004568QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4569 TypeLocBuilder &TLB,
4570 SubstTemplateTypeParmPackTypeLoc TL) {
4571 return TransformTypeSpecType(TLB, TL);
4572}
4573
4574template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004575QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004576 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004577 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004578 const TemplateSpecializationType *T = TL.getTypePtr();
4579
Douglas Gregor1d752d72011-03-02 18:46:51 +00004580 // The nested-name-specifier never matters in a TemplateSpecializationType,
4581 // because we can't have a dependent nested-name-specifier anyway.
4582 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004583 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004584 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4585 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004586 if (Template.isNull())
4587 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004588
John McCall43fed0d2010-11-12 08:19:04 +00004589 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4590}
4591
Eli Friedmanb001de72011-10-06 23:00:33 +00004592template<typename Derived>
4593QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4594 AtomicTypeLoc TL) {
4595 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4596 if (ValueType.isNull())
4597 return QualType();
4598
4599 QualType Result = TL.getType();
4600 if (getDerived().AlwaysRebuild() ||
4601 ValueType != TL.getValueLoc().getType()) {
4602 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4603 if (Result.isNull())
4604 return QualType();
4605 }
4606
4607 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4608 NewTL.setKWLoc(TL.getKWLoc());
4609 NewTL.setLParenLoc(TL.getLParenLoc());
4610 NewTL.setRParenLoc(TL.getRParenLoc());
4611
4612 return Result;
4613}
4614
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004615namespace {
4616 /// \brief Simple iterator that traverses the template arguments in a
4617 /// container that provides a \c getArgLoc() member function.
4618 ///
4619 /// This iterator is intended to be used with the iterator form of
4620 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4621 template<typename ArgLocContainer>
4622 class TemplateArgumentLocContainerIterator {
4623 ArgLocContainer *Container;
4624 unsigned Index;
4625
4626 public:
4627 typedef TemplateArgumentLoc value_type;
4628 typedef TemplateArgumentLoc reference;
4629 typedef int difference_type;
4630 typedef std::input_iterator_tag iterator_category;
4631
4632 class pointer {
4633 TemplateArgumentLoc Arg;
4634
4635 public:
4636 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4637
4638 const TemplateArgumentLoc *operator->() const {
4639 return &Arg;
4640 }
4641 };
4642
4643
4644 TemplateArgumentLocContainerIterator() {}
4645
4646 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4647 unsigned Index)
4648 : Container(&Container), Index(Index) { }
4649
4650 TemplateArgumentLocContainerIterator &operator++() {
4651 ++Index;
4652 return *this;
4653 }
4654
4655 TemplateArgumentLocContainerIterator operator++(int) {
4656 TemplateArgumentLocContainerIterator Old(*this);
4657 ++(*this);
4658 return Old;
4659 }
4660
4661 TemplateArgumentLoc operator*() const {
4662 return Container->getArgLoc(Index);
4663 }
4664
4665 pointer operator->() const {
4666 return pointer(Container->getArgLoc(Index));
4667 }
4668
4669 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004670 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004671 return X.Container == Y.Container && X.Index == Y.Index;
4672 }
4673
4674 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004675 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004676 return !(X == Y);
4677 }
4678 };
4679}
4680
4681
John McCall43fed0d2010-11-12 08:19:04 +00004682template <typename Derived>
4683QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4684 TypeLocBuilder &TLB,
4685 TemplateSpecializationTypeLoc TL,
4686 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004687 TemplateArgumentListInfo NewTemplateArgs;
4688 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4689 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004690 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4691 ArgIterator;
4692 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4693 ArgIterator(TL, TL.getNumArgs()),
4694 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004695 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004696
John McCall833ca992009-10-29 08:12:44 +00004697 // FIXME: maybe don't rebuild if all the template arguments are the same.
4698
4699 QualType Result =
4700 getDerived().RebuildTemplateSpecializationType(Template,
4701 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004702 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004703
4704 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004705 // Specializations of template template parameters are represented as
4706 // TemplateSpecializationTypes, and substitution of type alias templates
4707 // within a dependent context can transform them into
4708 // DependentTemplateSpecializationTypes.
4709 if (isa<DependentTemplateSpecializationType>(Result)) {
4710 DependentTemplateSpecializationTypeLoc NewTL
4711 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004712 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004713 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004714 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004715 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004716 NewTL.setLAngleLoc(TL.getLAngleLoc());
4717 NewTL.setRAngleLoc(TL.getRAngleLoc());
4718 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4719 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4720 return Result;
4721 }
4722
John McCall833ca992009-10-29 08:12:44 +00004723 TemplateSpecializationTypeLoc NewTL
4724 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004725 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004726 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4727 NewTL.setLAngleLoc(TL.getLAngleLoc());
4728 NewTL.setRAngleLoc(TL.getRAngleLoc());
4729 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4730 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004731 }
Mike Stump1eb44332009-09-09 15:08:12 +00004732
John McCall833ca992009-10-29 08:12:44 +00004733 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004734}
Mike Stump1eb44332009-09-09 15:08:12 +00004735
Douglas Gregora88f09f2011-02-28 17:23:35 +00004736template <typename Derived>
4737QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4738 TypeLocBuilder &TLB,
4739 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004740 TemplateName Template,
4741 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004742 TemplateArgumentListInfo NewTemplateArgs;
4743 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4744 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4745 typedef TemplateArgumentLocContainerIterator<
4746 DependentTemplateSpecializationTypeLoc> ArgIterator;
4747 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4748 ArgIterator(TL, TL.getNumArgs()),
4749 NewTemplateArgs))
4750 return QualType();
4751
4752 // FIXME: maybe don't rebuild if all the template arguments are the same.
4753
4754 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4755 QualType Result
4756 = getSema().Context.getDependentTemplateSpecializationType(
4757 TL.getTypePtr()->getKeyword(),
4758 DTN->getQualifier(),
4759 DTN->getIdentifier(),
4760 NewTemplateArgs);
4761
4762 DependentTemplateSpecializationTypeLoc NewTL
4763 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004764 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004765 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004766 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004767 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004768 NewTL.setLAngleLoc(TL.getLAngleLoc());
4769 NewTL.setRAngleLoc(TL.getRAngleLoc());
4770 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4771 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4772 return Result;
4773 }
4774
4775 QualType Result
4776 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004777 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004778 NewTemplateArgs);
4779
4780 if (!Result.isNull()) {
4781 /// FIXME: Wrap this in an elaborated-type-specifier?
4782 TemplateSpecializationTypeLoc NewTL
4783 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004784 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004785 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004786 NewTL.setLAngleLoc(TL.getLAngleLoc());
4787 NewTL.setRAngleLoc(TL.getRAngleLoc());
4788 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4789 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4790 }
4791
4792 return Result;
4793}
4794
Mike Stump1eb44332009-09-09 15:08:12 +00004795template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004796QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004797TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004798 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004799 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004800
Douglas Gregor9e876872011-03-01 18:12:44 +00004801 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004802 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004803 if (TL.getQualifierLoc()) {
4804 QualifierLoc
4805 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4806 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004807 return QualType();
4808 }
Mike Stump1eb44332009-09-09 15:08:12 +00004809
John McCall43fed0d2010-11-12 08:19:04 +00004810 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4811 if (NamedT.isNull())
4812 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004813
Richard Smith3e4c6c42011-05-05 21:57:07 +00004814 // C++0x [dcl.type.elab]p2:
4815 // If the identifier resolves to a typedef-name or the simple-template-id
4816 // resolves to an alias template specialization, the
4817 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004818 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4819 if (const TemplateSpecializationType *TST =
4820 NamedT->getAs<TemplateSpecializationType>()) {
4821 TemplateName Template = TST->getTemplateName();
4822 if (TypeAliasTemplateDecl *TAT =
4823 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4824 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4825 diag::err_tag_reference_non_tag) << 4;
4826 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4827 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004828 }
4829 }
4830
John McCalla2becad2009-10-21 00:40:46 +00004831 QualType Result = TL.getType();
4832 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004833 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004834 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004835 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004836 T->getKeyword(),
4837 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004838 if (Result.isNull())
4839 return QualType();
4840 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004841
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004842 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004843 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004844 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004845 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004846}
Mike Stump1eb44332009-09-09 15:08:12 +00004847
4848template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004849QualType TreeTransform<Derived>::TransformAttributedType(
4850 TypeLocBuilder &TLB,
4851 AttributedTypeLoc TL) {
4852 const AttributedType *oldType = TL.getTypePtr();
4853 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4854 if (modifiedType.isNull())
4855 return QualType();
4856
4857 QualType result = TL.getType();
4858
4859 // FIXME: dependent operand expressions?
4860 if (getDerived().AlwaysRebuild() ||
4861 modifiedType != oldType->getModifiedType()) {
4862 // TODO: this is really lame; we should really be rebuilding the
4863 // equivalent type from first principles.
4864 QualType equivalentType
4865 = getDerived().TransformType(oldType->getEquivalentType());
4866 if (equivalentType.isNull())
4867 return QualType();
4868 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4869 modifiedType,
4870 equivalentType);
4871 }
4872
4873 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4874 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4875 if (TL.hasAttrOperand())
4876 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4877 if (TL.hasAttrExprOperand())
4878 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4879 else if (TL.hasAttrEnumOperand())
4880 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4881
4882 return result;
4883}
4884
4885template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004886QualType
4887TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4888 ParenTypeLoc TL) {
4889 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4890 if (Inner.isNull())
4891 return QualType();
4892
4893 QualType Result = TL.getType();
4894 if (getDerived().AlwaysRebuild() ||
4895 Inner != TL.getInnerLoc().getType()) {
4896 Result = getDerived().RebuildParenType(Inner);
4897 if (Result.isNull())
4898 return QualType();
4899 }
4900
4901 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4902 NewTL.setLParenLoc(TL.getLParenLoc());
4903 NewTL.setRParenLoc(TL.getRParenLoc());
4904 return Result;
4905}
4906
4907template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004908QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004909 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004910 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004911
Douglas Gregor2494dd02011-03-01 01:34:45 +00004912 NestedNameSpecifierLoc QualifierLoc
4913 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4914 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004915 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004916
John McCall33500952010-06-11 00:33:02 +00004917 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004918 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004919 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004920 QualifierLoc,
4921 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004922 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004923 if (Result.isNull())
4924 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004925
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004926 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4927 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004928 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4929
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004930 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004931 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004932 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004933 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004934 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004935 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004936 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004937 NewTL.setNameLoc(TL.getNameLoc());
4938 }
John McCalla2becad2009-10-21 00:40:46 +00004939 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004940}
Mike Stump1eb44332009-09-09 15:08:12 +00004941
Douglas Gregor577f75a2009-08-04 16:50:30 +00004942template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004943QualType TreeTransform<Derived>::
4944 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004945 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004946 NestedNameSpecifierLoc QualifierLoc;
4947 if (TL.getQualifierLoc()) {
4948 QualifierLoc
4949 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4950 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004951 return QualType();
4952 }
4953
John McCall43fed0d2010-11-12 08:19:04 +00004954 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004955 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004956}
4957
4958template<typename Derived>
4959QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004960TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4961 DependentTemplateSpecializationTypeLoc TL,
4962 NestedNameSpecifierLoc QualifierLoc) {
4963 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4964
4965 TemplateArgumentListInfo NewTemplateArgs;
4966 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4967 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4968
4969 typedef TemplateArgumentLocContainerIterator<
4970 DependentTemplateSpecializationTypeLoc> ArgIterator;
4971 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4972 ArgIterator(TL, TL.getNumArgs()),
4973 NewTemplateArgs))
4974 return QualType();
4975
4976 QualType Result
4977 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4978 QualifierLoc,
4979 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004980 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004981 NewTemplateArgs);
4982 if (Result.isNull())
4983 return QualType();
4984
4985 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4986 QualType NamedT = ElabT->getNamedType();
4987
4988 // Copy information relevant to the template specialization.
4989 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004990 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004991 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004992 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004993 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4994 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004995 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004996 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004997
4998 // Copy information relevant to the elaborated type.
4999 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005000 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005001 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005002 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5003 DependentTemplateSpecializationTypeLoc SpecTL
5004 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005005 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005006 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005007 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005008 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005009 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5010 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005011 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005012 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005013 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005014 TemplateSpecializationTypeLoc SpecTL
5015 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005016 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005017 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005018 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5019 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005020 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005021 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005022 }
5023 return Result;
5024}
5025
5026template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005027QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5028 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005029 QualType Pattern
5030 = getDerived().TransformType(TLB, TL.getPatternLoc());
5031 if (Pattern.isNull())
5032 return QualType();
5033
5034 QualType Result = TL.getType();
5035 if (getDerived().AlwaysRebuild() ||
5036 Pattern != TL.getPatternLoc().getType()) {
5037 Result = getDerived().RebuildPackExpansionType(Pattern,
5038 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005039 TL.getEllipsisLoc(),
5040 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005041 if (Result.isNull())
5042 return QualType();
5043 }
5044
5045 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5046 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5047 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005048}
5049
5050template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005051QualType
5052TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005053 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005054 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005055 TLB.pushFullCopy(TL);
5056 return TL.getType();
5057}
5058
5059template<typename Derived>
5060QualType
5061TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005062 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005063 // ObjCObjectType is never dependent.
5064 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005065 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005066}
Mike Stump1eb44332009-09-09 15:08:12 +00005067
5068template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005069QualType
5070TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005071 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005072 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005073 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005074 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005075}
5076
Douglas Gregor577f75a2009-08-04 16:50:30 +00005077//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005078// Statement transformation
5079//===----------------------------------------------------------------------===//
5080template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005081StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005082TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005083 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005084}
5085
5086template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005087StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005088TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5089 return getDerived().TransformCompoundStmt(S, false);
5090}
5091
5092template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005093StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005094TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005095 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005096 Sema::CompoundScopeRAII CompoundScope(getSema());
5097
John McCall7114cba2010-08-27 19:56:05 +00005098 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005099 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005100 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00005101 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5102 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005103 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005104 if (Result.isInvalid()) {
5105 // Immediately fail if this was a DeclStmt, since it's very
5106 // likely that this will cause problems for future statements.
5107 if (isa<DeclStmt>(*B))
5108 return StmtError();
5109
5110 // Otherwise, just keep processing substatements and fail later.
5111 SubStmtInvalid = true;
5112 continue;
5113 }
Mike Stump1eb44332009-09-09 15:08:12 +00005114
Douglas Gregor43959a92009-08-20 07:17:43 +00005115 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5116 Statements.push_back(Result.takeAs<Stmt>());
5117 }
Mike Stump1eb44332009-09-09 15:08:12 +00005118
John McCall7114cba2010-08-27 19:56:05 +00005119 if (SubStmtInvalid)
5120 return StmtError();
5121
Douglas Gregor43959a92009-08-20 07:17:43 +00005122 if (!getDerived().AlwaysRebuild() &&
5123 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005124 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005125
5126 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5127 move_arg(Statements),
5128 S->getRBracLoc(),
5129 IsStmtExpr);
5130}
Mike Stump1eb44332009-09-09 15:08:12 +00005131
Douglas Gregor43959a92009-08-20 07:17:43 +00005132template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005133StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005134TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005135 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005136 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005137 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5138 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005139
Eli Friedman264c1f82009-11-19 03:14:00 +00005140 // Transform the left-hand case value.
5141 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005142 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005143 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005144 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005145
Eli Friedman264c1f82009-11-19 03:14:00 +00005146 // Transform the right-hand case value (for the GNU case-range extension).
5147 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005148 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005149 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005150 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005151 }
Mike Stump1eb44332009-09-09 15:08:12 +00005152
Douglas Gregor43959a92009-08-20 07:17:43 +00005153 // Build the case statement.
5154 // Case statements are always rebuilt so that they will attached to their
5155 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005156 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005157 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005158 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005159 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005160 S->getColonLoc());
5161 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005162 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005163
Douglas Gregor43959a92009-08-20 07:17:43 +00005164 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005165 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005166 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005167 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005168
Douglas Gregor43959a92009-08-20 07:17:43 +00005169 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005170 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005171}
5172
5173template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005174StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005175TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005176 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005177 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005178 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005179 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005180
Douglas Gregor43959a92009-08-20 07:17:43 +00005181 // Default statements are always rebuilt
5182 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005183 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005184}
Mike Stump1eb44332009-09-09 15:08:12 +00005185
Douglas Gregor43959a92009-08-20 07:17:43 +00005186template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005187StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005188TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005189 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005190 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005191 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005192
Chris Lattner57ad3782011-02-17 20:34:02 +00005193 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5194 S->getDecl());
5195 if (!LD)
5196 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005197
5198
Douglas Gregor43959a92009-08-20 07:17:43 +00005199 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005200 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005201 cast<LabelDecl>(LD), SourceLocation(),
5202 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005203}
Mike Stump1eb44332009-09-09 15:08:12 +00005204
Douglas Gregor43959a92009-08-20 07:17:43 +00005205template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005206StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005207TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5208 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5209 if (SubStmt.isInvalid())
5210 return StmtError();
5211
5212 // TODO: transform attributes
5213 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5214 return S;
5215
5216 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5217 S->getAttrs(),
5218 SubStmt.get());
5219}
5220
5221template<typename Derived>
5222StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005223TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005224 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005225 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005226 VarDecl *ConditionVar = 0;
5227 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005228 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005229 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005230 getDerived().TransformDefinition(
5231 S->getConditionVariable()->getLocation(),
5232 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005233 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005234 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005235 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005236 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005237
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005238 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005239 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005240
5241 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005242 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005243 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5244 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005245 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005246 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005247
John McCall9ae2f072010-08-23 23:25:46 +00005248 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005249 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005250 }
Sean Huntc3021132010-05-05 15:23:54 +00005251
John McCall9ae2f072010-08-23 23:25:46 +00005252 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5253 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005254 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005255
Douglas Gregor43959a92009-08-20 07:17:43 +00005256 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005257 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005258 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005259 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005260
Douglas Gregor43959a92009-08-20 07:17:43 +00005261 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005262 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005263 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005264 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005265
Douglas Gregor43959a92009-08-20 07:17:43 +00005266 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005267 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005268 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005269 Then.get() == S->getThen() &&
5270 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005271 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005272
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005273 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005274 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005275 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005276}
5277
5278template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005279StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005280TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005281 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005282 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005283 VarDecl *ConditionVar = 0;
5284 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005285 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005286 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005287 getDerived().TransformDefinition(
5288 S->getConditionVariable()->getLocation(),
5289 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005290 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005291 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005292 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005293 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005294
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005295 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005296 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005297 }
Mike Stump1eb44332009-09-09 15:08:12 +00005298
Douglas Gregor43959a92009-08-20 07:17:43 +00005299 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005300 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005301 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005302 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005303 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005304 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005305
Douglas Gregor43959a92009-08-20 07:17:43 +00005306 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005307 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005308 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005309 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005310
Douglas Gregor43959a92009-08-20 07:17:43 +00005311 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005312 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5313 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005314}
Mike Stump1eb44332009-09-09 15:08:12 +00005315
Douglas Gregor43959a92009-08-20 07:17:43 +00005316template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005317StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005318TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005319 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005320 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005321 VarDecl *ConditionVar = 0;
5322 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005323 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005324 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005325 getDerived().TransformDefinition(
5326 S->getConditionVariable()->getLocation(),
5327 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005328 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005329 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005330 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005331 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005332
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005333 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005334 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005335
5336 if (S->getCond()) {
5337 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005338 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5339 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005340 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005341 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005342 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005343 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005344 }
Mike Stump1eb44332009-09-09 15:08:12 +00005345
John McCall9ae2f072010-08-23 23:25:46 +00005346 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5347 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005348 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005349
Douglas Gregor43959a92009-08-20 07:17:43 +00005350 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005351 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005352 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005353 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005354
Douglas Gregor43959a92009-08-20 07:17:43 +00005355 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005356 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005357 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005358 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005359 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005360
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005361 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005362 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005363}
Mike Stump1eb44332009-09-09 15:08:12 +00005364
Douglas Gregor43959a92009-08-20 07:17:43 +00005365template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005366StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005367TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005368 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005369 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005370 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005371 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005372
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005373 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005374 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005375 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005376 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005377
Douglas Gregor43959a92009-08-20 07:17:43 +00005378 if (!getDerived().AlwaysRebuild() &&
5379 Cond.get() == S->getCond() &&
5380 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005381 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005382
John McCall9ae2f072010-08-23 23:25:46 +00005383 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5384 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005385 S->getRParenLoc());
5386}
Mike Stump1eb44332009-09-09 15:08:12 +00005387
Douglas Gregor43959a92009-08-20 07:17:43 +00005388template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005389StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005390TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005391 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005392 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005393 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005394 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005395
Douglas Gregor43959a92009-08-20 07:17:43 +00005396 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005397 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005398 VarDecl *ConditionVar = 0;
5399 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005400 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005401 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005402 getDerived().TransformDefinition(
5403 S->getConditionVariable()->getLocation(),
5404 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005405 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005406 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005407 } else {
5408 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005409
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005410 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005411 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005412
5413 if (S->getCond()) {
5414 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005415 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5416 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005417 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005418 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005419
John McCall9ae2f072010-08-23 23:25:46 +00005420 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005421 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005422 }
Mike Stump1eb44332009-09-09 15:08:12 +00005423
John McCall9ae2f072010-08-23 23:25:46 +00005424 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5425 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005426 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005427
Douglas Gregor43959a92009-08-20 07:17:43 +00005428 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005429 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005430 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005431 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005432
John McCall9ae2f072010-08-23 23:25:46 +00005433 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5434 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005435 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005436
Douglas Gregor43959a92009-08-20 07:17:43 +00005437 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005438 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005439 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005440 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005441
Douglas Gregor43959a92009-08-20 07:17:43 +00005442 if (!getDerived().AlwaysRebuild() &&
5443 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005444 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005445 Inc.get() == S->getInc() &&
5446 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005447 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005448
Douglas Gregor43959a92009-08-20 07:17:43 +00005449 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005450 Init.get(), FullCond, ConditionVar,
5451 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005452}
5453
5454template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005455StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005456TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005457 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5458 S->getLabel());
5459 if (!LD)
5460 return StmtError();
5461
Douglas Gregor43959a92009-08-20 07:17:43 +00005462 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005463 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005464 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005465}
5466
5467template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005468StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005469TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005470 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005471 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005472 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005473 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005474
Douglas Gregor43959a92009-08-20 07:17:43 +00005475 if (!getDerived().AlwaysRebuild() &&
5476 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005477 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005478
5479 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005480 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005481}
5482
5483template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005484StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005485TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005486 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005487}
Mike Stump1eb44332009-09-09 15:08:12 +00005488
Douglas Gregor43959a92009-08-20 07:17:43 +00005489template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005490StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005491TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005492 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005493}
Mike Stump1eb44332009-09-09 15:08:12 +00005494
Douglas Gregor43959a92009-08-20 07:17:43 +00005495template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005496StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005497TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005498 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005499 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005500 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005501
Mike Stump1eb44332009-09-09 15:08:12 +00005502 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005503 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005504 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005505}
Mike Stump1eb44332009-09-09 15:08:12 +00005506
Douglas Gregor43959a92009-08-20 07:17:43 +00005507template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005508StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005509TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005510 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005511 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005512 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5513 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005514 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5515 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005516 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005517 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005518
Douglas Gregor43959a92009-08-20 07:17:43 +00005519 if (Transformed != *D)
5520 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005521
Douglas Gregor43959a92009-08-20 07:17:43 +00005522 Decls.push_back(Transformed);
5523 }
Mike Stump1eb44332009-09-09 15:08:12 +00005524
Douglas Gregor43959a92009-08-20 07:17:43 +00005525 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005526 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005527
5528 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005529 S->getStartLoc(), S->getEndLoc());
5530}
Mike Stump1eb44332009-09-09 15:08:12 +00005531
Douglas Gregor43959a92009-08-20 07:17:43 +00005532template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005533StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005534TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005535
John McCallca0408f2010-08-23 06:44:23 +00005536 ASTOwningVector<Expr*> Constraints(getSema());
5537 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005538 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005539
John McCall60d7b3a2010-08-24 06:29:42 +00005540 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005541 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005542
5543 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005544
Anders Carlsson703e3942010-01-24 05:50:09 +00005545 // Go through the outputs.
5546 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005547 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005548
Anders Carlsson703e3942010-01-24 05:50:09 +00005549 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005550 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005551
Anders Carlsson703e3942010-01-24 05:50:09 +00005552 // Transform the output expr.
5553 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005554 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005555 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005556 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005557
Anders Carlsson703e3942010-01-24 05:50:09 +00005558 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005559
John McCall9ae2f072010-08-23 23:25:46 +00005560 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005561 }
Sean Huntc3021132010-05-05 15:23:54 +00005562
Anders Carlsson703e3942010-01-24 05:50:09 +00005563 // Go through the inputs.
5564 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005565 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005566
Anders Carlsson703e3942010-01-24 05:50:09 +00005567 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005568 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005569
Anders Carlsson703e3942010-01-24 05:50:09 +00005570 // Transform the input expr.
5571 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005572 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005573 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005574 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005575
Anders Carlsson703e3942010-01-24 05:50:09 +00005576 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005577
John McCall9ae2f072010-08-23 23:25:46 +00005578 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005579 }
Sean Huntc3021132010-05-05 15:23:54 +00005580
Anders Carlsson703e3942010-01-24 05:50:09 +00005581 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005582 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005583
5584 // Go through the clobbers.
5585 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005586 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005587
5588 // No need to transform the asm string literal.
5589 AsmString = SemaRef.Owned(S->getAsmString());
5590
5591 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5592 S->isSimple(),
5593 S->isVolatile(),
5594 S->getNumOutputs(),
5595 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005596 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005597 move_arg(Constraints),
5598 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005599 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005600 move_arg(Clobbers),
5601 S->getRParenLoc(),
5602 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005603}
5604
5605
5606template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005607StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005608TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005609 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005610 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005611 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005612 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005613
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005614 // Transform the @catch statements (if present).
5615 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005616 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005617 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005618 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005619 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005620 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005621 if (Catch.get() != S->getCatchStmt(I))
5622 AnyCatchChanged = true;
5623 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005624 }
Sean Huntc3021132010-05-05 15:23:54 +00005625
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005626 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005627 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005628 if (S->getFinallyStmt()) {
5629 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5630 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005631 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005632 }
5633
5634 // If nothing changed, just retain this statement.
5635 if (!getDerived().AlwaysRebuild() &&
5636 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005637 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005638 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005639 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005640
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005641 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005642 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5643 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005644}
Mike Stump1eb44332009-09-09 15:08:12 +00005645
Douglas Gregor43959a92009-08-20 07:17:43 +00005646template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005647StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005648TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005649 // Transform the @catch parameter, if there is one.
5650 VarDecl *Var = 0;
5651 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5652 TypeSourceInfo *TSInfo = 0;
5653 if (FromVar->getTypeSourceInfo()) {
5654 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5655 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005656 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005657 }
Sean Huntc3021132010-05-05 15:23:54 +00005658
Douglas Gregorbe270a02010-04-26 17:57:08 +00005659 QualType T;
5660 if (TSInfo)
5661 T = TSInfo->getType();
5662 else {
5663 T = getDerived().TransformType(FromVar->getType());
5664 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005665 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005666 }
Sean Huntc3021132010-05-05 15:23:54 +00005667
Douglas Gregorbe270a02010-04-26 17:57:08 +00005668 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5669 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005670 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005671 }
Sean Huntc3021132010-05-05 15:23:54 +00005672
John McCall60d7b3a2010-08-24 06:29:42 +00005673 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005674 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005675 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005676
5677 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005678 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005679 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005680}
Mike Stump1eb44332009-09-09 15:08:12 +00005681
Douglas Gregor43959a92009-08-20 07:17:43 +00005682template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005683StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005684TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005685 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005686 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005687 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005688 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005689
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005690 // If nothing changed, just retain this statement.
5691 if (!getDerived().AlwaysRebuild() &&
5692 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005693 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005694
5695 // Build a new statement.
5696 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005697 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005698}
Mike Stump1eb44332009-09-09 15:08:12 +00005699
Douglas Gregor43959a92009-08-20 07:17:43 +00005700template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005701StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005702TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005703 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005704 if (S->getThrowExpr()) {
5705 Operand = getDerived().TransformExpr(S->getThrowExpr());
5706 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005707 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005708 }
Sean Huntc3021132010-05-05 15:23:54 +00005709
Douglas Gregord1377b22010-04-22 21:44:01 +00005710 if (!getDerived().AlwaysRebuild() &&
5711 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005712 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005713
John McCall9ae2f072010-08-23 23:25:46 +00005714 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005715}
Mike Stump1eb44332009-09-09 15:08:12 +00005716
Douglas Gregor43959a92009-08-20 07:17:43 +00005717template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005718StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005719TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005720 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005721 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005722 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005723 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005724 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005725 Object =
5726 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5727 Object.get());
5728 if (Object.isInvalid())
5729 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005730
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005731 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005732 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005733 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005734 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005735
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005736 // If nothing change, just retain the current statement.
5737 if (!getDerived().AlwaysRebuild() &&
5738 Object.get() == S->getSynchExpr() &&
5739 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005740 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005741
5742 // Build a new statement.
5743 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005744 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005745}
5746
5747template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005748StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005749TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5750 ObjCAutoreleasePoolStmt *S) {
5751 // Transform the body.
5752 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5753 if (Body.isInvalid())
5754 return StmtError();
5755
5756 // If nothing changed, just retain this statement.
5757 if (!getDerived().AlwaysRebuild() &&
5758 Body.get() == S->getSubStmt())
5759 return SemaRef.Owned(S);
5760
5761 // Build a new statement.
5762 return getDerived().RebuildObjCAutoreleasePoolStmt(
5763 S->getAtLoc(), Body.get());
5764}
5765
5766template<typename Derived>
5767StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005768TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005769 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005770 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005771 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005772 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005773 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005774
Douglas Gregorc3203e72010-04-22 23:10:45 +00005775 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005776 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005777 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005778 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005779 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5780 Collection.take());
5781 if (Collection.isInvalid())
5782 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005783
Douglas Gregorc3203e72010-04-22 23:10:45 +00005784 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005785 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005786 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005787 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005788
Douglas Gregorc3203e72010-04-22 23:10:45 +00005789 // If nothing changed, just retain this statement.
5790 if (!getDerived().AlwaysRebuild() &&
5791 Element.get() == S->getElement() &&
5792 Collection.get() == S->getCollection() &&
5793 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005794 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005795
Douglas Gregorc3203e72010-04-22 23:10:45 +00005796 // Build a new statement.
5797 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5798 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005799 Element.get(),
5800 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005801 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005802 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005803}
5804
5805
5806template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005807StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005808TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5809 // Transform the exception declaration, if any.
5810 VarDecl *Var = 0;
5811 if (S->getExceptionDecl()) {
5812 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005813 TypeSourceInfo *T = getDerived().TransformType(
5814 ExceptionDecl->getTypeSourceInfo());
5815 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005816 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005817
Douglas Gregor83cb9422010-09-09 17:09:21 +00005818 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005819 ExceptionDecl->getInnerLocStart(),
5820 ExceptionDecl->getLocation(),
5821 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005822 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005823 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005824 }
Mike Stump1eb44332009-09-09 15:08:12 +00005825
Douglas Gregor43959a92009-08-20 07:17:43 +00005826 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005827 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005828 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005829 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005830
Douglas Gregor43959a92009-08-20 07:17:43 +00005831 if (!getDerived().AlwaysRebuild() &&
5832 !Var &&
5833 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005834 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005835
5836 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5837 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005838 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005839}
Mike Stump1eb44332009-09-09 15:08:12 +00005840
Douglas Gregor43959a92009-08-20 07:17:43 +00005841template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005842StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005843TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5844 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005845 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005846 = getDerived().TransformCompoundStmt(S->getTryBlock());
5847 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005848 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005849
Douglas Gregor43959a92009-08-20 07:17:43 +00005850 // Transform the handlers.
5851 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005852 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005853 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005854 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005855 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5856 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005857 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005858
Douglas Gregor43959a92009-08-20 07:17:43 +00005859 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5860 Handlers.push_back(Handler.takeAs<Stmt>());
5861 }
Mike Stump1eb44332009-09-09 15:08:12 +00005862
Douglas Gregor43959a92009-08-20 07:17:43 +00005863 if (!getDerived().AlwaysRebuild() &&
5864 TryBlock.get() == S->getTryBlock() &&
5865 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005866 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005867
John McCall9ae2f072010-08-23 23:25:46 +00005868 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005869 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005870}
Mike Stump1eb44332009-09-09 15:08:12 +00005871
Richard Smithad762fc2011-04-14 22:09:26 +00005872template<typename Derived>
5873StmtResult
5874TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5875 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5876 if (Range.isInvalid())
5877 return StmtError();
5878
5879 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5880 if (BeginEnd.isInvalid())
5881 return StmtError();
5882
5883 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5884 if (Cond.isInvalid())
5885 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005886 if (Cond.get())
5887 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5888 if (Cond.isInvalid())
5889 return StmtError();
5890 if (Cond.get())
5891 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005892
5893 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5894 if (Inc.isInvalid())
5895 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005896 if (Inc.get())
5897 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005898
5899 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5900 if (LoopVar.isInvalid())
5901 return StmtError();
5902
5903 StmtResult NewStmt = S;
5904 if (getDerived().AlwaysRebuild() ||
5905 Range.get() != S->getRangeStmt() ||
5906 BeginEnd.get() != S->getBeginEndStmt() ||
5907 Cond.get() != S->getCond() ||
5908 Inc.get() != S->getInc() ||
5909 LoopVar.get() != S->getLoopVarStmt())
5910 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5911 S->getColonLoc(), Range.get(),
5912 BeginEnd.get(), Cond.get(),
5913 Inc.get(), LoopVar.get(),
5914 S->getRParenLoc());
5915
5916 StmtResult Body = getDerived().TransformStmt(S->getBody());
5917 if (Body.isInvalid())
5918 return StmtError();
5919
5920 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5921 // it now so we have a new statement to attach the body to.
5922 if (Body.get() != S->getBody() && NewStmt.get() == S)
5923 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5924 S->getColonLoc(), Range.get(),
5925 BeginEnd.get(), Cond.get(),
5926 Inc.get(), LoopVar.get(),
5927 S->getRParenLoc());
5928
5929 if (NewStmt.get() == S)
5930 return SemaRef.Owned(S);
5931
5932 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5933}
5934
John Wiegley28bbe4b2011-04-28 01:08:34 +00005935template<typename Derived>
5936StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005937TreeTransform<Derived>::TransformMSDependentExistsStmt(
5938 MSDependentExistsStmt *S) {
5939 // Transform the nested-name-specifier, if any.
5940 NestedNameSpecifierLoc QualifierLoc;
5941 if (S->getQualifierLoc()) {
5942 QualifierLoc
5943 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5944 if (!QualifierLoc)
5945 return StmtError();
5946 }
5947
5948 // Transform the declaration name.
5949 DeclarationNameInfo NameInfo = S->getNameInfo();
5950 if (NameInfo.getName()) {
5951 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5952 if (!NameInfo.getName())
5953 return StmtError();
5954 }
5955
5956 // Check whether anything changed.
5957 if (!getDerived().AlwaysRebuild() &&
5958 QualifierLoc == S->getQualifierLoc() &&
5959 NameInfo.getName() == S->getNameInfo().getName())
5960 return S;
5961
5962 // Determine whether this name exists, if we can.
5963 CXXScopeSpec SS;
5964 SS.Adopt(QualifierLoc);
5965 bool Dependent = false;
5966 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5967 case Sema::IER_Exists:
5968 if (S->isIfExists())
5969 break;
5970
5971 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5972
5973 case Sema::IER_DoesNotExist:
5974 if (S->isIfNotExists())
5975 break;
5976
5977 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5978
5979 case Sema::IER_Dependent:
5980 Dependent = true;
5981 break;
Douglas Gregor65019ac2011-10-25 03:44:56 +00005982
5983 case Sema::IER_Error:
5984 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005985 }
5986
5987 // We need to continue with the instantiation, so do so now.
5988 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5989 if (SubStmt.isInvalid())
5990 return StmtError();
5991
5992 // If we have resolved the name, just transform to the substatement.
5993 if (!Dependent)
5994 return SubStmt;
5995
5996 // The name is still dependent, so build a dependent expression again.
5997 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5998 S->isIfExists(),
5999 QualifierLoc,
6000 NameInfo,
6001 SubStmt.get());
6002}
6003
6004template<typename Derived>
6005StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006006TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6007 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6008 if(TryBlock.isInvalid()) return StmtError();
6009
6010 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6011 if(!getDerived().AlwaysRebuild() &&
6012 TryBlock.get() == S->getTryBlock() &&
6013 Handler.get() == S->getHandler())
6014 return SemaRef.Owned(S);
6015
6016 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6017 S->getTryLoc(),
6018 TryBlock.take(),
6019 Handler.take());
6020}
6021
6022template<typename Derived>
6023StmtResult
6024TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6025 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6026 if(Block.isInvalid()) return StmtError();
6027
6028 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6029 Block.take());
6030}
6031
6032template<typename Derived>
6033StmtResult
6034TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6035 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6036 if(FilterExpr.isInvalid()) return StmtError();
6037
6038 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6039 if(Block.isInvalid()) return StmtError();
6040
6041 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6042 FilterExpr.take(),
6043 Block.take());
6044}
6045
6046template<typename Derived>
6047StmtResult
6048TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6049 if(isa<SEHFinallyStmt>(Handler))
6050 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6051 else
6052 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6053}
6054
Douglas Gregor43959a92009-08-20 07:17:43 +00006055//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006056// Expression transformation
6057//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006058template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006059ExprResult
John McCall454feb92009-12-08 09:21:05 +00006060TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006061 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006062}
Mike Stump1eb44332009-09-09 15:08:12 +00006063
6064template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006065ExprResult
John McCall454feb92009-12-08 09:21:05 +00006066TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006067 NestedNameSpecifierLoc QualifierLoc;
6068 if (E->getQualifierLoc()) {
6069 QualifierLoc
6070 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6071 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006072 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006073 }
John McCalldbd872f2009-12-08 09:08:17 +00006074
6075 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006076 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6077 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006078 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006079 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006080
John McCallec8045d2010-08-17 21:27:17 +00006081 DeclarationNameInfo NameInfo = E->getNameInfo();
6082 if (NameInfo.getName()) {
6083 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6084 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006085 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006086 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006087
6088 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006089 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006090 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006091 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006092 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006093
6094 // Mark it referenced in the new context regardless.
6095 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006096 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006097
John McCall3fa5cae2010-10-26 07:05:15 +00006098 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006099 }
John McCalldbd872f2009-12-08 09:08:17 +00006100
6101 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006102 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006103 TemplateArgs = &TransArgs;
6104 TransArgs.setLAngleLoc(E->getLAngleLoc());
6105 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006106 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6107 E->getNumTemplateArgs(),
6108 TransArgs))
6109 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006110 }
6111
Douglas Gregor40d96a62011-02-28 21:54:11 +00006112 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
6113 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006114}
Mike Stump1eb44332009-09-09 15:08:12 +00006115
Douglas Gregorb98b1992009-08-11 05:31:07 +00006116template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006117ExprResult
John McCall454feb92009-12-08 09:21:05 +00006118TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006119 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006120}
Mike Stump1eb44332009-09-09 15:08:12 +00006121
Douglas Gregorb98b1992009-08-11 05:31:07 +00006122template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006123ExprResult
John McCall454feb92009-12-08 09:21:05 +00006124TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006125 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006126}
Mike Stump1eb44332009-09-09 15:08:12 +00006127
Douglas Gregorb98b1992009-08-11 05:31:07 +00006128template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006129ExprResult
John McCall454feb92009-12-08 09:21:05 +00006130TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006131 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006132}
Mike Stump1eb44332009-09-09 15:08:12 +00006133
Douglas Gregorb98b1992009-08-11 05:31:07 +00006134template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006135ExprResult
John McCall454feb92009-12-08 09:21:05 +00006136TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006137 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006138}
Mike Stump1eb44332009-09-09 15:08:12 +00006139
Douglas Gregorb98b1992009-08-11 05:31:07 +00006140template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006141ExprResult
John McCall454feb92009-12-08 09:21:05 +00006142TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006143 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006144}
6145
6146template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006147ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006148TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6149 return SemaRef.MaybeBindToTemporary(E);
6150}
6151
6152template<typename Derived>
6153ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006154TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6155 ExprResult ControllingExpr =
6156 getDerived().TransformExpr(E->getControllingExpr());
6157 if (ControllingExpr.isInvalid())
6158 return ExprError();
6159
Chris Lattner686775d2011-07-20 06:58:45 +00006160 SmallVector<Expr *, 4> AssocExprs;
6161 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006162 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6163 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6164 if (TS) {
6165 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6166 if (!AssocType)
6167 return ExprError();
6168 AssocTypes.push_back(AssocType);
6169 } else {
6170 AssocTypes.push_back(0);
6171 }
6172
6173 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6174 if (AssocExpr.isInvalid())
6175 return ExprError();
6176 AssocExprs.push_back(AssocExpr.release());
6177 }
6178
6179 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6180 E->getDefaultLoc(),
6181 E->getRParenLoc(),
6182 ControllingExpr.release(),
6183 AssocTypes.data(),
6184 AssocExprs.data(),
6185 E->getNumAssocs());
6186}
6187
6188template<typename Derived>
6189ExprResult
John McCall454feb92009-12-08 09:21:05 +00006190TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006191 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006192 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006193 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006194
Douglas Gregorb98b1992009-08-11 05:31:07 +00006195 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006196 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006197
John McCall9ae2f072010-08-23 23:25:46 +00006198 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006199 E->getRParen());
6200}
6201
Mike Stump1eb44332009-09-09 15:08:12 +00006202template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006203ExprResult
John McCall454feb92009-12-08 09:21:05 +00006204TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006205 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006206 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006207 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006208
Douglas Gregorb98b1992009-08-11 05:31:07 +00006209 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006210 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006211
Douglas Gregorb98b1992009-08-11 05:31:07 +00006212 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6213 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006214 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006215}
Mike Stump1eb44332009-09-09 15:08:12 +00006216
Douglas Gregorb98b1992009-08-11 05:31:07 +00006217template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006218ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006219TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6220 // Transform the type.
6221 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6222 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006223 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006224
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006225 // Transform all of the components into components similar to what the
6226 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00006227 // FIXME: It would be slightly more efficient in the non-dependent case to
6228 // just map FieldDecls, rather than requiring the rebuilder to look for
6229 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006230 // template code that we don't care.
6231 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006232 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006233 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006234 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006235 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6236 const Node &ON = E->getComponent(I);
6237 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006238 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006239 Comp.LocStart = ON.getSourceRange().getBegin();
6240 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006241 switch (ON.getKind()) {
6242 case Node::Array: {
6243 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006244 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006245 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006246 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006247
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006248 ExprChanged = ExprChanged || Index.get() != FromIndex;
6249 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006250 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006251 break;
6252 }
Sean Huntc3021132010-05-05 15:23:54 +00006253
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006254 case Node::Field:
6255 case Node::Identifier:
6256 Comp.isBrackets = false;
6257 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006258 if (!Comp.U.IdentInfo)
6259 continue;
Sean Huntc3021132010-05-05 15:23:54 +00006260
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006261 break;
Sean Huntc3021132010-05-05 15:23:54 +00006262
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006263 case Node::Base:
6264 // Will be recomputed during the rebuild.
6265 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006266 }
Sean Huntc3021132010-05-05 15:23:54 +00006267
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006268 Components.push_back(Comp);
6269 }
Sean Huntc3021132010-05-05 15:23:54 +00006270
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006271 // If nothing changed, retain the existing expression.
6272 if (!getDerived().AlwaysRebuild() &&
6273 Type == E->getTypeSourceInfo() &&
6274 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006275 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006276
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006277 // Build a new offsetof expression.
6278 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6279 Components.data(), Components.size(),
6280 E->getRParenLoc());
6281}
6282
6283template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006284ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006285TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6286 assert(getDerived().AlreadyTransformed(E->getType()) &&
6287 "opaque value expression requires transformation");
6288 return SemaRef.Owned(E);
6289}
6290
6291template<typename Derived>
6292ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006293TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006294 // Rebuild the syntactic form. The original syntactic form has
6295 // opaque-value expressions in it, so strip those away and rebuild
6296 // the result. This is a really awful way of doing this, but the
6297 // better solution (rebuilding the semantic expressions and
6298 // rebinding OVEs as necessary) doesn't work; we'd need
6299 // TreeTransform to not strip away implicit conversions.
6300 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6301 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006302 if (result.isInvalid()) return ExprError();
6303
6304 // If that gives us a pseudo-object result back, the pseudo-object
6305 // expression must have been an lvalue-to-rvalue conversion which we
6306 // should reapply.
6307 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6308 result = SemaRef.checkPseudoObjectRValue(result.take());
6309
6310 return result;
6311}
6312
6313template<typename Derived>
6314ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006315TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6316 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006317 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006318 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006319
John McCalla93c9342009-12-07 02:54:59 +00006320 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006321 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006322 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006323
John McCall5ab75172009-11-04 07:28:41 +00006324 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006325 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006326
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006327 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6328 E->getKind(),
6329 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006330 }
Mike Stump1eb44332009-09-09 15:08:12 +00006331
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006332 // C++0x [expr.sizeof]p1:
6333 // The operand is either an expression, which is an unevaluated operand
6334 // [...]
6335 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006336
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006337 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6338 if (SubExpr.isInvalid())
6339 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006340
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006341 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6342 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006343
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006344 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6345 E->getOperatorLoc(),
6346 E->getKind(),
6347 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006348}
Mike Stump1eb44332009-09-09 15:08:12 +00006349
Douglas Gregorb98b1992009-08-11 05:31:07 +00006350template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006351ExprResult
John McCall454feb92009-12-08 09:21:05 +00006352TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006353 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006354 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006355 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006356
John McCall60d7b3a2010-08-24 06:29:42 +00006357 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006358 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006359 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006360
6361
Douglas Gregorb98b1992009-08-11 05:31:07 +00006362 if (!getDerived().AlwaysRebuild() &&
6363 LHS.get() == E->getLHS() &&
6364 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006365 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006366
John McCall9ae2f072010-08-23 23:25:46 +00006367 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006368 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006369 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006370 E->getRBracketLoc());
6371}
Mike Stump1eb44332009-09-09 15:08:12 +00006372
6373template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006374ExprResult
John McCall454feb92009-12-08 09:21:05 +00006375TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006376 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006377 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006378 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006379 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006380
6381 // Transform arguments.
6382 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006383 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006384 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6385 &ArgChanged))
6386 return ExprError();
6387
Douglas Gregorb98b1992009-08-11 05:31:07 +00006388 if (!getDerived().AlwaysRebuild() &&
6389 Callee.get() == E->getCallee() &&
6390 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006391 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006392
Douglas Gregorb98b1992009-08-11 05:31:07 +00006393 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006394 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006395 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006396 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006397 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006398 E->getRParenLoc());
6399}
Mike Stump1eb44332009-09-09 15:08:12 +00006400
6401template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006402ExprResult
John McCall454feb92009-12-08 09:21:05 +00006403TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006404 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006405 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006406 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006407
Douglas Gregor40d96a62011-02-28 21:54:11 +00006408 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006409 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006410 QualifierLoc
6411 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6412
6413 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006414 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006415 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006416 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006417
Eli Friedmanf595cc42009-12-04 06:40:45 +00006418 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006419 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6420 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006421 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006422 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006423
John McCall6bb80172010-03-30 21:47:33 +00006424 NamedDecl *FoundDecl = E->getFoundDecl();
6425 if (FoundDecl == E->getMemberDecl()) {
6426 FoundDecl = Member;
6427 } else {
6428 FoundDecl = cast_or_null<NamedDecl>(
6429 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6430 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006431 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006432 }
6433
Douglas Gregorb98b1992009-08-11 05:31:07 +00006434 if (!getDerived().AlwaysRebuild() &&
6435 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006436 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006437 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006438 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006439 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006440
Anders Carlsson1f240322009-12-22 05:24:09 +00006441 // Mark it referenced in the new context regardless.
6442 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006443 SemaRef.MarkMemberReferenced(E);
6444
John McCall3fa5cae2010-10-26 07:05:15 +00006445 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006446 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006447
John McCalld5532b62009-11-23 01:53:49 +00006448 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006449 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006450 TransArgs.setLAngleLoc(E->getLAngleLoc());
6451 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006452 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6453 E->getNumTemplateArgs(),
6454 TransArgs))
6455 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006456 }
Sean Huntc3021132010-05-05 15:23:54 +00006457
Douglas Gregorb98b1992009-08-11 05:31:07 +00006458 // FIXME: Bogus source location for the operator
6459 SourceLocation FakeOperatorLoc
6460 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6461
John McCallc2233c52010-01-15 08:34:02 +00006462 // FIXME: to do this check properly, we will need to preserve the
6463 // first-qualifier-in-scope here, just in case we had a dependent
6464 // base (and therefore couldn't do the check) and a
6465 // nested-name-qualifier (and therefore could do the lookup).
6466 NamedDecl *FirstQualifierInScope = 0;
6467
John McCall9ae2f072010-08-23 23:25:46 +00006468 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006469 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006470 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006471 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006472 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006473 Member,
John McCall6bb80172010-03-30 21:47:33 +00006474 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006475 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006476 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006477 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006478}
Mike Stump1eb44332009-09-09 15:08:12 +00006479
Douglas Gregorb98b1992009-08-11 05:31:07 +00006480template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006481ExprResult
John McCall454feb92009-12-08 09:21:05 +00006482TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006483 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006485 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006486
John McCall60d7b3a2010-08-24 06:29:42 +00006487 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006488 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006489 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006490
Douglas Gregorb98b1992009-08-11 05:31:07 +00006491 if (!getDerived().AlwaysRebuild() &&
6492 LHS.get() == E->getLHS() &&
6493 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006494 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006495
Douglas Gregorb98b1992009-08-11 05:31:07 +00006496 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006497 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006498}
6499
Mike Stump1eb44332009-09-09 15:08:12 +00006500template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006501ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006502TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006503 CompoundAssignOperator *E) {
6504 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006505}
Mike Stump1eb44332009-09-09 15:08:12 +00006506
Douglas Gregorb98b1992009-08-11 05:31:07 +00006507template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006508ExprResult TreeTransform<Derived>::
6509TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6510 // Just rebuild the common and RHS expressions and see whether we
6511 // get any changes.
6512
6513 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6514 if (commonExpr.isInvalid())
6515 return ExprError();
6516
6517 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6518 if (rhs.isInvalid())
6519 return ExprError();
6520
6521 if (!getDerived().AlwaysRebuild() &&
6522 commonExpr.get() == e->getCommon() &&
6523 rhs.get() == e->getFalseExpr())
6524 return SemaRef.Owned(e);
6525
6526 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6527 e->getQuestionLoc(),
6528 0,
6529 e->getColonLoc(),
6530 rhs.get());
6531}
6532
6533template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006534ExprResult
John McCall454feb92009-12-08 09:21:05 +00006535TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006536 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006537 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006538 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006539
John McCall60d7b3a2010-08-24 06:29:42 +00006540 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006541 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006542 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006543
John McCall60d7b3a2010-08-24 06:29:42 +00006544 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006545 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006546 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006547
Douglas Gregorb98b1992009-08-11 05:31:07 +00006548 if (!getDerived().AlwaysRebuild() &&
6549 Cond.get() == E->getCond() &&
6550 LHS.get() == E->getLHS() &&
6551 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006552 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006553
John McCall9ae2f072010-08-23 23:25:46 +00006554 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006555 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006556 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006557 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006558 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006559}
Mike Stump1eb44332009-09-09 15:08:12 +00006560
6561template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006562ExprResult
John McCall454feb92009-12-08 09:21:05 +00006563TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006564 // Implicit casts are eliminated during transformation, since they
6565 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006566 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006567}
Mike Stump1eb44332009-09-09 15:08:12 +00006568
Douglas Gregorb98b1992009-08-11 05:31:07 +00006569template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006570ExprResult
John McCall454feb92009-12-08 09:21:05 +00006571TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006572 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6573 if (!Type)
6574 return ExprError();
6575
John McCall60d7b3a2010-08-24 06:29:42 +00006576 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006577 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006578 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006579 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006580
Douglas Gregorb98b1992009-08-11 05:31:07 +00006581 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006582 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006583 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006584 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006585
John McCall9d125032010-01-15 18:39:57 +00006586 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006587 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006588 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006589 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006590}
Mike Stump1eb44332009-09-09 15:08:12 +00006591
Douglas Gregorb98b1992009-08-11 05:31:07 +00006592template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006593ExprResult
John McCall454feb92009-12-08 09:21:05 +00006594TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006595 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6596 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6597 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006598 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006599
John McCall60d7b3a2010-08-24 06:29:42 +00006600 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006601 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006602 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006603
Douglas Gregorb98b1992009-08-11 05:31:07 +00006604 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006605 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006606 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006607 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006608
John McCall1d7d8d62010-01-19 22:33:45 +00006609 // Note: the expression type doesn't necessarily match the
6610 // type-as-written, but that's okay, because it should always be
6611 // derivable from the initializer.
6612
John McCall42f56b52010-01-18 19:35:47 +00006613 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006614 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006615 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006616}
Mike Stump1eb44332009-09-09 15:08:12 +00006617
Douglas Gregorb98b1992009-08-11 05:31:07 +00006618template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006619ExprResult
John McCall454feb92009-12-08 09:21:05 +00006620TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006621 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006622 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006623 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006624
Douglas Gregorb98b1992009-08-11 05:31:07 +00006625 if (!getDerived().AlwaysRebuild() &&
6626 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006627 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006628
Douglas Gregorb98b1992009-08-11 05:31:07 +00006629 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006630 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006632 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633 E->getAccessorLoc(),
6634 E->getAccessor());
6635}
Mike Stump1eb44332009-09-09 15:08:12 +00006636
Douglas Gregorb98b1992009-08-11 05:31:07 +00006637template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006638ExprResult
John McCall454feb92009-12-08 09:21:05 +00006639TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006641
John McCallca0408f2010-08-23 06:44:23 +00006642 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006643 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6644 Inits, &InitChanged))
6645 return ExprError();
6646
Douglas Gregorb98b1992009-08-11 05:31:07 +00006647 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006648 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006649
Douglas Gregorb98b1992009-08-11 05:31:07 +00006650 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006651 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006652}
Mike Stump1eb44332009-09-09 15:08:12 +00006653
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006655ExprResult
John McCall454feb92009-12-08 09:21:05 +00006656TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006657 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006658
Douglas Gregor43959a92009-08-20 07:17:43 +00006659 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006660 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006661 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006662 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006663
Douglas Gregor43959a92009-08-20 07:17:43 +00006664 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006665 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006666 bool ExprChanged = false;
6667 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6668 DEnd = E->designators_end();
6669 D != DEnd; ++D) {
6670 if (D->isFieldDesignator()) {
6671 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6672 D->getDotLoc(),
6673 D->getFieldLoc()));
6674 continue;
6675 }
Mike Stump1eb44332009-09-09 15:08:12 +00006676
Douglas Gregorb98b1992009-08-11 05:31:07 +00006677 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006678 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006679 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006680 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006681
6682 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006683 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006684
Douglas Gregorb98b1992009-08-11 05:31:07 +00006685 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6686 ArrayExprs.push_back(Index.release());
6687 continue;
6688 }
Mike Stump1eb44332009-09-09 15:08:12 +00006689
Douglas Gregorb98b1992009-08-11 05:31:07 +00006690 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006691 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6693 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006694 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006695
John McCall60d7b3a2010-08-24 06:29:42 +00006696 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006697 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006698 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006699
6700 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006701 End.get(),
6702 D->getLBracketLoc(),
6703 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006704
Douglas Gregorb98b1992009-08-11 05:31:07 +00006705 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6706 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006707
Douglas Gregorb98b1992009-08-11 05:31:07 +00006708 ArrayExprs.push_back(Start.release());
6709 ArrayExprs.push_back(End.release());
6710 }
Mike Stump1eb44332009-09-09 15:08:12 +00006711
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712 if (!getDerived().AlwaysRebuild() &&
6713 Init.get() == E->getInit() &&
6714 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006715 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006716
Douglas Gregorb98b1992009-08-11 05:31:07 +00006717 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6718 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006719 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006720}
Mike Stump1eb44332009-09-09 15:08:12 +00006721
Douglas Gregorb98b1992009-08-11 05:31:07 +00006722template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006723ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006724TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006725 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006726 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006727
Douglas Gregor5557b252009-10-28 00:29:27 +00006728 // FIXME: Will we ever have proper type location here? Will we actually
6729 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006730 QualType T = getDerived().TransformType(E->getType());
6731 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006732 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006733
Douglas Gregorb98b1992009-08-11 05:31:07 +00006734 if (!getDerived().AlwaysRebuild() &&
6735 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006736 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006737
Douglas Gregorb98b1992009-08-11 05:31:07 +00006738 return getDerived().RebuildImplicitValueInitExpr(T);
6739}
Mike Stump1eb44332009-09-09 15:08:12 +00006740
Douglas Gregorb98b1992009-08-11 05:31:07 +00006741template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006742ExprResult
John McCall454feb92009-12-08 09:21:05 +00006743TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006744 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6745 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006746 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006747
John McCall60d7b3a2010-08-24 06:29:42 +00006748 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006749 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006750 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006751
Douglas Gregorb98b1992009-08-11 05:31:07 +00006752 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006753 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006754 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006755 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006756
John McCall9ae2f072010-08-23 23:25:46 +00006757 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006758 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006759}
6760
6761template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006762ExprResult
John McCall454feb92009-12-08 09:21:05 +00006763TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006764 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006765 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006766 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6767 &ArgumentChanged))
6768 return ExprError();
6769
Douglas Gregorb98b1992009-08-11 05:31:07 +00006770 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6771 move_arg(Inits),
6772 E->getRParenLoc());
6773}
Mike Stump1eb44332009-09-09 15:08:12 +00006774
Douglas Gregorb98b1992009-08-11 05:31:07 +00006775/// \brief Transform an address-of-label expression.
6776///
6777/// By default, the transformation of an address-of-label expression always
6778/// rebuilds the expression, so that the label identifier can be resolved to
6779/// the corresponding label statement by semantic analysis.
6780template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006781ExprResult
John McCall454feb92009-12-08 09:21:05 +00006782TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006783 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6784 E->getLabel());
6785 if (!LD)
6786 return ExprError();
6787
Douglas Gregorb98b1992009-08-11 05:31:07 +00006788 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006789 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006790}
Mike Stump1eb44332009-09-09 15:08:12 +00006791
6792template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006793ExprResult
John McCall454feb92009-12-08 09:21:05 +00006794TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006795 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006796 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006797 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006798 if (SubStmt.isInvalid()) {
6799 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006800 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006801 }
Mike Stump1eb44332009-09-09 15:08:12 +00006802
Douglas Gregorb98b1992009-08-11 05:31:07 +00006803 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006804 SubStmt.get() == E->getSubStmt()) {
6805 // Calling this an 'error' is unintuitive, but it does the right thing.
6806 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006807 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006808 }
Mike Stump1eb44332009-09-09 15:08:12 +00006809
6810 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006811 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006812 E->getRParenLoc());
6813}
Mike Stump1eb44332009-09-09 15:08:12 +00006814
Douglas Gregorb98b1992009-08-11 05:31:07 +00006815template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006816ExprResult
John McCall454feb92009-12-08 09:21:05 +00006817TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006818 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006819 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006820 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006821
John McCall60d7b3a2010-08-24 06:29:42 +00006822 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006823 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006824 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006825
John McCall60d7b3a2010-08-24 06:29:42 +00006826 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006827 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006828 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006829
Douglas Gregorb98b1992009-08-11 05:31:07 +00006830 if (!getDerived().AlwaysRebuild() &&
6831 Cond.get() == E->getCond() &&
6832 LHS.get() == E->getLHS() &&
6833 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006834 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006835
Douglas Gregorb98b1992009-08-11 05:31:07 +00006836 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006837 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006838 E->getRParenLoc());
6839}
Mike Stump1eb44332009-09-09 15:08:12 +00006840
Douglas Gregorb98b1992009-08-11 05:31:07 +00006841template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006842ExprResult
John McCall454feb92009-12-08 09:21:05 +00006843TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006844 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006845}
6846
6847template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006848ExprResult
John McCall454feb92009-12-08 09:21:05 +00006849TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006850 switch (E->getOperator()) {
6851 case OO_New:
6852 case OO_Delete:
6853 case OO_Array_New:
6854 case OO_Array_Delete:
6855 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Sean Huntc3021132010-05-05 15:23:54 +00006856
Douglas Gregor668d6d92009-12-13 20:44:55 +00006857 case OO_Call: {
6858 // This is a call to an object's operator().
6859 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6860
6861 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006862 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006863 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006864 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006865
6866 // FIXME: Poor location information
6867 SourceLocation FakeLParenLoc
6868 = SemaRef.PP.getLocForEndOfToken(
6869 static_cast<Expr *>(Object.get())->getLocEnd());
6870
6871 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006872 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006873 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6874 Args))
6875 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006876
John McCall9ae2f072010-08-23 23:25:46 +00006877 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006878 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006879 E->getLocEnd());
6880 }
6881
6882#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6883 case OO_##Name:
6884#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6885#include "clang/Basic/OperatorKinds.def"
6886 case OO_Subscript:
6887 // Handled below.
6888 break;
6889
6890 case OO_Conditional:
6891 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006892
6893 case OO_None:
6894 case NUM_OVERLOADED_OPERATORS:
6895 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006896 }
6897
John McCall60d7b3a2010-08-24 06:29:42 +00006898 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006899 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006900 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006901
John McCall60d7b3a2010-08-24 06:29:42 +00006902 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006903 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006904 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006905
John McCall60d7b3a2010-08-24 06:29:42 +00006906 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006907 if (E->getNumArgs() == 2) {
6908 Second = getDerived().TransformExpr(E->getArg(1));
6909 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006910 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006911 }
Mike Stump1eb44332009-09-09 15:08:12 +00006912
Douglas Gregorb98b1992009-08-11 05:31:07 +00006913 if (!getDerived().AlwaysRebuild() &&
6914 Callee.get() == E->getCallee() &&
6915 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006916 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006917 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006918
Douglas Gregorb98b1992009-08-11 05:31:07 +00006919 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6920 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006921 Callee.get(),
6922 First.get(),
6923 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006924}
Mike Stump1eb44332009-09-09 15:08:12 +00006925
Douglas Gregorb98b1992009-08-11 05:31:07 +00006926template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006927ExprResult
John McCall454feb92009-12-08 09:21:05 +00006928TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6929 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006930}
Mike Stump1eb44332009-09-09 15:08:12 +00006931
Douglas Gregorb98b1992009-08-11 05:31:07 +00006932template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006933ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006934TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6935 // Transform the callee.
6936 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6937 if (Callee.isInvalid())
6938 return ExprError();
6939
6940 // Transform exec config.
6941 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6942 if (EC.isInvalid())
6943 return ExprError();
6944
6945 // Transform arguments.
6946 bool ArgChanged = false;
6947 ASTOwningVector<Expr*> Args(SemaRef);
6948 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6949 &ArgChanged))
6950 return ExprError();
6951
6952 if (!getDerived().AlwaysRebuild() &&
6953 Callee.get() == E->getCallee() &&
6954 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006955 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006956
6957 // FIXME: Wrong source location information for the '('.
6958 SourceLocation FakeLParenLoc
6959 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6960 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6961 move_arg(Args),
6962 E->getRParenLoc(), EC.get());
6963}
6964
6965template<typename Derived>
6966ExprResult
John McCall454feb92009-12-08 09:21:05 +00006967TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006968 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6969 if (!Type)
6970 return ExprError();
6971
John McCall60d7b3a2010-08-24 06:29:42 +00006972 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006973 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006974 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006975 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006976
Douglas Gregorb98b1992009-08-11 05:31:07 +00006977 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006978 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006979 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006980 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006981
Douglas Gregorb98b1992009-08-11 05:31:07 +00006982 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006983 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006984 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6985 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6986 SourceLocation FakeRParenLoc
6987 = SemaRef.PP.getLocForEndOfToken(
6988 E->getSubExpr()->getSourceRange().getEnd());
6989 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006990 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006991 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006992 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006993 FakeRAngleLoc,
6994 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006995 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006996 FakeRParenLoc);
6997}
Mike Stump1eb44332009-09-09 15:08:12 +00006998
Douglas Gregorb98b1992009-08-11 05:31:07 +00006999template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007000ExprResult
John McCall454feb92009-12-08 09:21:05 +00007001TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7002 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007003}
Mike Stump1eb44332009-09-09 15:08:12 +00007004
7005template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007006ExprResult
John McCall454feb92009-12-08 09:21:05 +00007007TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7008 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007009}
7010
Douglas Gregorb98b1992009-08-11 05:31:07 +00007011template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007012ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007013TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007014 CXXReinterpretCastExpr *E) {
7015 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007016}
Mike Stump1eb44332009-09-09 15:08:12 +00007017
Douglas Gregorb98b1992009-08-11 05:31:07 +00007018template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007019ExprResult
John McCall454feb92009-12-08 09:21:05 +00007020TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7021 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007022}
Mike Stump1eb44332009-09-09 15:08:12 +00007023
Douglas Gregorb98b1992009-08-11 05:31:07 +00007024template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007025ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007026TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007027 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007028 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7029 if (!Type)
7030 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007031
John McCall60d7b3a2010-08-24 06:29:42 +00007032 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007033 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007034 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007035 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007036
Douglas Gregorb98b1992009-08-11 05:31:07 +00007037 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007038 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007039 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007040 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007041
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007042 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007043 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007044 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007045 E->getRParenLoc());
7046}
Mike Stump1eb44332009-09-09 15:08:12 +00007047
Douglas Gregorb98b1992009-08-11 05:31:07 +00007048template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007049ExprResult
John McCall454feb92009-12-08 09:21:05 +00007050TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007051 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007052 TypeSourceInfo *TInfo
7053 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7054 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007055 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007056
Douglas Gregorb98b1992009-08-11 05:31:07 +00007057 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007058 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007059 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007060
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007061 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7062 E->getLocStart(),
7063 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007064 E->getLocEnd());
7065 }
Mike Stump1eb44332009-09-09 15:08:12 +00007066
Eli Friedmanef331b72012-01-20 01:26:23 +00007067 // We don't know whether the subexpression is potentially evaluated until
7068 // after we perform semantic analysis. We speculatively assume it is
7069 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007070 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00007071 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00007072
John McCall60d7b3a2010-08-24 06:29:42 +00007073 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007074 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007075 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007076
Douglas Gregorb98b1992009-08-11 05:31:07 +00007077 if (!getDerived().AlwaysRebuild() &&
7078 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007079 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007080
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007081 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7082 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007083 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007084 E->getLocEnd());
7085}
7086
7087template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007088ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007089TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7090 if (E->isTypeOperand()) {
7091 TypeSourceInfo *TInfo
7092 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7093 if (!TInfo)
7094 return ExprError();
7095
7096 if (!getDerived().AlwaysRebuild() &&
7097 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007098 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007099
Douglas Gregor3c52a212011-03-06 17:40:41 +00007100 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007101 E->getLocStart(),
7102 TInfo,
7103 E->getLocEnd());
7104 }
7105
Francois Pichet01b7c302010-09-08 12:20:18 +00007106 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7107
7108 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7109 if (SubExpr.isInvalid())
7110 return ExprError();
7111
7112 if (!getDerived().AlwaysRebuild() &&
7113 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007114 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007115
7116 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7117 E->getLocStart(),
7118 SubExpr.get(),
7119 E->getLocEnd());
7120}
7121
7122template<typename Derived>
7123ExprResult
John McCall454feb92009-12-08 09:21:05 +00007124TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *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
Douglas Gregorb98b1992009-08-11 05:31:07 +00007130TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007131 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007132 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007133}
Mike Stump1eb44332009-09-09 15:08:12 +00007134
Douglas Gregorb98b1992009-08-11 05:31:07 +00007135template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007136ExprResult
John McCall454feb92009-12-08 09:21:05 +00007137TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007138 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007139 QualType T;
7140 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7141 T = MD->getThisType(getSema().Context);
7142 else
7143 T = getSema().Context.getPointerType(
7144 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007145
Douglas Gregorec79d872012-02-24 17:41:38 +00007146 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7147 // Make sure that we capture 'this'.
7148 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007149 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007150 }
7151
Douglas Gregor828a1972010-01-07 23:12:05 +00007152 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007153}
Mike Stump1eb44332009-09-09 15:08:12 +00007154
Douglas Gregorb98b1992009-08-11 05:31:07 +00007155template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007156ExprResult
John McCall454feb92009-12-08 09:21:05 +00007157TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007158 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007159 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007160 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007161
Douglas Gregorb98b1992009-08-11 05:31:07 +00007162 if (!getDerived().AlwaysRebuild() &&
7163 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007164 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007165
Douglas Gregorbca01b42011-07-06 22:04:06 +00007166 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7167 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007168}
Mike Stump1eb44332009-09-09 15:08:12 +00007169
Douglas Gregorb98b1992009-08-11 05:31:07 +00007170template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007171ExprResult
John McCall454feb92009-12-08 09:21:05 +00007172TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007173 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007174 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7175 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007176 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007177 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007178
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007179 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007180 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007181 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007182
Douglas Gregor036aed12009-12-23 23:03:06 +00007183 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007184}
Mike Stump1eb44332009-09-09 15:08:12 +00007185
Douglas Gregorb98b1992009-08-11 05:31:07 +00007186template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007187ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007188TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7189 CXXScalarValueInitExpr *E) {
7190 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7191 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007192 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00007193
Douglas Gregorb98b1992009-08-11 05:31:07 +00007194 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007195 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007196 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007197
Douglas Gregorab6677e2010-09-08 00:15:04 +00007198 return getDerived().RebuildCXXScalarValueInitExpr(T,
7199 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007200 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007201}
Mike Stump1eb44332009-09-09 15:08:12 +00007202
Douglas Gregorb98b1992009-08-11 05:31:07 +00007203template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007204ExprResult
John McCall454feb92009-12-08 09:21:05 +00007205TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007206 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007207 TypeSourceInfo *AllocTypeInfo
7208 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7209 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007210 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007211
Douglas Gregorb98b1992009-08-11 05:31:07 +00007212 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007213 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007214 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007215 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007216
Douglas Gregorb98b1992009-08-11 05:31:07 +00007217 // Transform the placement arguments (if any).
7218 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007219 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007220 if (getDerived().TransformExprs(E->getPlacementArgs(),
7221 E->getNumPlacementArgs(), true,
7222 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007223 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007224
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007225 // Transform the initializer (if any).
7226 Expr *OldInit = E->getInitializer();
7227 ExprResult NewInit;
7228 if (OldInit)
7229 NewInit = getDerived().TransformExpr(OldInit);
7230 if (NewInit.isInvalid())
7231 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007232
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007233 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007234 FunctionDecl *OperatorNew = 0;
7235 if (E->getOperatorNew()) {
7236 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007237 getDerived().TransformDecl(E->getLocStart(),
7238 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007239 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007240 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007241 }
7242
7243 FunctionDecl *OperatorDelete = 0;
7244 if (E->getOperatorDelete()) {
7245 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007246 getDerived().TransformDecl(E->getLocStart(),
7247 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007248 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007249 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007250 }
Sean Huntc3021132010-05-05 15:23:54 +00007251
Douglas Gregorb98b1992009-08-11 05:31:07 +00007252 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007253 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007254 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007255 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007256 OperatorNew == E->getOperatorNew() &&
7257 OperatorDelete == E->getOperatorDelete() &&
7258 !ArgumentChanged) {
7259 // Mark any declarations we need as referenced.
7260 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007261 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007262 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007263 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007264 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007265
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007266 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007267 QualType ElementType
7268 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7269 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7270 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7271 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007272 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007273 }
7274 }
7275 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007276
John McCall3fa5cae2010-10-26 07:05:15 +00007277 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007278 }
Mike Stump1eb44332009-09-09 15:08:12 +00007279
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007280 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007281 if (!ArraySize.get()) {
7282 // If no array size was specified, but the new expression was
7283 // instantiated with an array type (e.g., "new T" where T is
7284 // instantiated with "int[4]"), extract the outer bound from the
7285 // array type as our array size. We do this with constant and
7286 // dependently-sized array types.
7287 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7288 if (!ArrayT) {
7289 // Do nothing
7290 } else if (const ConstantArrayType *ConsArrayT
7291 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007292 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007293 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7294 ConsArrayT->getSize(),
7295 SemaRef.Context.getSizeType(),
7296 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007297 AllocType = ConsArrayT->getElementType();
7298 } else if (const DependentSizedArrayType *DepArrayT
7299 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7300 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007301 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007302 AllocType = DepArrayT->getElementType();
7303 }
7304 }
7305 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007306
Douglas Gregorb98b1992009-08-11 05:31:07 +00007307 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7308 E->isGlobalNew(),
7309 /*FIXME:*/E->getLocStart(),
7310 move_arg(PlacementArgs),
7311 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007312 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007313 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007314 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007315 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007316 E->getDirectInitRange(),
7317 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007318}
Mike Stump1eb44332009-09-09 15:08:12 +00007319
Douglas Gregorb98b1992009-08-11 05:31:07 +00007320template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007321ExprResult
John McCall454feb92009-12-08 09:21:05 +00007322TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007323 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007324 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007325 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007326
Douglas Gregor1af74512010-02-26 00:38:10 +00007327 // Transform the delete operator, if known.
7328 FunctionDecl *OperatorDelete = 0;
7329 if (E->getOperatorDelete()) {
7330 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007331 getDerived().TransformDecl(E->getLocStart(),
7332 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007333 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007334 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007335 }
Sean Huntc3021132010-05-05 15:23:54 +00007336
Douglas Gregorb98b1992009-08-11 05:31:07 +00007337 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007338 Operand.get() == E->getArgument() &&
7339 OperatorDelete == E->getOperatorDelete()) {
7340 // Mark any declarations we need as referenced.
7341 // FIXME: instantiation-specific.
7342 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007343 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007344
7345 if (!E->getArgument()->isTypeDependent()) {
7346 QualType Destroyed = SemaRef.Context.getBaseElementType(
7347 E->getDestroyedType());
7348 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7349 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Eli Friedman5f2987c2012-02-02 03:46:19 +00007350 SemaRef.MarkFunctionReferenced(E->getLocStart(),
7351 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007352 }
7353 }
7354
John McCall3fa5cae2010-10-26 07:05:15 +00007355 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007356 }
Mike Stump1eb44332009-09-09 15:08:12 +00007357
Douglas Gregorb98b1992009-08-11 05:31:07 +00007358 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7359 E->isGlobalDelete(),
7360 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007361 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007362}
Mike Stump1eb44332009-09-09 15:08:12 +00007363
Douglas Gregorb98b1992009-08-11 05:31:07 +00007364template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007365ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007366TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007367 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007368 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007369 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007370 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007371
John McCallb3d87482010-08-24 05:47:05 +00007372 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007373 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007374 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007375 E->getOperatorLoc(),
7376 E->isArrow()? tok::arrow : tok::period,
7377 ObjectTypePtr,
7378 MayBePseudoDestructor);
7379 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007380 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007381
John McCallb3d87482010-08-24 05:47:05 +00007382 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007383 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7384 if (QualifierLoc) {
7385 QualifierLoc
7386 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7387 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007388 return ExprError();
7389 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007390 CXXScopeSpec SS;
7391 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007392
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007393 PseudoDestructorTypeStorage Destroyed;
7394 if (E->getDestroyedTypeInfo()) {
7395 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007396 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007397 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007398 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007399 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007400 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007401 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007402 // We aren't likely to be able to resolve the identifier down to a type
7403 // now anyway, so just retain the identifier.
7404 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7405 E->getDestroyedTypeLoc());
7406 } else {
7407 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007408 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007409 *E->getDestroyedTypeIdentifier(),
7410 E->getDestroyedTypeLoc(),
7411 /*Scope=*/0,
7412 SS, ObjectTypePtr,
7413 false);
7414 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007415 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007416
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007417 Destroyed
7418 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7419 E->getDestroyedTypeLoc());
7420 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007421
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007422 TypeSourceInfo *ScopeTypeInfo = 0;
7423 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007424 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007425 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007426 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007427 }
Sean Huntc3021132010-05-05 15:23:54 +00007428
John McCall9ae2f072010-08-23 23:25:46 +00007429 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007430 E->getOperatorLoc(),
7431 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007432 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007433 ScopeTypeInfo,
7434 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007435 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007436 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007437}
Mike Stump1eb44332009-09-09 15:08:12 +00007438
Douglas Gregora71d8192009-09-04 17:36:40 +00007439template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007440ExprResult
John McCallba135432009-11-21 08:51:07 +00007441TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007442 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007443 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7444 Sema::LookupOrdinaryName);
7445
7446 // Transform all the decls.
7447 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7448 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007449 NamedDecl *InstD = static_cast<NamedDecl*>(
7450 getDerived().TransformDecl(Old->getNameLoc(),
7451 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007452 if (!InstD) {
7453 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7454 // This can happen because of dependent hiding.
7455 if (isa<UsingShadowDecl>(*I))
7456 continue;
7457 else
John McCallf312b1e2010-08-26 23:41:50 +00007458 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007459 }
John McCallf7a1a742009-11-24 19:00:30 +00007460
7461 // Expand using declarations.
7462 if (isa<UsingDecl>(InstD)) {
7463 UsingDecl *UD = cast<UsingDecl>(InstD);
7464 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7465 E = UD->shadow_end(); I != E; ++I)
7466 R.addDecl(*I);
7467 continue;
7468 }
7469
7470 R.addDecl(InstD);
7471 }
7472
7473 // Resolve a kind, but don't do any further analysis. If it's
7474 // ambiguous, the callee needs to deal with it.
7475 R.resolveKind();
7476
7477 // Rebuild the nested-name qualifier, if present.
7478 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007479 if (Old->getQualifierLoc()) {
7480 NestedNameSpecifierLoc QualifierLoc
7481 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7482 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007483 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007484
Douglas Gregor4c9be892011-02-28 20:01:57 +00007485 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007486 }
7487
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007488 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007489 CXXRecordDecl *NamingClass
7490 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7491 Old->getNameLoc(),
7492 Old->getNamingClass()));
7493 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007494 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007495
Douglas Gregor66c45152010-04-27 16:10:10 +00007496 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007497 }
7498
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007499 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7500
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007501 // If we have neither explicit template arguments, nor the template keyword,
7502 // it's a normal declaration name.
7503 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007504 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7505
7506 // If we have template arguments, rebuild them, then rebuild the
7507 // templateid expression.
7508 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007509 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7510 Old->getNumTemplateArgs(),
7511 TransArgs))
7512 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007513
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007514 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007515 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007516}
Mike Stump1eb44332009-09-09 15:08:12 +00007517
Douglas Gregorb98b1992009-08-11 05:31:07 +00007518template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007519ExprResult
John McCall454feb92009-12-08 09:21:05 +00007520TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007521 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7522 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007523 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007524
Douglas Gregorb98b1992009-08-11 05:31:07 +00007525 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007526 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007527 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007528
Mike Stump1eb44332009-09-09 15:08:12 +00007529 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007530 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007531 T,
7532 E->getLocEnd());
7533}
Mike Stump1eb44332009-09-09 15:08:12 +00007534
Douglas Gregorb98b1992009-08-11 05:31:07 +00007535template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007536ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007537TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7538 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7539 if (!LhsT)
7540 return ExprError();
7541
7542 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7543 if (!RhsT)
7544 return ExprError();
7545
7546 if (!getDerived().AlwaysRebuild() &&
7547 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7548 return SemaRef.Owned(E);
7549
7550 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7551 E->getLocStart(),
7552 LhsT, RhsT,
7553 E->getLocEnd());
7554}
7555
7556template<typename Derived>
7557ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007558TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7559 bool ArgChanged = false;
7560 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7561 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7562 TypeSourceInfo *From = E->getArg(I);
7563 TypeLoc FromTL = From->getTypeLoc();
7564 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7565 TypeLocBuilder TLB;
7566 TLB.reserve(FromTL.getFullDataSize());
7567 QualType To = getDerived().TransformType(TLB, FromTL);
7568 if (To.isNull())
7569 return ExprError();
7570
7571 if (To == From->getType())
7572 Args.push_back(From);
7573 else {
7574 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7575 ArgChanged = true;
7576 }
7577 continue;
7578 }
7579
7580 ArgChanged = true;
7581
7582 // We have a pack expansion. Instantiate it.
7583 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
7584 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7585 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7586 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
7587
7588 // Determine whether the set of unexpanded parameter packs can and should
7589 // be expanded.
7590 bool Expand = true;
7591 bool RetainExpansion = false;
7592 llvm::Optional<unsigned> OrigNumExpansions
7593 = ExpansionTL.getTypePtr()->getNumExpansions();
7594 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7595 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7596 PatternTL.getSourceRange(),
7597 Unexpanded,
7598 Expand, RetainExpansion,
7599 NumExpansions))
7600 return ExprError();
7601
7602 if (!Expand) {
7603 // The transform has determined that we should perform a simple
7604 // transformation on the pack expansion, producing another pack
7605 // expansion.
7606 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7607
7608 TypeLocBuilder TLB;
7609 TLB.reserve(From->getTypeLoc().getFullDataSize());
7610
7611 QualType To = getDerived().TransformType(TLB, PatternTL);
7612 if (To.isNull())
7613 return ExprError();
7614
7615 To = getDerived().RebuildPackExpansionType(To,
7616 PatternTL.getSourceRange(),
7617 ExpansionTL.getEllipsisLoc(),
7618 NumExpansions);
7619 if (To.isNull())
7620 return ExprError();
7621
7622 PackExpansionTypeLoc ToExpansionTL
7623 = TLB.push<PackExpansionTypeLoc>(To);
7624 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7625 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7626 continue;
7627 }
7628
7629 // Expand the pack expansion by substituting for each argument in the
7630 // pack(s).
7631 for (unsigned I = 0; I != *NumExpansions; ++I) {
7632 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7633 TypeLocBuilder TLB;
7634 TLB.reserve(PatternTL.getFullDataSize());
7635 QualType To = getDerived().TransformType(TLB, PatternTL);
7636 if (To.isNull())
7637 return ExprError();
7638
7639 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7640 }
7641
7642 if (!RetainExpansion)
7643 continue;
7644
7645 // If we're supposed to retain a pack expansion, do so by temporarily
7646 // forgetting the partially-substituted parameter pack.
7647 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7648
7649 TypeLocBuilder TLB;
7650 TLB.reserve(From->getTypeLoc().getFullDataSize());
7651
7652 QualType To = getDerived().TransformType(TLB, PatternTL);
7653 if (To.isNull())
7654 return ExprError();
7655
7656 To = getDerived().RebuildPackExpansionType(To,
7657 PatternTL.getSourceRange(),
7658 ExpansionTL.getEllipsisLoc(),
7659 NumExpansions);
7660 if (To.isNull())
7661 return ExprError();
7662
7663 PackExpansionTypeLoc ToExpansionTL
7664 = TLB.push<PackExpansionTypeLoc>(To);
7665 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7666 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7667 }
7668
7669 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7670 return SemaRef.Owned(E);
7671
7672 return getDerived().RebuildTypeTrait(E->getTrait(),
7673 E->getLocStart(),
7674 Args,
7675 E->getLocEnd());
7676}
7677
7678template<typename Derived>
7679ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007680TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7681 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7682 if (!T)
7683 return ExprError();
7684
7685 if (!getDerived().AlwaysRebuild() &&
7686 T == E->getQueriedTypeSourceInfo())
7687 return SemaRef.Owned(E);
7688
7689 ExprResult SubExpr;
7690 {
7691 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7692 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7693 if (SubExpr.isInvalid())
7694 return ExprError();
7695
7696 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7697 return SemaRef.Owned(E);
7698 }
7699
7700 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7701 E->getLocStart(),
7702 T,
7703 SubExpr.get(),
7704 E->getLocEnd());
7705}
7706
7707template<typename Derived>
7708ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007709TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7710 ExprResult SubExpr;
7711 {
7712 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7713 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7714 if (SubExpr.isInvalid())
7715 return ExprError();
7716
7717 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7718 return SemaRef.Owned(E);
7719 }
7720
7721 return getDerived().RebuildExpressionTrait(
7722 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7723}
7724
7725template<typename Derived>
7726ExprResult
John McCall865d4472009-11-19 22:55:06 +00007727TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007728 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007729 NestedNameSpecifierLoc QualifierLoc
7730 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7731 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007732 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007733 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007734
John McCall43fed0d2010-11-12 08:19:04 +00007735 // TODO: If this is a conversion-function-id, verify that the
7736 // destination type name (if present) resolves the same way after
7737 // instantiation as it did in the local scope.
7738
Abramo Bagnara25777432010-08-11 22:01:17 +00007739 DeclarationNameInfo NameInfo
7740 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7741 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007742 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007743
John McCallf7a1a742009-11-24 19:00:30 +00007744 if (!E->hasExplicitTemplateArgs()) {
7745 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007746 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007747 // Note: it is sufficient to compare the Name component of NameInfo:
7748 // if name has not changed, DNLoc has not changed either.
7749 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007750 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007751
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007752 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007753 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007754 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007755 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007756 }
John McCalld5532b62009-11-23 01:53:49 +00007757
7758 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007759 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7760 E->getNumTemplateArgs(),
7761 TransArgs))
7762 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007763
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007764 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007765 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007766 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007767 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007768}
7769
7770template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007771ExprResult
John McCall454feb92009-12-08 09:21:05 +00007772TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007773 // CXXConstructExprs are always implicit, so when we have a
7774 // 1-argument construction we just transform that argument.
7775 if (E->getNumArgs() == 1 ||
7776 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7777 return getDerived().TransformExpr(E->getArg(0));
7778
Douglas Gregorb98b1992009-08-11 05:31:07 +00007779 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7780
7781 QualType T = getDerived().TransformType(E->getType());
7782 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007783 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007784
7785 CXXConstructorDecl *Constructor
7786 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007787 getDerived().TransformDecl(E->getLocStart(),
7788 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007789 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007790 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007791
Douglas Gregorb98b1992009-08-11 05:31:07 +00007792 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007793 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007794 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7795 &ArgumentChanged))
7796 return ExprError();
7797
Douglas Gregorb98b1992009-08-11 05:31:07 +00007798 if (!getDerived().AlwaysRebuild() &&
7799 T == E->getType() &&
7800 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007801 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007802 // Mark the constructor as referenced.
7803 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007804 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007805 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007806 }
Mike Stump1eb44332009-09-09 15:08:12 +00007807
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007808 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7809 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007810 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007811 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007812 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007813 E->getConstructionKind(),
7814 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007815}
Mike Stump1eb44332009-09-09 15:08:12 +00007816
Douglas Gregorb98b1992009-08-11 05:31:07 +00007817/// \brief Transform a C++ temporary-binding expression.
7818///
Douglas Gregor51326552009-12-24 18:51:59 +00007819/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7820/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007821template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007822ExprResult
John McCall454feb92009-12-08 09:21:05 +00007823TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007824 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007825}
Mike Stump1eb44332009-09-09 15:08:12 +00007826
John McCall4765fa02010-12-06 08:20:24 +00007827/// \brief Transform a C++ expression that contains cleanups that should
7828/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007829///
John McCall4765fa02010-12-06 08:20:24 +00007830/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007831/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007832template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007833ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007834TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007835 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007836}
Mike Stump1eb44332009-09-09 15:08:12 +00007837
Douglas Gregorb98b1992009-08-11 05:31:07 +00007838template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007839ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007840TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007841 CXXTemporaryObjectExpr *E) {
7842 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7843 if (!T)
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 CXXConstructorDecl *Constructor
7847 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007848 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007849 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007850 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007851 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007852
Douglas Gregorb98b1992009-08-11 05:31:07 +00007853 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007854 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007855 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007856 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7857 &ArgumentChanged))
7858 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007859
Douglas Gregorb98b1992009-08-11 05:31:07 +00007860 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007861 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007862 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007863 !ArgumentChanged) {
7864 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007865 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007866 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007867 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007868
7869 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7870 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007871 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007872 E->getLocEnd());
7873}
Mike Stump1eb44332009-09-09 15:08:12 +00007874
Douglas Gregorb98b1992009-08-11 05:31:07 +00007875template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007876ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007877TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007878 // Create the local class that will describe the lambda.
7879 CXXRecordDecl *Class
Douglas Gregorf54486a2012-04-04 17:40:10 +00007880 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7881 /*KnownDependent=*/false);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007882 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7883
7884 // Transform the type of the lambda parameters and start the definition of
7885 // the lambda itself.
7886 TypeSourceInfo *MethodTy
7887 = TransformType(E->getCallOperator()->getTypeSourceInfo());
7888 if (!MethodTy)
7889 return ExprError();
7890
Douglas Gregorc6889e72012-02-14 22:28:59 +00007891 // Transform lambda parameters.
7892 bool Invalid = false;
7893 llvm::SmallVector<QualType, 4> ParamTypes;
7894 llvm::SmallVector<ParmVarDecl *, 4> Params;
7895 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7896 E->getCallOperator()->param_begin(),
7897 E->getCallOperator()->param_size(),
7898 0, ParamTypes, &Params))
7899 Invalid = true;
7900
Douglas Gregordfca6f52012-02-13 22:00:16 +00007901 // Build the call operator.
Douglas Gregorf54486a2012-04-04 17:40:10 +00007902 // Note: Once a lambda mangling number and context declaration have been
7903 // assigned, they never change.
7904 unsigned ManglingNumber = E->getLambdaClass()->getLambdaManglingNumber();
7905 Decl *ContextDecl = E->getLambdaClass()->getLambdaContextDecl();
Douglas Gregordfca6f52012-02-13 22:00:16 +00007906 CXXMethodDecl *CallOperator
7907 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
7908 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007909 E->getCallOperator()->getLocEnd(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00007910 Params, ManglingNumber, ContextDecl);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007911 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
7912
Douglas Gregord5387e82012-02-14 00:00:48 +00007913 // FIXME: Instantiation-specific.
7914 CallOperator->setInstantiationOfMemberFunction(E->getCallOperator(),
7915 TSK_ImplicitInstantiation);
7916
7917 // Introduce the context of the call operator.
7918 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7919
Douglas Gregordfca6f52012-02-13 22:00:16 +00007920 // Enter the scope of the lambda.
7921 sema::LambdaScopeInfo *LSI
7922 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7923 E->getCaptureDefault(),
7924 E->hasExplicitParameters(),
7925 E->hasExplicitResultType(),
7926 E->isMutable());
7927
7928 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00007929 bool FinishedExplicitCaptures = false;
7930 for (LambdaExpr::capture_iterator C = E->capture_begin(),
7931 CEnd = E->capture_end();
7932 C != CEnd; ++C) {
7933 // When we hit the first implicit capture, tell Sema that we've finished
7934 // the list of explicit captures.
7935 if (!FinishedExplicitCaptures && C->isImplicit()) {
7936 getSema().finishLambdaExplicitCaptures(LSI);
7937 FinishedExplicitCaptures = true;
7938 }
7939
7940 // Capturing 'this' is trivial.
7941 if (C->capturesThis()) {
7942 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7943 continue;
7944 }
7945
Douglas Gregora7365242012-02-14 19:27:52 +00007946 // Determine the capture kind for Sema.
7947 Sema::TryCaptureKind Kind
7948 = C->isImplicit()? Sema::TryCapture_Implicit
7949 : C->getCaptureKind() == LCK_ByCopy
7950 ? Sema::TryCapture_ExplicitByVal
7951 : Sema::TryCapture_ExplicitByRef;
7952 SourceLocation EllipsisLoc;
7953 if (C->isPackExpansion()) {
7954 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7955 bool ShouldExpand = false;
7956 bool RetainExpansion = false;
7957 llvm::Optional<unsigned> NumExpansions;
7958 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7959 C->getLocation(),
7960 Unexpanded,
7961 ShouldExpand, RetainExpansion,
7962 NumExpansions))
7963 return ExprError();
7964
7965 if (ShouldExpand) {
7966 // The transform has determined that we should perform an expansion;
7967 // transform and capture each of the arguments.
7968 // expansion of the pattern. Do so.
7969 VarDecl *Pack = C->getCapturedVar();
7970 for (unsigned I = 0; I != *NumExpansions; ++I) {
7971 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7972 VarDecl *CapturedVar
7973 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7974 Pack));
7975 if (!CapturedVar) {
7976 Invalid = true;
7977 continue;
7978 }
7979
7980 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007981 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregora7365242012-02-14 19:27:52 +00007982 }
7983 continue;
7984 }
7985
7986 EllipsisLoc = C->getEllipsisLoc();
7987 }
7988
Douglas Gregordfca6f52012-02-13 22:00:16 +00007989 // Transform the captured variable.
7990 VarDecl *CapturedVar
7991 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7992 C->getCapturedVar()));
7993 if (!CapturedVar) {
7994 Invalid = true;
7995 continue;
7996 }
Douglas Gregora7365242012-02-14 19:27:52 +00007997
Douglas Gregordfca6f52012-02-13 22:00:16 +00007998 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007999 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008000 }
8001 if (!FinishedExplicitCaptures)
8002 getSema().finishLambdaExplicitCaptures(LSI);
8003
Douglas Gregordfca6f52012-02-13 22:00:16 +00008004
8005 // Enter a new evaluation context to insulate the lambda from any
8006 // cleanups from the enclosing full-expression.
8007 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
8008
8009 if (Invalid) {
8010 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
8011 /*IsInstantiation=*/true);
8012 return ExprError();
8013 }
8014
8015 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008016 StmtResult Body = getDerived().TransformStmt(E->getBody());
8017 if (Body.isInvalid()) {
8018 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
8019 /*IsInstantiation=*/true);
8020 return ExprError();
8021 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008022
Douglas Gregordfca6f52012-02-13 22:00:16 +00008023 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008024 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008025}
8026
8027template<typename Derived>
8028ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008029TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008030 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008031 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8032 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008033 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008034
Douglas Gregorb98b1992009-08-11 05:31:07 +00008035 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008036 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008037 Args.reserve(E->arg_size());
8038 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
8039 &ArgumentChanged))
8040 return ExprError();
8041
Douglas Gregorb98b1992009-08-11 05:31:07 +00008042 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008043 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008044 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008045 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008046
Douglas Gregorb98b1992009-08-11 05:31:07 +00008047 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008048 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008049 E->getLParenLoc(),
8050 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00008051 E->getRParenLoc());
8052}
Mike Stump1eb44332009-09-09 15:08:12 +00008053
Douglas Gregorb98b1992009-08-11 05:31:07 +00008054template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008055ExprResult
John McCall865d4472009-11-19 22:55:06 +00008056TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008057 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008058 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008059 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008060 Expr *OldBase;
8061 QualType BaseType;
8062 QualType ObjectType;
8063 if (!E->isImplicitAccess()) {
8064 OldBase = E->getBase();
8065 Base = getDerived().TransformExpr(OldBase);
8066 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008067 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008068
John McCallaa81e162009-12-01 22:10:20 +00008069 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008070 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008071 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008072 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008073 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008074 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008075 ObjectTy,
8076 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008077 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008078 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008079
John McCallb3d87482010-08-24 05:47:05 +00008080 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008081 BaseType = ((Expr*) Base.get())->getType();
8082 } else {
8083 OldBase = 0;
8084 BaseType = getDerived().TransformType(E->getBaseType());
8085 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8086 }
Mike Stump1eb44332009-09-09 15:08:12 +00008087
Douglas Gregor6cd21982009-10-20 05:58:46 +00008088 // Transform the first part of the nested-name-specifier that qualifies
8089 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008090 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008091 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008092 E->getFirstQualifierFoundInScope(),
8093 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008094
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008095 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008096 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008097 QualifierLoc
8098 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8099 ObjectType,
8100 FirstQualifierInScope);
8101 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008102 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008103 }
Mike Stump1eb44332009-09-09 15:08:12 +00008104
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008105 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8106
John McCall43fed0d2010-11-12 08:19:04 +00008107 // TODO: If this is a conversion-function-id, verify that the
8108 // destination type name (if present) resolves the same way after
8109 // instantiation as it did in the local scope.
8110
Abramo Bagnara25777432010-08-11 22:01:17 +00008111 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008112 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008113 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008114 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008115
John McCallaa81e162009-12-01 22:10:20 +00008116 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008117 // This is a reference to a member without an explicitly-specified
8118 // template argument list. Optimize for this common case.
8119 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008120 Base.get() == OldBase &&
8121 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008122 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008123 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008124 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008125 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008126
John McCall9ae2f072010-08-23 23:25:46 +00008127 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008128 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008129 E->isArrow(),
8130 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008131 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008132 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008133 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008134 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008135 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008136 }
8137
John McCalld5532b62009-11-23 01:53:49 +00008138 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008139 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8140 E->getNumTemplateArgs(),
8141 TransArgs))
8142 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008143
John McCall9ae2f072010-08-23 23:25:46 +00008144 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008145 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008146 E->isArrow(),
8147 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008148 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008149 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008150 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008151 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008152 &TransArgs);
8153}
8154
8155template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008156ExprResult
John McCall454feb92009-12-08 09:21:05 +00008157TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008158 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008159 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008160 QualType BaseType;
8161 if (!Old->isImplicitAccess()) {
8162 Base = getDerived().TransformExpr(Old->getBase());
8163 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008164 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008165 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8166 Old->isArrow());
8167 if (Base.isInvalid())
8168 return ExprError();
8169 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008170 } else {
8171 BaseType = getDerived().TransformType(Old->getBaseType());
8172 }
John McCall129e2df2009-11-30 22:42:35 +00008173
Douglas Gregor4c9be892011-02-28 20:01:57 +00008174 NestedNameSpecifierLoc QualifierLoc;
8175 if (Old->getQualifierLoc()) {
8176 QualifierLoc
8177 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8178 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008179 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008180 }
8181
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008182 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8183
Abramo Bagnara25777432010-08-11 22:01:17 +00008184 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008185 Sema::LookupOrdinaryName);
8186
8187 // Transform all the decls.
8188 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8189 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008190 NamedDecl *InstD = static_cast<NamedDecl*>(
8191 getDerived().TransformDecl(Old->getMemberLoc(),
8192 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008193 if (!InstD) {
8194 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8195 // This can happen because of dependent hiding.
8196 if (isa<UsingShadowDecl>(*I))
8197 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008198 else {
8199 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008200 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008201 }
John McCall9f54ad42009-12-10 09:41:52 +00008202 }
John McCall129e2df2009-11-30 22:42:35 +00008203
8204 // Expand using declarations.
8205 if (isa<UsingDecl>(InstD)) {
8206 UsingDecl *UD = cast<UsingDecl>(InstD);
8207 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8208 E = UD->shadow_end(); I != E; ++I)
8209 R.addDecl(*I);
8210 continue;
8211 }
8212
8213 R.addDecl(InstD);
8214 }
8215
8216 R.resolveKind();
8217
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008218 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008219 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00008220 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008221 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008222 Old->getMemberLoc(),
8223 Old->getNamingClass()));
8224 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008225 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008226
Douglas Gregor66c45152010-04-27 16:10:10 +00008227 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008228 }
Sean Huntc3021132010-05-05 15:23:54 +00008229
John McCall129e2df2009-11-30 22:42:35 +00008230 TemplateArgumentListInfo TransArgs;
8231 if (Old->hasExplicitTemplateArgs()) {
8232 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8233 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008234 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8235 Old->getNumTemplateArgs(),
8236 TransArgs))
8237 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008238 }
John McCallc2233c52010-01-15 08:34:02 +00008239
8240 // FIXME: to do this check properly, we will need to preserve the
8241 // first-qualifier-in-scope here, just in case we had a dependent
8242 // base (and therefore couldn't do the check) and a
8243 // nested-name-qualifier (and therefore could do the lookup).
8244 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00008245
John McCall9ae2f072010-08-23 23:25:46 +00008246 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008247 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008248 Old->getOperatorLoc(),
8249 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008250 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008251 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008252 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008253 R,
8254 (Old->hasExplicitTemplateArgs()
8255 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008256}
8257
8258template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008259ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008260TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008261 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008262 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8263 if (SubExpr.isInvalid())
8264 return ExprError();
8265
8266 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008267 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008268
8269 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8270}
8271
8272template<typename Derived>
8273ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008274TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008275 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8276 if (Pattern.isInvalid())
8277 return ExprError();
8278
8279 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8280 return SemaRef.Owned(E);
8281
Douglas Gregor67fd1252011-01-14 21:20:45 +00008282 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8283 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008284}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008285
8286template<typename Derived>
8287ExprResult
8288TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8289 // If E is not value-dependent, then nothing will change when we transform it.
8290 // Note: This is an instantiation-centric view.
8291 if (!E->isValueDependent())
8292 return SemaRef.Owned(E);
8293
8294 // Note: None of the implementations of TryExpandParameterPacks can ever
8295 // produce a diagnostic when given only a single unexpanded parameter pack,
8296 // so
8297 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8298 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008299 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008300 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00008301 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008302 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008303 ShouldExpand, RetainExpansion,
8304 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008305 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00008306
Douglas Gregor089e8932011-10-10 18:59:29 +00008307 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008308 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00008309
8310 NamedDecl *Pack = E->getPack();
8311 if (!ShouldExpand) {
8312 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
8313 Pack));
8314 if (!Pack)
8315 return ExprError();
8316 }
8317
Douglas Gregoree8aff02011-01-04 17:33:58 +00008318
8319 // We now know the length of the parameter pack, so build a new expression
8320 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00008321 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00008322 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008323 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008324}
8325
Douglas Gregorbe230c32011-01-03 17:17:50 +00008326template<typename Derived>
8327ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008328TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8329 SubstNonTypeTemplateParmPackExpr *E) {
8330 // Default behavior is to do nothing with this transformation.
8331 return SemaRef.Owned(E);
8332}
8333
8334template<typename Derived>
8335ExprResult
John McCall91a57552011-07-15 05:09:51 +00008336TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8337 SubstNonTypeTemplateParmExpr *E) {
8338 // Default behavior is to do nothing with this transformation.
8339 return SemaRef.Owned(E);
8340}
8341
8342template<typename Derived>
8343ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008344TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8345 MaterializeTemporaryExpr *E) {
8346 return getDerived().TransformExpr(E->GetTemporaryExpr());
8347}
8348
8349template<typename Derived>
8350ExprResult
John McCall454feb92009-12-08 09:21:05 +00008351TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008352 return SemaRef.MaybeBindToTemporary(E);
8353}
8354
8355template<typename Derived>
8356ExprResult
8357TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008358 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008359}
8360
8361template<typename Derived>
8362ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008363TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8364 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8365 if (SubExpr.isInvalid())
8366 return ExprError();
8367
8368 if (!getDerived().AlwaysRebuild() &&
8369 SubExpr.get() == E->getSubExpr())
8370 return SemaRef.Owned(E);
8371
8372 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008373}
8374
8375template<typename Derived>
8376ExprResult
8377TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8378 // Transform each of the elements.
8379 llvm::SmallVector<Expr *, 8> Elements;
8380 bool ArgChanged = false;
8381 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
8382 /*IsCall=*/false, Elements, &ArgChanged))
8383 return ExprError();
8384
8385 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8386 return SemaRef.MaybeBindToTemporary(E);
8387
8388 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8389 Elements.data(),
8390 Elements.size());
8391}
8392
8393template<typename Derived>
8394ExprResult
8395TreeTransform<Derived>::TransformObjCDictionaryLiteral(
8396 ObjCDictionaryLiteral *E) {
8397 // Transform each of the elements.
8398 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8399 bool ArgChanged = false;
8400 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8401 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
8402
8403 if (OrigElement.isPackExpansion()) {
8404 // This key/value element is a pack expansion.
8405 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8406 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8407 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8408 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8409
8410 // Determine whether the set of unexpanded parameter packs can
8411 // and should be expanded.
8412 bool Expand = true;
8413 bool RetainExpansion = false;
8414 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8415 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8416 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8417 OrigElement.Value->getLocEnd());
8418 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8419 PatternRange,
8420 Unexpanded,
8421 Expand, RetainExpansion,
8422 NumExpansions))
8423 return ExprError();
8424
8425 if (!Expand) {
8426 // The transform has determined that we should perform a simple
8427 // transformation on the pack expansion, producing another pack
8428 // expansion.
8429 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8430 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8431 if (Key.isInvalid())
8432 return ExprError();
8433
8434 if (Key.get() != OrigElement.Key)
8435 ArgChanged = true;
8436
8437 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8438 if (Value.isInvalid())
8439 return ExprError();
8440
8441 if (Value.get() != OrigElement.Value)
8442 ArgChanged = true;
8443
8444 ObjCDictionaryElement Expansion = {
8445 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8446 };
8447 Elements.push_back(Expansion);
8448 continue;
8449 }
8450
8451 // Record right away that the argument was changed. This needs
8452 // to happen even if the array expands to nothing.
8453 ArgChanged = true;
8454
8455 // The transform has determined that we should perform an elementwise
8456 // expansion of the pattern. Do so.
8457 for (unsigned I = 0; I != *NumExpansions; ++I) {
8458 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8459 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8460 if (Key.isInvalid())
8461 return ExprError();
8462
8463 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8464 if (Value.isInvalid())
8465 return ExprError();
8466
8467 ObjCDictionaryElement Element = {
8468 Key.get(), Value.get(), SourceLocation(), NumExpansions
8469 };
8470
8471 // If any unexpanded parameter packs remain, we still have a
8472 // pack expansion.
8473 if (Key.get()->containsUnexpandedParameterPack() ||
8474 Value.get()->containsUnexpandedParameterPack())
8475 Element.EllipsisLoc = OrigElement.EllipsisLoc;
8476
8477 Elements.push_back(Element);
8478 }
8479
8480 // We've finished with this pack expansion.
8481 continue;
8482 }
8483
8484 // Transform and check key.
8485 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8486 if (Key.isInvalid())
8487 return ExprError();
8488
8489 if (Key.get() != OrigElement.Key)
8490 ArgChanged = true;
8491
8492 // Transform and check value.
8493 ExprResult Value
8494 = getDerived().TransformExpr(OrigElement.Value);
8495 if (Value.isInvalid())
8496 return ExprError();
8497
8498 if (Value.get() != OrigElement.Value)
8499 ArgChanged = true;
8500
8501 ObjCDictionaryElement Element = {
8502 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8503 };
8504 Elements.push_back(Element);
8505 }
8506
8507 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8508 return SemaRef.MaybeBindToTemporary(E);
8509
8510 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8511 Elements.data(),
8512 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008513}
8514
Mike Stump1eb44332009-09-09 15:08:12 +00008515template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008516ExprResult
John McCall454feb92009-12-08 09:21:05 +00008517TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008518 TypeSourceInfo *EncodedTypeInfo
8519 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8520 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008521 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008522
Douglas Gregorb98b1992009-08-11 05:31:07 +00008523 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008524 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008525 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008526
8527 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008528 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008529 E->getRParenLoc());
8530}
Mike Stump1eb44332009-09-09 15:08:12 +00008531
Douglas Gregorb98b1992009-08-11 05:31:07 +00008532template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008533ExprResult TreeTransform<Derived>::
8534TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8535 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8536 if (result.isInvalid()) return ExprError();
8537 Expr *subExpr = result.take();
8538
8539 if (!getDerived().AlwaysRebuild() &&
8540 subExpr == E->getSubExpr())
8541 return SemaRef.Owned(E);
8542
8543 return SemaRef.Owned(new(SemaRef.Context)
8544 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8545}
8546
8547template<typename Derived>
8548ExprResult TreeTransform<Derived>::
8549TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
8550 TypeSourceInfo *TSInfo
8551 = getDerived().TransformType(E->getTypeInfoAsWritten());
8552 if (!TSInfo)
8553 return ExprError();
8554
8555 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
8556 if (Result.isInvalid())
8557 return ExprError();
8558
8559 if (!getDerived().AlwaysRebuild() &&
8560 TSInfo == E->getTypeInfoAsWritten() &&
8561 Result.get() == E->getSubExpr())
8562 return SemaRef.Owned(E);
8563
8564 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
8565 E->getBridgeKeywordLoc(), TSInfo,
8566 Result.get());
8567}
8568
8569template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008570ExprResult
John McCall454feb92009-12-08 09:21:05 +00008571TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008572 // Transform arguments.
8573 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008574 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008575 Args.reserve(E->getNumArgs());
8576 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
8577 &ArgChanged))
8578 return ExprError();
8579
Douglas Gregor92e986e2010-04-22 16:44:27 +00008580 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8581 // Class message: transform the receiver type.
8582 TypeSourceInfo *ReceiverTypeInfo
8583 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8584 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008585 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008586
Douglas Gregor92e986e2010-04-22 16:44:27 +00008587 // If nothing changed, just retain the existing message send.
8588 if (!getDerived().AlwaysRebuild() &&
8589 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008590 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008591
8592 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008593 SmallVector<SourceLocation, 16> SelLocs;
8594 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008595 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8596 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008597 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008598 E->getMethodDecl(),
8599 E->getLeftLoc(),
8600 move_arg(Args),
8601 E->getRightLoc());
8602 }
8603
8604 // Instance message: transform the receiver
8605 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8606 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008607 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008608 = getDerived().TransformExpr(E->getInstanceReceiver());
8609 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008610 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008611
8612 // If nothing changed, just retain the existing message send.
8613 if (!getDerived().AlwaysRebuild() &&
8614 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008615 return SemaRef.MaybeBindToTemporary(E);
Sean Huntc3021132010-05-05 15:23:54 +00008616
Douglas Gregor92e986e2010-04-22 16:44:27 +00008617 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008618 SmallVector<SourceLocation, 16> SelLocs;
8619 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008620 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008621 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008622 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008623 E->getMethodDecl(),
8624 E->getLeftLoc(),
8625 move_arg(Args),
8626 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008627}
8628
Mike Stump1eb44332009-09-09 15:08:12 +00008629template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008630ExprResult
John McCall454feb92009-12-08 09:21:05 +00008631TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008632 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008633}
8634
Mike Stump1eb44332009-09-09 15:08:12 +00008635template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008636ExprResult
John McCall454feb92009-12-08 09:21:05 +00008637TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008638 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008639}
8640
Mike Stump1eb44332009-09-09 15:08:12 +00008641template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008642ExprResult
John McCall454feb92009-12-08 09:21:05 +00008643TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008644 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008645 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008646 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008647 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008648
8649 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008650
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008651 // If nothing changed, just retain the existing expression.
8652 if (!getDerived().AlwaysRebuild() &&
8653 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008654 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008655
John McCall9ae2f072010-08-23 23:25:46 +00008656 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008657 E->getLocation(),
8658 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008659}
8660
Mike Stump1eb44332009-09-09 15:08:12 +00008661template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008662ExprResult
John McCall454feb92009-12-08 09:21:05 +00008663TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008664 // 'super' and types never change. Property never changes. Just
8665 // retain the existing expression.
8666 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008667 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00008668
Douglas Gregore3303542010-04-26 20:47:02 +00008669 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008670 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008671 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008672 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008673
Douglas Gregore3303542010-04-26 20:47:02 +00008674 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008675
Douglas Gregore3303542010-04-26 20:47:02 +00008676 // If nothing changed, just retain the existing expression.
8677 if (!getDerived().AlwaysRebuild() &&
8678 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008679 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008680
John McCall12f78a62010-12-02 01:19:52 +00008681 if (E->isExplicitProperty())
8682 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8683 E->getExplicitProperty(),
8684 E->getLocation());
8685
8686 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008687 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008688 E->getImplicitPropertyGetter(),
8689 E->getImplicitPropertySetter(),
8690 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008691}
8692
Mike Stump1eb44332009-09-09 15:08:12 +00008693template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008694ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008695TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8696 // Transform the base expression.
8697 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8698 if (Base.isInvalid())
8699 return ExprError();
8700
8701 // Transform the key expression.
8702 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8703 if (Key.isInvalid())
8704 return ExprError();
8705
8706 // If nothing changed, just retain the existing expression.
8707 if (!getDerived().AlwaysRebuild() &&
8708 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8709 return SemaRef.Owned(E);
8710
8711 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
8712 Base.get(), Key.get(),
8713 E->getAtIndexMethodDecl(),
8714 E->setAtIndexMethodDecl());
8715}
8716
8717template<typename Derived>
8718ExprResult
John McCall454feb92009-12-08 09:21:05 +00008719TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008720 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008721 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008722 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008723 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008724
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008725 // If nothing changed, just retain the existing expression.
8726 if (!getDerived().AlwaysRebuild() &&
8727 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008728 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008729
John McCall9ae2f072010-08-23 23:25:46 +00008730 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008731 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008732}
8733
Mike Stump1eb44332009-09-09 15:08:12 +00008734template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008735ExprResult
John McCall454feb92009-12-08 09:21:05 +00008736TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008737 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008738 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008739 SubExprs.reserve(E->getNumSubExprs());
8740 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8741 SubExprs, &ArgumentChanged))
8742 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008743
Douglas Gregorb98b1992009-08-11 05:31:07 +00008744 if (!getDerived().AlwaysRebuild() &&
8745 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008746 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008747
Douglas Gregorb98b1992009-08-11 05:31:07 +00008748 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8749 move_arg(SubExprs),
8750 E->getRParenLoc());
8751}
8752
Mike Stump1eb44332009-09-09 15:08:12 +00008753template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008754ExprResult
John McCall454feb92009-12-08 09:21:05 +00008755TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008756 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008757
John McCallc6ac9c32011-02-04 18:33:18 +00008758 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8759 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8760
8761 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008762 blockScope->TheDecl->setBlockMissingReturnType(
8763 oldBlock->blockMissingReturnType());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008764
Chris Lattner686775d2011-07-20 06:58:45 +00008765 SmallVector<ParmVarDecl*, 4> params;
8766 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008767
8768 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008769 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8770 oldBlock->param_begin(),
8771 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008772 0, paramTypes, &params)) {
8773 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008774 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008775 }
John McCallc6ac9c32011-02-04 18:33:18 +00008776
8777 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008778 QualType exprResultType =
8779 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008780
8781 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008782 if (exprResultType->isObjCObjectType()) {
John McCallc6ac9c32011-02-04 18:33:18 +00008783 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008784 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008785 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008786 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008787 return ExprError();
8788 }
John McCall711c52b2011-01-05 12:14:39 +00008789
John McCallc6ac9c32011-02-04 18:33:18 +00008790 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008791 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008792 paramTypes.data(),
8793 paramTypes.size(),
8794 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008795 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008796 exprFunctionType->getExtInfo());
8797 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008798
8799 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008800 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008801 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008802
8803 if (!oldBlock->blockMissingReturnType()) {
8804 blockScope->HasImplicitReturnType = false;
8805 blockScope->ReturnType = exprResultType;
8806 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008807
John McCall711c52b2011-01-05 12:14:39 +00008808 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008809 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008810 if (body.isInvalid()) {
8811 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008812 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008813 }
John McCall711c52b2011-01-05 12:14:39 +00008814
John McCallc6ac9c32011-02-04 18:33:18 +00008815#ifndef NDEBUG
8816 // In builds with assertions, make sure that we captured everything we
8817 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008818 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8819 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8820 e = oldBlock->capture_end(); i != e; ++i) {
8821 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008822
Douglas Gregorfc921372011-05-20 15:32:55 +00008823 // Ignore parameter packs.
8824 if (isa<ParmVarDecl>(oldCapture) &&
8825 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8826 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008827
Douglas Gregorfc921372011-05-20 15:32:55 +00008828 VarDecl *newCapture =
8829 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8830 oldCapture));
8831 assert(blockScope->CaptureMap.count(newCapture));
8832 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008833 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008834 }
8835#endif
8836
8837 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8838 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008839}
8840
Mike Stump1eb44332009-09-09 15:08:12 +00008841template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008842ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008843TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008844 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008845}
Eli Friedman276b0612011-10-11 02:20:01 +00008846
8847template<typename Derived>
8848ExprResult
8849TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008850 QualType RetTy = getDerived().TransformType(E->getType());
8851 bool ArgumentChanged = false;
8852 ASTOwningVector<Expr*> SubExprs(SemaRef);
8853 SubExprs.reserve(E->getNumSubExprs());
8854 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8855 SubExprs, &ArgumentChanged))
8856 return ExprError();
8857
8858 if (!getDerived().AlwaysRebuild() &&
8859 !ArgumentChanged)
8860 return SemaRef.Owned(E);
8861
8862 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8863 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008864}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008865
Douglas Gregorb98b1992009-08-11 05:31:07 +00008866//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008867// Type reconstruction
8868//===----------------------------------------------------------------------===//
8869
Mike Stump1eb44332009-09-09 15:08:12 +00008870template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008871QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8872 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008873 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008874 getDerived().getBaseEntity());
8875}
8876
Mike Stump1eb44332009-09-09 15:08:12 +00008877template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008878QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8879 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008880 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008881 getDerived().getBaseEntity());
8882}
8883
Mike Stump1eb44332009-09-09 15:08:12 +00008884template<typename Derived>
8885QualType
John McCall85737a72009-10-30 00:06:24 +00008886TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8887 bool WrittenAsLValue,
8888 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008889 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008890 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008891}
8892
8893template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008894QualType
John McCall85737a72009-10-30 00:06:24 +00008895TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8896 QualType ClassType,
8897 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008898 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008899 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008900}
8901
8902template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008903QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008904TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8905 ArrayType::ArraySizeModifier SizeMod,
8906 const llvm::APInt *Size,
8907 Expr *SizeExpr,
8908 unsigned IndexTypeQuals,
8909 SourceRange BracketsRange) {
8910 if (SizeExpr || !Size)
8911 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8912 IndexTypeQuals, BracketsRange,
8913 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008914
8915 QualType Types[] = {
8916 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8917 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8918 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008919 };
8920 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8921 QualType SizeType;
8922 for (unsigned I = 0; I != NumTypes; ++I)
8923 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8924 SizeType = Types[I];
8925 break;
8926 }
Mike Stump1eb44332009-09-09 15:08:12 +00008927
Eli Friedman01f276d2012-01-25 23:20:27 +00008928 // Note that we can return a VariableArrayType here in the case where
8929 // the element type was a dependent VariableArrayType.
8930 IntegerLiteral *ArraySize
8931 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8932 /*FIXME*/BracketsRange.getBegin());
8933 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008934 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008935 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008936}
Mike Stump1eb44332009-09-09 15:08:12 +00008937
Douglas Gregor577f75a2009-08-04 16:50:30 +00008938template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008939QualType
8940TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008941 ArrayType::ArraySizeModifier SizeMod,
8942 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008943 unsigned IndexTypeQuals,
8944 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008945 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008946 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008947}
8948
8949template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008950QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008951TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008952 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008953 unsigned IndexTypeQuals,
8954 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008955 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008956 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008957}
Mike Stump1eb44332009-09-09 15:08:12 +00008958
Douglas Gregor577f75a2009-08-04 16:50:30 +00008959template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008960QualType
8961TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008962 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008963 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008964 unsigned IndexTypeQuals,
8965 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008966 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008967 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008968 IndexTypeQuals, BracketsRange);
8969}
8970
8971template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008972QualType
8973TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008974 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008975 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008976 unsigned IndexTypeQuals,
8977 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008978 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008979 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008980 IndexTypeQuals, BracketsRange);
8981}
8982
8983template<typename Derived>
8984QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008985 unsigned NumElements,
8986 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008987 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008988 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008989}
Mike Stump1eb44332009-09-09 15:08:12 +00008990
Douglas Gregor577f75a2009-08-04 16:50:30 +00008991template<typename Derived>
8992QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8993 unsigned NumElements,
8994 SourceLocation AttributeLoc) {
8995 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8996 NumElements, true);
8997 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008998 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8999 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009000 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009001}
Mike Stump1eb44332009-09-09 15:08:12 +00009002
Douglas Gregor577f75a2009-08-04 16:50:30 +00009003template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009004QualType
9005TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009006 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009007 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009008 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009009}
Mike Stump1eb44332009-09-09 15:08:12 +00009010
Douglas Gregor577f75a2009-08-04 16:50:30 +00009011template<typename Derived>
9012QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00009013 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009014 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00009015 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009016 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00009017 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00009018 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00009019 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00009020 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009021 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009022 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009023 getDerived().getBaseEntity(),
9024 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009025}
Mike Stump1eb44332009-09-09 15:08:12 +00009026
Douglas Gregor577f75a2009-08-04 16:50:30 +00009027template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009028QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9029 return SemaRef.Context.getFunctionNoProtoType(T);
9030}
9031
9032template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009033QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9034 assert(D && "no decl found");
9035 if (D->isInvalidDecl()) return QualType();
9036
Douglas Gregor92e986e2010-04-22 16:44:27 +00009037 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009038 TypeDecl *Ty;
9039 if (isa<UsingDecl>(D)) {
9040 UsingDecl *Using = cast<UsingDecl>(D);
9041 assert(Using->isTypeName() &&
9042 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9043
9044 // A valid resolved using typename decl points to exactly one type decl.
9045 assert(++Using->shadow_begin() == Using->shadow_end());
9046 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00009047
John McCalled976492009-12-04 22:46:56 +00009048 } else {
9049 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9050 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9051 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9052 }
9053
9054 return SemaRef.Context.getTypeDeclType(Ty);
9055}
9056
9057template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009058QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9059 SourceLocation Loc) {
9060 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009061}
9062
9063template<typename Derived>
9064QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9065 return SemaRef.Context.getTypeOfType(Underlying);
9066}
9067
9068template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009069QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9070 SourceLocation Loc) {
9071 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009072}
9073
9074template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009075QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9076 UnaryTransformType::UTTKind UKind,
9077 SourceLocation Loc) {
9078 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9079}
9080
9081template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009082QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009083 TemplateName Template,
9084 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009085 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009086 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009087}
Mike Stump1eb44332009-09-09 15:08:12 +00009088
Douglas Gregordcee1a12009-08-06 05:28:30 +00009089template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009090QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9091 SourceLocation KWLoc) {
9092 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9093}
9094
9095template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009096TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009097TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009098 bool TemplateKW,
9099 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009100 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009101 Template);
9102}
9103
9104template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009105TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009106TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9107 const IdentifierInfo &Name,
9108 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009109 QualType ObjectType,
9110 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009111 UnqualifiedId TemplateName;
9112 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009113 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009114 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009115 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009116 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009117 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009118 /*EnteringContext=*/false,
9119 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009120 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009121}
Mike Stump1eb44332009-09-09 15:08:12 +00009122
Douglas Gregorb98b1992009-08-11 05:31:07 +00009123template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009124TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009125TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009126 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009127 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009128 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009129 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009130 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009131 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009132 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009133 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009134 Sema::TemplateTy Template;
9135 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009136 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009137 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009138 /*EnteringContext=*/false,
9139 Template);
9140 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009141}
Sean Huntc3021132010-05-05 15:23:54 +00009142
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009143template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009144ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009145TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9146 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009147 Expr *OrigCallee,
9148 Expr *First,
9149 Expr *Second) {
9150 Expr *Callee = OrigCallee->IgnoreParenCasts();
9151 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009152
Douglas Gregorb98b1992009-08-11 05:31:07 +00009153 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009154 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009155 if (!First->getType()->isOverloadableType() &&
9156 !Second->getType()->isOverloadableType())
9157 return getSema().CreateBuiltinArraySubscriptExpr(First,
9158 Callee->getLocStart(),
9159 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009160 } else if (Op == OO_Arrow) {
9161 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009162 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9163 } else if (Second == 0 || isPostIncDec) {
9164 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009165 // The argument is not of overloadable type, so try to create a
9166 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009167 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009168 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009169
John McCall9ae2f072010-08-23 23:25:46 +00009170 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009171 }
9172 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009173 if (!First->getType()->isOverloadableType() &&
9174 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009175 // Neither of the arguments is an overloadable type, so try to
9176 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009177 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009178 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009179 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009180 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009181 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009182
Douglas Gregorb98b1992009-08-11 05:31:07 +00009183 return move(Result);
9184 }
9185 }
Mike Stump1eb44332009-09-09 15:08:12 +00009186
9187 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009188 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009189 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009190
John McCall9ae2f072010-08-23 23:25:46 +00009191 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009192 assert(ULE->requiresADL());
9193
9194 // FIXME: Do we have to check
9195 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009196 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009197 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009198 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00009199 }
Mike Stump1eb44332009-09-09 15:08:12 +00009200
Douglas Gregorb98b1992009-08-11 05:31:07 +00009201 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009202 Expr *Args[2] = { First, Second };
9203 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009204
Douglas Gregorb98b1992009-08-11 05:31:07 +00009205 // Create the overloaded operator invocation for unary operators.
9206 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009207 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009208 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009209 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009210 }
Mike Stump1eb44332009-09-09 15:08:12 +00009211
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009212 if (Op == OO_Subscript) {
9213 SourceLocation LBrace;
9214 SourceLocation RBrace;
9215
9216 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9217 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9218 LBrace = SourceLocation::getFromRawEncoding(
9219 NameLoc.CXXOperatorName.BeginOpNameLoc);
9220 RBrace = SourceLocation::getFromRawEncoding(
9221 NameLoc.CXXOperatorName.EndOpNameLoc);
9222 } else {
9223 LBrace = Callee->getLocStart();
9224 RBrace = OpLoc;
9225 }
9226
9227 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9228 First, Second);
9229 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009230
Douglas Gregorb98b1992009-08-11 05:31:07 +00009231 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009232 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009233 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009234 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9235 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009236 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009237
Mike Stump1eb44332009-09-09 15:08:12 +00009238 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009239}
Mike Stump1eb44332009-09-09 15:08:12 +00009240
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009241template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009242ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009243TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009244 SourceLocation OperatorLoc,
9245 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009246 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009247 TypeSourceInfo *ScopeType,
9248 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009249 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009250 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009251 QualType BaseType = Base->getType();
9252 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009253 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00009254 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009255 !BaseType->getAs<PointerType>()->getPointeeType()
9256 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009257 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009258 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009259 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009260 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009261 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009262 /*FIXME?*/true);
9263 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009264
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009265 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009266 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9267 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9268 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9269 NameInfo.setNamedTypeInfo(DestroyedType);
9270
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009271 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00009272
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009273 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009274 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009275 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009276 SS, TemplateKWLoc,
9277 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009278 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009279 /*TemplateArgs*/ 0);
9280}
9281
Douglas Gregor577f75a2009-08-04 16:50:30 +00009282} // end namespace clang
9283
9284#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H