blob: 08c7d7d11a14ecdcec6ee42cf3ea26ef26d4f210 [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
Chad Rosier8cd64b42012-06-11 20:47:18 +00001182 /// \brief Build a new MS style inline asm statement.
1183 ///
1184 /// By default, performs semantic analysis to build the new statement.
1185 /// Subclasses may override this routine to provide different behavior.
1186 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc,
1187 std::string &AsmString,
1188 SourceLocation EndLoc) {
1189 return getSema().ActOnMSAsmStmt(AsmLoc, AsmString, EndLoc);
1190 }
1191
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001192 /// \brief Build a new Objective-C @try statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001196 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001197 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001198 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001199 Stmt *Finally) {
1200 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1201 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001202 }
1203
Douglas Gregorbe270a02010-04-26 17:57:08 +00001204 /// \brief Rebuild an Objective-C exception declaration.
1205 ///
1206 /// By default, performs semantic analysis to build the new declaration.
1207 /// Subclasses may override this routine to provide different behavior.
1208 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1209 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001210 return getSema().BuildObjCExceptionDecl(TInfo, T,
1211 ExceptionDecl->getInnerLocStart(),
1212 ExceptionDecl->getLocation(),
1213 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001214 }
Sean Huntc3021132010-05-05 15:23:54 +00001215
Douglas Gregorbe270a02010-04-26 17:57:08 +00001216 /// \brief Build a new Objective-C @catch statement.
1217 ///
1218 /// By default, performs semantic analysis to build the new statement.
1219 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001220 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001221 SourceLocation RParenLoc,
1222 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001223 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001224 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001225 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001226 }
Sean Huntc3021132010-05-05 15:23:54 +00001227
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001228 /// \brief Build a new Objective-C @finally statement.
1229 ///
1230 /// By default, performs semantic analysis to build the new statement.
1231 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001232 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001233 Stmt *Body) {
1234 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001235 }
Sean Huntc3021132010-05-05 15:23:54 +00001236
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001237 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001238 ///
1239 /// By default, performs semantic analysis to build the new statement.
1240 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001241 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001242 Expr *Operand) {
1243 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001244 }
Sean Huntc3021132010-05-05 15:23:54 +00001245
John McCall07524032011-07-27 21:50:02 +00001246 /// \brief Rebuild the operand to an Objective-C @synchronized statement.
1247 ///
1248 /// By default, performs semantic analysis to build the new statement.
1249 /// Subclasses may override this routine to provide different behavior.
1250 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1251 Expr *object) {
1252 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1253 }
1254
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001255 /// \brief Build a new Objective-C @synchronized statement.
1256 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001257 /// By default, performs semantic analysis to build the new statement.
1258 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001259 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001260 Expr *Object, Stmt *Body) {
1261 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001262 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001263
John McCallf85e1932011-06-15 23:02:42 +00001264 /// \brief Build a new Objective-C @autoreleasepool statement.
1265 ///
1266 /// By default, performs semantic analysis to build the new statement.
1267 /// Subclasses may override this routine to provide different behavior.
1268 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1269 Stmt *Body) {
1270 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1271 }
John McCall990567c2011-07-27 01:07:15 +00001272
1273 /// \brief Build the collection operand to a new Objective-C fast
1274 /// enumeration statement.
1275 ///
1276 /// By default, performs semantic analysis to build the new statement.
1277 /// Subclasses may override this routine to provide different behavior.
1278 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1279 Expr *collection) {
1280 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1281 }
John McCallf85e1932011-06-15 23:02:42 +00001282
Douglas Gregorc3203e72010-04-22 23:10:45 +00001283 /// \brief Build a new Objective-C fast enumeration statement.
1284 ///
1285 /// By default, performs semantic analysis to build the new statement.
1286 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001287 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001288 SourceLocation LParenLoc,
1289 Stmt *Element,
1290 Expr *Collection,
1291 SourceLocation RParenLoc,
1292 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001293 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001294 Element,
1295 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001296 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001297 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001298 }
Sean Huntc3021132010-05-05 15:23:54 +00001299
Douglas Gregor43959a92009-08-20 07:17:43 +00001300 /// \brief Build a new C++ exception declaration.
1301 ///
1302 /// By default, performs semantic analysis to build the new decaration.
1303 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001304 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001305 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001306 SourceLocation StartLoc,
1307 SourceLocation IdLoc,
1308 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001309 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1310 StartLoc, IdLoc, Id);
1311 if (Var)
1312 getSema().CurContext->addDecl(Var);
1313 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001314 }
1315
1316 /// \brief Build a new C++ catch statement.
1317 ///
1318 /// By default, performs semantic analysis to build the new statement.
1319 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001320 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001321 VarDecl *ExceptionDecl,
1322 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001323 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1324 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001325 }
Mike Stump1eb44332009-09-09 15:08:12 +00001326
Douglas Gregor43959a92009-08-20 07:17:43 +00001327 /// \brief Build a new C++ try statement.
1328 ///
1329 /// By default, performs semantic analysis to build the new statement.
1330 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001331 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001332 Stmt *TryBlock,
1333 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001334 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001335 }
Mike Stump1eb44332009-09-09 15:08:12 +00001336
Richard Smithad762fc2011-04-14 22:09:26 +00001337 /// \brief Build a new C++0x range-based for statement.
1338 ///
1339 /// By default, performs semantic analysis to build the new statement.
1340 /// Subclasses may override this routine to provide different behavior.
1341 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1342 SourceLocation ColonLoc,
1343 Stmt *Range, Stmt *BeginEnd,
1344 Expr *Cond, Expr *Inc,
1345 Stmt *LoopVar,
1346 SourceLocation RParenLoc) {
1347 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1348 Cond, Inc, LoopVar, RParenLoc);
1349 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001350
1351 /// \brief Build a new C++0x range-based for statement.
1352 ///
1353 /// By default, performs semantic analysis to build the new statement.
1354 /// Subclasses may override this routine to provide different behavior.
1355 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1356 bool IsIfExists,
1357 NestedNameSpecifierLoc QualifierLoc,
1358 DeclarationNameInfo NameInfo,
1359 Stmt *Nested) {
1360 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1361 QualifierLoc, NameInfo, Nested);
1362 }
1363
Richard Smithad762fc2011-04-14 22:09:26 +00001364 /// \brief Attach body to a C++0x range-based for statement.
1365 ///
1366 /// By default, performs semantic analysis to finish the new statement.
1367 /// Subclasses may override this routine to provide different behavior.
1368 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1369 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1370 }
1371
John Wiegley28bbe4b2011-04-28 01:08:34 +00001372 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1373 SourceLocation TryLoc,
1374 Stmt *TryBlock,
1375 Stmt *Handler) {
1376 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1377 }
1378
1379 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1380 Expr *FilterExpr,
1381 Stmt *Block) {
1382 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1383 }
1384
1385 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1386 Stmt *Block) {
1387 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1388 }
1389
Douglas Gregorb98b1992009-08-11 05:31:07 +00001390 /// \brief Build a new expression that references a declaration.
1391 ///
1392 /// By default, performs semantic analysis to build the new expression.
1393 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001394 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001395 LookupResult &R,
1396 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001397 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1398 }
1399
1400
1401 /// \brief Build a new expression that references a declaration.
1402 ///
1403 /// By default, performs semantic analysis to build the new expression.
1404 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001405 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001406 ValueDecl *VD,
1407 const DeclarationNameInfo &NameInfo,
1408 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001409 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001410 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001411
1412 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001413
1414 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 }
Mike Stump1eb44332009-09-09 15:08:12 +00001416
Douglas Gregorb98b1992009-08-11 05:31:07 +00001417 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001418 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001419 /// By default, performs semantic analysis to build the new expression.
1420 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001421 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001422 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001423 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001424 }
1425
Douglas Gregora71d8192009-09-04 17:36:40 +00001426 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001427 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001428 /// By default, performs semantic analysis to build the new expression.
1429 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001430 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001431 SourceLocation OperatorLoc,
1432 bool isArrow,
1433 CXXScopeSpec &SS,
1434 TypeSourceInfo *ScopeType,
1435 SourceLocation CCLoc,
1436 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001437 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001438
Douglas Gregorb98b1992009-08-11 05:31:07 +00001439 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001440 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001441 /// By default, performs semantic analysis to build the new expression.
1442 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001443 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001444 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001445 Expr *SubExpr) {
1446 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001447 }
Mike Stump1eb44332009-09-09 15:08:12 +00001448
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001449 /// \brief Build a new builtin offsetof expression.
1450 ///
1451 /// By default, performs semantic analysis to build the new expression.
1452 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001453 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001454 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001455 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001456 unsigned NumComponents,
1457 SourceLocation RParenLoc) {
1458 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1459 NumComponents, RParenLoc);
1460 }
Sean Huntc3021132010-05-05 15:23:54 +00001461
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001462 /// \brief Build a new sizeof, alignof or vec_step expression with a
1463 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001464 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001465 /// By default, performs semantic analysis to build the new expression.
1466 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001467 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1468 SourceLocation OpLoc,
1469 UnaryExprOrTypeTrait ExprKind,
1470 SourceRange R) {
1471 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001472 }
1473
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001474 /// \brief Build a new sizeof, alignof or vec step expression with an
1475 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001476 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001477 /// By default, performs semantic analysis to build the new expression.
1478 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001479 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1480 UnaryExprOrTypeTrait ExprKind,
1481 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001482 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001483 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001484 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001485 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001486
Douglas Gregorb98b1992009-08-11 05:31:07 +00001487 return move(Result);
1488 }
Mike Stump1eb44332009-09-09 15:08:12 +00001489
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001491 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001492 /// By default, performs semantic analysis to build the new expression.
1493 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001494 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001496 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001497 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001498 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1499 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001500 RBracketLoc);
1501 }
1502
1503 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001504 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001505 /// By default, performs semantic analysis to build the new expression.
1506 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001507 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001508 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001509 SourceLocation RParenLoc,
1510 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001511 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001512 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001513 }
1514
1515 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001516 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001517 /// By default, performs semantic analysis to build the new expression.
1518 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001519 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001520 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001521 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001522 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001523 const DeclarationNameInfo &MemberNameInfo,
1524 ValueDecl *Member,
1525 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001526 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001527 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001528 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1529 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001530 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001531 // We have a reference to an unnamed field. This is always the
1532 // base of an anonymous struct/union member access, i.e. the
1533 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001534 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001535 assert(Member->getType()->isRecordType() &&
1536 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001537
Richard Smith9138b4e2011-10-26 19:06:56 +00001538 BaseResult =
1539 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001540 QualifierLoc.getNestedNameSpecifier(),
1541 FoundDecl, Member);
1542 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001543 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001544 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001545 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001546 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001547 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001548 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001549 cast<FieldDecl>(Member)->getType(),
1550 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001551 return getSema().Owned(ME);
1552 }
Mike Stump1eb44332009-09-09 15:08:12 +00001553
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001554 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001555 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001556
John Wiegley429bb272011-04-08 18:41:53 +00001557 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001558 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001559
John McCall6bb80172010-03-30 21:47:33 +00001560 // FIXME: this involves duplicating earlier analysis in a lot of
1561 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001562 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001563 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001564 R.resolveKind();
1565
John McCall9ae2f072010-08-23 23:25:46 +00001566 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001567 SS, TemplateKWLoc,
1568 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001569 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001570 }
Mike Stump1eb44332009-09-09 15:08:12 +00001571
Douglas Gregorb98b1992009-08-11 05:31:07 +00001572 /// \brief Build a new binary 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 RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001577 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001578 Expr *LHS, Expr *RHS) {
1579 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001580 }
1581
1582 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001583 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001584 /// By default, performs semantic analysis to build the new expression.
1585 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001586 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001587 SourceLocation QuestionLoc,
1588 Expr *LHS,
1589 SourceLocation ColonLoc,
1590 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001591 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1592 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 }
1594
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001596 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001597 /// By default, performs semantic analysis to build the new expression.
1598 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001599 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001600 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001601 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001602 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001603 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001604 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001605 }
Mike Stump1eb44332009-09-09 15:08:12 +00001606
Douglas Gregorb98b1992009-08-11 05:31:07 +00001607 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001608 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001609 /// By default, performs semantic analysis to build the new expression.
1610 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001611 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001612 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001613 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001614 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001615 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001616 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001617 }
Mike Stump1eb44332009-09-09 15:08:12 +00001618
Douglas Gregorb98b1992009-08-11 05:31:07 +00001619 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001620 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001621 /// By default, performs semantic analysis to build the new expression.
1622 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001623 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001624 SourceLocation OpLoc,
1625 SourceLocation AccessorLoc,
1626 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001627
John McCall129e2df2009-11-30 22:42:35 +00001628 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001629 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001630 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001631 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001632 SS, SourceLocation(),
1633 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001634 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001635 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001636 }
Mike Stump1eb44332009-09-09 15:08:12 +00001637
Douglas Gregorb98b1992009-08-11 05:31:07 +00001638 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001639 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001640 /// By default, performs semantic analysis to build the new expression.
1641 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001642 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001643 MultiExprArg Inits,
1644 SourceLocation RBraceLoc,
1645 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001646 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001647 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1648 if (Result.isInvalid() || ResultTy->isDependentType())
1649 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001650
Douglas Gregore48319a2009-11-09 17:16:50 +00001651 // Patch in the result type we were given, which may have been computed
1652 // when the initial InitListExpr was built.
1653 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1654 ILE->setType(ResultTy);
1655 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001656 }
Mike Stump1eb44332009-09-09 15:08:12 +00001657
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001659 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001660 /// By default, performs semantic analysis to build the new expression.
1661 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001662 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 MultiExprArg ArrayExprs,
1664 SourceLocation EqualOrColonLoc,
1665 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001666 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001667 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001669 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001670 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001671 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001672
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 ArrayExprs.release();
1674 return move(Result);
1675 }
Mike Stump1eb44332009-09-09 15:08:12 +00001676
Douglas Gregorb98b1992009-08-11 05:31:07 +00001677 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001678 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 /// By default, builds the implicit value initialization without performing
1680 /// any semantic analysis. Subclasses may override this routine to provide
1681 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001682 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001683 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1684 }
Mike Stump1eb44332009-09-09 15:08:12 +00001685
Douglas Gregorb98b1992009-08-11 05:31:07 +00001686 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001687 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001688 /// By default, performs semantic analysis to build the new expression.
1689 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001690 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001691 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001692 SourceLocation RParenLoc) {
1693 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001694 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001695 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 }
1697
1698 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001699 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 /// By default, performs semantic analysis to build the new expression.
1701 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001702 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001703 MultiExprArg SubExprs,
1704 SourceLocation RParenLoc) {
1705 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
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 address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001709 ///
1710 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001711 /// rather than attempting to map the label statement itself.
1712 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001713 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001714 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001715 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
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 GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001719 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001720 /// 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 RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001723 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001724 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001725 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001726 }
Mike Stump1eb44332009-09-09 15:08:12 +00001727
Douglas Gregorb98b1992009-08-11 05:31:07 +00001728 /// \brief Build a new __builtin_choose_expr expression.
1729 ///
1730 /// By default, performs semantic analysis to build the new expression.
1731 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001732 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001733 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001734 SourceLocation RParenLoc) {
1735 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001736 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001737 RParenLoc);
1738 }
Mike Stump1eb44332009-09-09 15:08:12 +00001739
Peter Collingbournef111d932011-04-15 00:35:48 +00001740 /// \brief Build a new generic selection expression.
1741 ///
1742 /// By default, performs semantic analysis to build the new expression.
1743 /// Subclasses may override this routine to provide different behavior.
1744 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1745 SourceLocation DefaultLoc,
1746 SourceLocation RParenLoc,
1747 Expr *ControllingExpr,
1748 TypeSourceInfo **Types,
1749 Expr **Exprs,
1750 unsigned NumAssocs) {
1751 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1752 ControllingExpr, Types, Exprs,
1753 NumAssocs);
1754 }
1755
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 /// \brief Build a new overloaded operator call expression.
1757 ///
1758 /// By default, performs semantic analysis to build the new expression.
1759 /// The semantic analysis provides the behavior of template instantiation,
1760 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001761 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001762 /// argument-dependent lookup, etc. Subclasses may override this routine to
1763 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001764 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001766 Expr *Callee,
1767 Expr *First,
1768 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001769
1770 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001771 /// reinterpret_cast.
1772 ///
1773 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001774 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001775 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001776 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001777 Stmt::StmtClass Class,
1778 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001779 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001780 SourceLocation RAngleLoc,
1781 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001782 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001783 SourceLocation RParenLoc) {
1784 switch (Class) {
1785 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001786 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001787 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001788 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789
1790 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001791 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001792 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001793 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001794
Douglas Gregorb98b1992009-08-11 05:31:07 +00001795 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001796 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001797 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001798 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001800
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001802 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001803 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001804 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001805
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001807 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001808 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 }
Mike Stump1eb44332009-09-09 15:08:12 +00001810
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 /// \brief Build a new C++ static_cast expression.
1812 ///
1813 /// By default, performs semantic analysis to build the new expression.
1814 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001815 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001816 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001817 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001818 SourceLocation RAngleLoc,
1819 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001820 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001821 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001822 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001823 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001824 SourceRange(LAngleLoc, RAngleLoc),
1825 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001826 }
1827
1828 /// \brief Build a new C++ dynamic_cast expression.
1829 ///
1830 /// By default, performs semantic analysis to build the new expression.
1831 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001832 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001833 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001834 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001835 SourceLocation RAngleLoc,
1836 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001837 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001838 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001839 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001840 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001841 SourceRange(LAngleLoc, RAngleLoc),
1842 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001843 }
1844
1845 /// \brief Build a new C++ reinterpret_cast expression.
1846 ///
1847 /// By default, performs semantic analysis to build the new expression.
1848 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001849 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001850 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001851 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001852 SourceLocation RAngleLoc,
1853 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001854 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001855 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001856 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001857 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001858 SourceRange(LAngleLoc, RAngleLoc),
1859 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001860 }
1861
1862 /// \brief Build a new C++ const_cast expression.
1863 ///
1864 /// By default, performs semantic analysis to build the new expression.
1865 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001866 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001867 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001868 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001869 SourceLocation RAngleLoc,
1870 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001871 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001872 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001873 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001874 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001875 SourceRange(LAngleLoc, RAngleLoc),
1876 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001877 }
Mike Stump1eb44332009-09-09 15:08:12 +00001878
Douglas Gregorb98b1992009-08-11 05:31:07 +00001879 /// \brief Build a new C++ functional-style cast expression.
1880 ///
1881 /// By default, performs semantic analysis to build the new expression.
1882 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001883 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1884 SourceLocation LParenLoc,
1885 Expr *Sub,
1886 SourceLocation RParenLoc) {
1887 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001888 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 RParenLoc);
1890 }
Mike Stump1eb44332009-09-09 15:08:12 +00001891
Douglas Gregorb98b1992009-08-11 05:31:07 +00001892 /// \brief Build a new C++ typeid(type) expression.
1893 ///
1894 /// By default, performs semantic analysis to build the new expression.
1895 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001896 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001897 SourceLocation TypeidLoc,
1898 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001899 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001900 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001901 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001902 }
Mike Stump1eb44332009-09-09 15:08:12 +00001903
Francois Pichet01b7c302010-09-08 12:20:18 +00001904
Douglas Gregorb98b1992009-08-11 05:31:07 +00001905 /// \brief Build a new C++ typeid(expr) expression.
1906 ///
1907 /// By default, performs semantic analysis to build the new expression.
1908 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001909 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001910 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001911 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001912 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001913 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001914 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001915 }
1916
Francois Pichet01b7c302010-09-08 12:20:18 +00001917 /// \brief Build a new C++ __uuidof(type) expression.
1918 ///
1919 /// By default, performs semantic analysis to build the new expression.
1920 /// Subclasses may override this routine to provide different behavior.
1921 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1922 SourceLocation TypeidLoc,
1923 TypeSourceInfo *Operand,
1924 SourceLocation RParenLoc) {
1925 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1926 RParenLoc);
1927 }
1928
1929 /// \brief Build a new C++ __uuidof(expr) expression.
1930 ///
1931 /// By default, performs semantic analysis to build the new expression.
1932 /// Subclasses may override this routine to provide different behavior.
1933 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1934 SourceLocation TypeidLoc,
1935 Expr *Operand,
1936 SourceLocation RParenLoc) {
1937 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1938 RParenLoc);
1939 }
1940
Douglas Gregorb98b1992009-08-11 05:31:07 +00001941 /// \brief Build a new C++ "this" expression.
1942 ///
1943 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001944 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001945 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001946 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001947 QualType ThisType,
1948 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001949 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001950 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001951 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1952 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001953 }
1954
1955 /// \brief Build a new C++ throw expression.
1956 ///
1957 /// By default, performs semantic analysis to build the new expression.
1958 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001959 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1960 bool IsThrownVariableInScope) {
1961 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001962 }
1963
1964 /// \brief Build a new C++ default-argument expression.
1965 ///
1966 /// By default, builds a new default-argument expression, which does not
1967 /// require any semantic analysis. Subclasses may override this routine to
1968 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001969 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001970 ParmVarDecl *Param) {
1971 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1972 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001973 }
1974
1975 /// \brief Build a new C++ zero-initialization expression.
1976 ///
1977 /// By default, performs semantic analysis to build the new expression.
1978 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001979 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1980 SourceLocation LParenLoc,
1981 SourceLocation RParenLoc) {
1982 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001983 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001984 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001985 }
Mike Stump1eb44332009-09-09 15:08:12 +00001986
Douglas Gregorb98b1992009-08-11 05:31:07 +00001987 /// \brief Build a new C++ "new" expression.
1988 ///
1989 /// By default, performs semantic analysis to build the new expression.
1990 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001991 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001992 bool UseGlobal,
1993 SourceLocation PlacementLParen,
1994 MultiExprArg PlacementArgs,
1995 SourceLocation PlacementRParen,
1996 SourceRange TypeIdParens,
1997 QualType AllocatedType,
1998 TypeSourceInfo *AllocatedTypeInfo,
1999 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002000 SourceRange DirectInitRange,
2001 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002002 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002003 PlacementLParen,
2004 move(PlacementArgs),
2005 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002006 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002007 AllocatedType,
2008 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002009 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002010 DirectInitRange,
2011 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002012 }
Mike Stump1eb44332009-09-09 15:08:12 +00002013
Douglas Gregorb98b1992009-08-11 05:31:07 +00002014 /// \brief Build a new C++ "delete" expression.
2015 ///
2016 /// By default, performs semantic analysis to build the new expression.
2017 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002018 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002019 bool IsGlobalDelete,
2020 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002021 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002022 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002023 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002024 }
Mike Stump1eb44332009-09-09 15:08:12 +00002025
Douglas Gregorb98b1992009-08-11 05:31:07 +00002026 /// \brief Build a new unary type trait expression.
2027 ///
2028 /// By default, performs semantic analysis to build the new expression.
2029 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002030 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002031 SourceLocation StartLoc,
2032 TypeSourceInfo *T,
2033 SourceLocation RParenLoc) {
2034 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002035 }
2036
Francois Pichet6ad6f282010-12-07 00:08:36 +00002037 /// \brief Build a new binary type trait expression.
2038 ///
2039 /// By default, performs semantic analysis to build the new expression.
2040 /// Subclasses may override this routine to provide different behavior.
2041 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2042 SourceLocation StartLoc,
2043 TypeSourceInfo *LhsT,
2044 TypeSourceInfo *RhsT,
2045 SourceLocation RParenLoc) {
2046 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2047 }
2048
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002049 /// \brief Build a new type trait expression.
2050 ///
2051 /// By default, performs semantic analysis to build the new expression.
2052 /// Subclasses may override this routine to provide different behavior.
2053 ExprResult RebuildTypeTrait(TypeTrait Trait,
2054 SourceLocation StartLoc,
2055 ArrayRef<TypeSourceInfo *> Args,
2056 SourceLocation RParenLoc) {
2057 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2058 }
2059
John Wiegley21ff2e52011-04-28 00:16:57 +00002060 /// \brief Build a new array type trait expression.
2061 ///
2062 /// By default, performs semantic analysis to build the new expression.
2063 /// Subclasses may override this routine to provide different behavior.
2064 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2065 SourceLocation StartLoc,
2066 TypeSourceInfo *TSInfo,
2067 Expr *DimExpr,
2068 SourceLocation RParenLoc) {
2069 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2070 }
2071
John Wiegley55262202011-04-25 06:54:41 +00002072 /// \brief Build a new expression trait expression.
2073 ///
2074 /// By default, performs semantic analysis to build the new expression.
2075 /// Subclasses may override this routine to provide different behavior.
2076 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2077 SourceLocation StartLoc,
2078 Expr *Queried,
2079 SourceLocation RParenLoc) {
2080 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2081 }
2082
Mike Stump1eb44332009-09-09 15:08:12 +00002083 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002084 /// expression.
2085 ///
2086 /// By default, performs semantic analysis to build the new expression.
2087 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002088 ExprResult RebuildDependentScopeDeclRefExpr(
2089 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002090 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002091 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002092 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002093 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002094 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002095
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002096 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002097 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002098 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002099
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002100 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002101 }
2102
2103 /// \brief Build a new template-id expression.
2104 ///
2105 /// By default, performs semantic analysis to build the new expression.
2106 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002107 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002108 SourceLocation TemplateKWLoc,
2109 LookupResult &R,
2110 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002111 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002112 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2113 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002114 }
2115
2116 /// \brief Build a new object-construction expression.
2117 ///
2118 /// By default, performs semantic analysis to build the new expression.
2119 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002120 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002121 SourceLocation Loc,
2122 CXXConstructorDecl *Constructor,
2123 bool IsElidable,
2124 MultiExprArg Args,
2125 bool HadMultipleCandidates,
2126 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002127 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002128 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002129 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002130 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002131 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002132 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002133
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002134 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002135 move_arg(ConvertedArgs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002136 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002137 RequiresZeroInit, ConstructKind,
2138 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002139 }
2140
2141 /// \brief Build a new object-construction expression.
2142 ///
2143 /// By default, performs semantic analysis to build the new expression.
2144 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002145 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2146 SourceLocation LParenLoc,
2147 MultiExprArg Args,
2148 SourceLocation RParenLoc) {
2149 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002150 LParenLoc,
2151 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002152 RParenLoc);
2153 }
2154
2155 /// \brief Build a new object-construction expression.
2156 ///
2157 /// By default, performs semantic analysis to build the new expression.
2158 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002159 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2160 SourceLocation LParenLoc,
2161 MultiExprArg Args,
2162 SourceLocation RParenLoc) {
2163 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002164 LParenLoc,
2165 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002166 RParenLoc);
2167 }
Mike Stump1eb44332009-09-09 15:08:12 +00002168
Douglas Gregorb98b1992009-08-11 05:31:07 +00002169 /// \brief Build a new member reference expression.
2170 ///
2171 /// By default, performs semantic analysis to build the new expression.
2172 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002173 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002174 QualType BaseType,
2175 bool IsArrow,
2176 SourceLocation OperatorLoc,
2177 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002178 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002179 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002180 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002181 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002182 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002183 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002184
John McCall9ae2f072010-08-23 23:25:46 +00002185 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002186 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002187 SS, TemplateKWLoc,
2188 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002189 MemberNameInfo,
2190 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002191 }
2192
John McCall129e2df2009-11-30 22:42:35 +00002193 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002194 ///
2195 /// By default, performs semantic analysis to build the new expression.
2196 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002197 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2198 SourceLocation OperatorLoc,
2199 bool IsArrow,
2200 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002201 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002202 NamedDecl *FirstQualifierInScope,
2203 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002204 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002205 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002206 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002207
John McCall9ae2f072010-08-23 23:25:46 +00002208 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002209 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002210 SS, TemplateKWLoc,
2211 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002212 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002213 }
Mike Stump1eb44332009-09-09 15:08:12 +00002214
Sebastian Redl2e156222010-09-10 20:55:43 +00002215 /// \brief Build a new noexcept expression.
2216 ///
2217 /// By default, performs semantic analysis to build the new expression.
2218 /// Subclasses may override this routine to provide different behavior.
2219 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2220 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2221 }
2222
Douglas Gregoree8aff02011-01-04 17:33:58 +00002223 /// \brief Build a new expression to compute the length of a parameter pack.
2224 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2225 SourceLocation PackLoc,
2226 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002227 llvm::Optional<unsigned> Length) {
2228 if (Length)
2229 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2230 OperatorLoc, Pack, PackLoc,
2231 RParenLoc, *Length);
2232
Douglas Gregoree8aff02011-01-04 17:33:58 +00002233 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2234 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002235 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002236 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002237
Patrick Beardeb382ec2012-04-19 00:25:12 +00002238 /// \brief Build a new Objective-C boxed expression.
2239 ///
2240 /// By default, performs semantic analysis to build the new expression.
2241 /// Subclasses may override this routine to provide different behavior.
2242 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2243 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2244 }
2245
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002246 /// \brief Build a new Objective-C array literal.
2247 ///
2248 /// By default, performs semantic analysis to build the new expression.
2249 /// Subclasses may override this routine to provide different behavior.
2250 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2251 Expr **Elements, unsigned NumElements) {
2252 return getSema().BuildObjCArrayLiteral(Range,
2253 MultiExprArg(Elements, NumElements));
2254 }
2255
2256 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
2257 Expr *Base, Expr *Key,
2258 ObjCMethodDecl *getterMethod,
2259 ObjCMethodDecl *setterMethod) {
2260 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2261 getterMethod, setterMethod);
2262 }
2263
2264 /// \brief Build a new Objective-C dictionary literal.
2265 ///
2266 /// By default, performs semantic analysis to build the new expression.
2267 /// Subclasses may override this routine to provide different behavior.
2268 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2269 ObjCDictionaryElement *Elements,
2270 unsigned NumElements) {
2271 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2272 }
2273
Douglas Gregorb98b1992009-08-11 05:31:07 +00002274 /// \brief Build a new Objective-C @encode expression.
2275 ///
2276 /// By default, performs semantic analysis to build the new expression.
2277 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002278 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002279 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002280 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002281 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002282 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002283 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002284
Douglas Gregor92e986e2010-04-22 16:44:27 +00002285 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002286 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002287 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002288 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002289 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002290 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002291 MultiExprArg Args,
2292 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002293 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2294 ReceiverTypeInfo->getType(),
2295 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002296 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002297 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002298 }
2299
2300 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002301 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002302 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002303 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002304 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002305 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002306 MultiExprArg Args,
2307 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002308 return SemaRef.BuildInstanceMessage(Receiver,
2309 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002310 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002311 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002312 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002313 }
2314
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002315 /// \brief Build a new Objective-C ivar reference expression.
2316 ///
2317 /// By default, performs semantic analysis to build the new expression.
2318 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002319 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002320 SourceLocation IvarLoc,
2321 bool IsArrow, bool IsFreeIvar) {
2322 // FIXME: We lose track of the IsFreeIvar bit.
2323 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002324 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002325 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2326 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002327 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002328 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002329 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002330 false);
John Wiegley429bb272011-04-08 18:41:53 +00002331 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002332 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002333
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002334 if (Result.get())
2335 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002336
John Wiegley429bb272011-04-08 18:41:53 +00002337 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002338 /*FIXME:*/IvarLoc, IsArrow,
2339 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002340 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002341 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002342 /*TemplateArgs=*/0);
2343 }
Douglas Gregore3303542010-04-26 20:47:02 +00002344
2345 /// \brief Build a new Objective-C property reference expression.
2346 ///
2347 /// By default, performs semantic analysis to build the new expression.
2348 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002349 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002350 ObjCPropertyDecl *Property,
2351 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002352 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002353 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002354 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2355 Sema::LookupMemberName);
2356 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002357 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002358 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002359 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002360 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002361 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002362
Douglas Gregore3303542010-04-26 20:47:02 +00002363 if (Result.get())
2364 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002365
John Wiegley429bb272011-04-08 18:41:53 +00002366 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002367 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002368 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002369 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002370 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002371 /*TemplateArgs=*/0);
2372 }
Sean Huntc3021132010-05-05 15:23:54 +00002373
John McCall12f78a62010-12-02 01:19:52 +00002374 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002375 ///
2376 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002377 /// Subclasses may override this routine to provide different behavior.
2378 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2379 ObjCMethodDecl *Getter,
2380 ObjCMethodDecl *Setter,
2381 SourceLocation PropertyLoc) {
2382 // Since these expressions can only be value-dependent, we do not
2383 // need to perform semantic analysis again.
2384 return Owned(
2385 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2386 VK_LValue, OK_ObjCProperty,
2387 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002388 }
2389
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002390 /// \brief Build a new Objective-C "isa" expression.
2391 ///
2392 /// By default, performs semantic analysis to build the new expression.
2393 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002394 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002395 bool IsArrow) {
2396 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002397 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002398 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2399 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002400 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002401 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002402 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002403 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002404 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002405
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002406 if (Result.get())
2407 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002408
John Wiegley429bb272011-04-08 18:41:53 +00002409 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002410 /*FIXME:*/IsaLoc, IsArrow,
2411 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002412 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002413 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002414 /*TemplateArgs=*/0);
2415 }
Sean Huntc3021132010-05-05 15:23:54 +00002416
Douglas Gregorb98b1992009-08-11 05:31:07 +00002417 /// \brief Build a new shuffle vector expression.
2418 ///
2419 /// By default, performs semantic analysis to build the new expression.
2420 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002421 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002422 MultiExprArg SubExprs,
2423 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002424 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002425 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002426 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2427 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2428 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2429 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002430
Douglas Gregorb98b1992009-08-11 05:31:07 +00002431 // Build a reference to the __builtin_shufflevector builtin
2432 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002433 ExprResult Callee
John McCallf4b88a42012-03-10 09:33:50 +00002434 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false,
2435 Builtin->getType(),
John Wiegley429bb272011-04-08 18:41:53 +00002436 VK_LValue, BuiltinLoc));
2437 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2438 if (Callee.isInvalid())
2439 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002440
2441 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002442 unsigned NumSubExprs = SubExprs.size();
2443 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002444 ExprResult TheCall = SemaRef.Owned(
2445 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002446 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002447 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002448 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002449 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002450
Douglas Gregorb98b1992009-08-11 05:31:07 +00002451 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002452 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002453 }
John McCall43fed0d2010-11-12 08:19:04 +00002454
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002455 /// \brief Build a new template argument pack expansion.
2456 ///
2457 /// By default, performs semantic analysis to build a new pack expansion
2458 /// for a template argument. Subclasses may override this routine to provide
2459 /// different behavior.
2460 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002461 SourceLocation EllipsisLoc,
2462 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002463 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002464 case TemplateArgument::Expression: {
2465 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002466 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2467 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002468 if (Result.isInvalid())
2469 return TemplateArgumentLoc();
2470
2471 return TemplateArgumentLoc(Result.get(), Result.get());
2472 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002473
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002474 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002475 return TemplateArgumentLoc(TemplateArgument(
2476 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002477 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002478 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002479 Pattern.getTemplateNameLoc(),
2480 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002481
2482 case TemplateArgument::Null:
2483 case TemplateArgument::Integral:
2484 case TemplateArgument::Declaration:
2485 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002486 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002487 llvm_unreachable("Pack expansion pattern has no parameter packs");
2488
2489 case TemplateArgument::Type:
2490 if (TypeSourceInfo *Expansion
2491 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002492 EllipsisLoc,
2493 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002494 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2495 Expansion);
2496 break;
2497 }
2498
2499 return TemplateArgumentLoc();
2500 }
2501
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002502 /// \brief Build a new expression pack expansion.
2503 ///
2504 /// By default, performs semantic analysis to build a new pack expansion
2505 /// for an expression. Subclasses may override this routine to provide
2506 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002507 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2508 llvm::Optional<unsigned> NumExpansions) {
2509 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002510 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002511
2512 /// \brief Build a new atomic operation expression.
2513 ///
2514 /// By default, performs semantic analysis to build the new expression.
2515 /// Subclasses may override this routine to provide different behavior.
2516 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2517 MultiExprArg SubExprs,
2518 QualType RetTy,
2519 AtomicExpr::AtomicOp Op,
2520 SourceLocation RParenLoc) {
2521 // Just create the expression; there is not any interesting semantic
2522 // analysis here because we can't actually build an AtomicExpr until
2523 // we are sure it is semantically sound.
2524 unsigned NumSubExprs = SubExprs.size();
2525 Expr **Subs = (Expr **)SubExprs.release();
2526 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2527 NumSubExprs, RetTy, Op,
2528 RParenLoc);
2529 }
2530
John McCall43fed0d2010-11-12 08:19:04 +00002531private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002532 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2533 QualType ObjectType,
2534 NamedDecl *FirstQualifierInScope,
2535 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002536
2537 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2538 QualType ObjectType,
2539 NamedDecl *FirstQualifierInScope,
2540 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002541};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002542
Douglas Gregor43959a92009-08-20 07:17:43 +00002543template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002544StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002545 if (!S)
2546 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002547
Douglas Gregor43959a92009-08-20 07:17:43 +00002548 switch (S->getStmtClass()) {
2549 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002550
Douglas Gregor43959a92009-08-20 07:17:43 +00002551 // Transform individual statement nodes
2552#define STMT(Node, Parent) \
2553 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002554#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002555#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002556#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002557
Douglas Gregor43959a92009-08-20 07:17:43 +00002558 // Transform expressions by calling TransformExpr.
2559#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002560#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002561#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002562#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002563 {
John McCall60d7b3a2010-08-24 06:29:42 +00002564 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002565 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002566 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002567
John McCall9ae2f072010-08-23 23:25:46 +00002568 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002569 }
Mike Stump1eb44332009-09-09 15:08:12 +00002570 }
2571
John McCall3fa5cae2010-10-26 07:05:15 +00002572 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002573}
Mike Stump1eb44332009-09-09 15:08:12 +00002574
2575
Douglas Gregor670444e2009-08-04 22:27:00 +00002576template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002577ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002578 if (!E)
2579 return SemaRef.Owned(E);
2580
2581 switch (E->getStmtClass()) {
2582 case Stmt::NoStmtClass: break;
2583#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002584#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002585#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002586 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002587#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002588 }
2589
John McCall3fa5cae2010-10-26 07:05:15 +00002590 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002591}
2592
2593template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002594bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2595 unsigned NumInputs,
2596 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002597 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002598 bool *ArgChanged) {
2599 for (unsigned I = 0; I != NumInputs; ++I) {
2600 // If requested, drop call arguments that need to be dropped.
2601 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2602 if (ArgChanged)
2603 *ArgChanged = true;
2604
2605 break;
2606 }
2607
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002608 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2609 Expr *Pattern = Expansion->getPattern();
2610
Chris Lattner686775d2011-07-20 06:58:45 +00002611 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002612 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2613 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2614
2615 // Determine whether the set of unexpanded parameter packs can and should
2616 // be expanded.
2617 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002618 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002619 llvm::Optional<unsigned> OrigNumExpansions
2620 = Expansion->getNumExpansions();
2621 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002622 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2623 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002624 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002625 Expand, RetainExpansion,
2626 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002627 return true;
2628
2629 if (!Expand) {
2630 // The transform has determined that we should perform a simple
2631 // transformation on the pack expansion, producing another pack
2632 // expansion.
2633 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2634 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2635 if (OutPattern.isInvalid())
2636 return true;
2637
2638 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002639 Expansion->getEllipsisLoc(),
2640 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002641 if (Out.isInvalid())
2642 return true;
2643
2644 if (ArgChanged)
2645 *ArgChanged = true;
2646 Outputs.push_back(Out.get());
2647 continue;
2648 }
John McCallc8fc90a2011-07-06 07:30:07 +00002649
2650 // Record right away that the argument was changed. This needs
2651 // to happen even if the array expands to nothing.
2652 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002653
2654 // The transform has determined that we should perform an elementwise
2655 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002656 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002657 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2658 ExprResult Out = getDerived().TransformExpr(Pattern);
2659 if (Out.isInvalid())
2660 return true;
2661
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002662 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002663 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2664 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002665 if (Out.isInvalid())
2666 return true;
2667 }
2668
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002669 Outputs.push_back(Out.get());
2670 }
2671
2672 continue;
2673 }
2674
Douglas Gregoraa165f82011-01-03 19:04:46 +00002675 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2676 if (Result.isInvalid())
2677 return true;
2678
2679 if (Result.get() != Inputs[I] && ArgChanged)
2680 *ArgChanged = true;
2681
2682 Outputs.push_back(Result.get());
2683 }
2684
2685 return false;
2686}
2687
2688template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002689NestedNameSpecifierLoc
2690TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2691 NestedNameSpecifierLoc NNS,
2692 QualType ObjectType,
2693 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002694 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002695 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2696 Qualifier = Qualifier.getPrefix())
2697 Qualifiers.push_back(Qualifier);
2698
2699 CXXScopeSpec SS;
2700 while (!Qualifiers.empty()) {
2701 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2702 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2703
2704 switch (QNNS->getKind()) {
2705 case NestedNameSpecifier::Identifier:
2706 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2707 *QNNS->getAsIdentifier(),
2708 Q.getLocalBeginLoc(),
2709 Q.getLocalEndLoc(),
2710 ObjectType, false, SS,
2711 FirstQualifierInScope, false))
2712 return NestedNameSpecifierLoc();
2713
2714 break;
2715
2716 case NestedNameSpecifier::Namespace: {
2717 NamespaceDecl *NS
2718 = cast_or_null<NamespaceDecl>(
2719 getDerived().TransformDecl(
2720 Q.getLocalBeginLoc(),
2721 QNNS->getAsNamespace()));
2722 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2723 break;
2724 }
2725
2726 case NestedNameSpecifier::NamespaceAlias: {
2727 NamespaceAliasDecl *Alias
2728 = cast_or_null<NamespaceAliasDecl>(
2729 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2730 QNNS->getAsNamespaceAlias()));
2731 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2732 Q.getLocalEndLoc());
2733 break;
2734 }
2735
2736 case NestedNameSpecifier::Global:
2737 // There is no meaningful transformation that one could perform on the
2738 // global scope.
2739 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2740 break;
2741
2742 case NestedNameSpecifier::TypeSpecWithTemplate:
2743 case NestedNameSpecifier::TypeSpec: {
2744 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2745 FirstQualifierInScope, SS);
2746
2747 if (!TL)
2748 return NestedNameSpecifierLoc();
2749
2750 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
David Blaikie4e4d0842012-03-11 07:00:24 +00002751 (SemaRef.getLangOpts().CPlusPlus0x &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002752 TL.getType()->isEnumeralType())) {
2753 assert(!TL.getType().hasLocalQualifiers() &&
2754 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002755 if (TL.getType()->isEnumeralType())
2756 SemaRef.Diag(TL.getBeginLoc(),
2757 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002758 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2759 Q.getLocalEndLoc());
2760 break;
2761 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002762 // If the nested-name-specifier is an invalid type def, don't emit an
2763 // error because a previous error should have already been emitted.
2764 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2765 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2766 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2767 << TL.getType() << SS.getRange();
2768 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002769 return NestedNameSpecifierLoc();
2770 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002771 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002772
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002773 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002774 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002775 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002776 }
2777
2778 // Don't rebuild the nested-name-specifier if we don't have to.
2779 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2780 !getDerived().AlwaysRebuild())
2781 return NNS;
2782
2783 // If we can re-use the source-location data from the original
2784 // nested-name-specifier, do so.
2785 if (SS.location_size() == NNS.getDataLength() &&
2786 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2787 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2788
2789 // Allocate new nested-name-specifier location information.
2790 return SS.getWithLocInContext(SemaRef.Context);
2791}
2792
2793template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002794DeclarationNameInfo
2795TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002796::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002797 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002798 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002799 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002800
2801 switch (Name.getNameKind()) {
2802 case DeclarationName::Identifier:
2803 case DeclarationName::ObjCZeroArgSelector:
2804 case DeclarationName::ObjCOneArgSelector:
2805 case DeclarationName::ObjCMultiArgSelector:
2806 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002807 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002808 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002809 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002810
Douglas Gregor81499bb2009-09-03 22:13:48 +00002811 case DeclarationName::CXXConstructorName:
2812 case DeclarationName::CXXDestructorName:
2813 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002814 TypeSourceInfo *NewTInfo;
2815 CanQualType NewCanTy;
2816 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002817 NewTInfo = getDerived().TransformType(OldTInfo);
2818 if (!NewTInfo)
2819 return DeclarationNameInfo();
2820 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002821 }
2822 else {
2823 NewTInfo = 0;
2824 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002825 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002826 if (NewT.isNull())
2827 return DeclarationNameInfo();
2828 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2829 }
Mike Stump1eb44332009-09-09 15:08:12 +00002830
Abramo Bagnara25777432010-08-11 22:01:17 +00002831 DeclarationName NewName
2832 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2833 NewCanTy);
2834 DeclarationNameInfo NewNameInfo(NameInfo);
2835 NewNameInfo.setName(NewName);
2836 NewNameInfo.setNamedTypeInfo(NewTInfo);
2837 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002838 }
Mike Stump1eb44332009-09-09 15:08:12 +00002839 }
2840
David Blaikieb219cfc2011-09-23 05:06:16 +00002841 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002842}
2843
2844template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002845TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002846TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2847 TemplateName Name,
2848 SourceLocation NameLoc,
2849 QualType ObjectType,
2850 NamedDecl *FirstQualifierInScope) {
2851 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2852 TemplateDecl *Template = QTN->getTemplateDecl();
2853 assert(Template && "qualified template name must refer to a template");
2854
2855 TemplateDecl *TransTemplate
2856 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2857 Template));
2858 if (!TransTemplate)
2859 return TemplateName();
2860
2861 if (!getDerived().AlwaysRebuild() &&
2862 SS.getScopeRep() == QTN->getQualifier() &&
2863 TransTemplate == Template)
2864 return Name;
2865
2866 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2867 TransTemplate);
2868 }
2869
2870 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2871 if (SS.getScopeRep()) {
2872 // These apply to the scope specifier, not the template.
2873 ObjectType = QualType();
2874 FirstQualifierInScope = 0;
2875 }
2876
2877 if (!getDerived().AlwaysRebuild() &&
2878 SS.getScopeRep() == DTN->getQualifier() &&
2879 ObjectType.isNull())
2880 return Name;
2881
2882 if (DTN->isIdentifier()) {
2883 return getDerived().RebuildTemplateName(SS,
2884 *DTN->getIdentifier(),
2885 NameLoc,
2886 ObjectType,
2887 FirstQualifierInScope);
2888 }
2889
2890 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2891 ObjectType);
2892 }
2893
2894 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2895 TemplateDecl *TransTemplate
2896 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2897 Template));
2898 if (!TransTemplate)
2899 return TemplateName();
2900
2901 if (!getDerived().AlwaysRebuild() &&
2902 TransTemplate == Template)
2903 return Name;
2904
2905 return TemplateName(TransTemplate);
2906 }
2907
2908 if (SubstTemplateTemplateParmPackStorage *SubstPack
2909 = Name.getAsSubstTemplateTemplateParmPack()) {
2910 TemplateTemplateParmDecl *TransParam
2911 = cast_or_null<TemplateTemplateParmDecl>(
2912 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2913 if (!TransParam)
2914 return TemplateName();
2915
2916 if (!getDerived().AlwaysRebuild() &&
2917 TransParam == SubstPack->getParameterPack())
2918 return Name;
2919
2920 return getDerived().RebuildTemplateName(TransParam,
2921 SubstPack->getArgumentPack());
2922 }
2923
2924 // These should be getting filtered out before they reach the AST.
2925 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002926}
2927
2928template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002929void TreeTransform<Derived>::InventTemplateArgumentLoc(
2930 const TemplateArgument &Arg,
2931 TemplateArgumentLoc &Output) {
2932 SourceLocation Loc = getDerived().getBaseLocation();
2933 switch (Arg.getKind()) {
2934 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002935 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002936 break;
2937
2938 case TemplateArgument::Type:
2939 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002940 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002941
John McCall833ca992009-10-29 08:12:44 +00002942 break;
2943
Douglas Gregor788cd062009-11-11 01:00:40 +00002944 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002945 case TemplateArgument::TemplateExpansion: {
2946 NestedNameSpecifierLocBuilder Builder;
2947 TemplateName Template = Arg.getAsTemplate();
2948 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2949 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2950 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2951 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2952
2953 if (Arg.getKind() == TemplateArgument::Template)
2954 Output = TemplateArgumentLoc(Arg,
2955 Builder.getWithLocInContext(SemaRef.Context),
2956 Loc);
2957 else
2958 Output = TemplateArgumentLoc(Arg,
2959 Builder.getWithLocInContext(SemaRef.Context),
2960 Loc, Loc);
2961
Douglas Gregor788cd062009-11-11 01:00:40 +00002962 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002963 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002964
John McCall833ca992009-10-29 08:12:44 +00002965 case TemplateArgument::Expression:
2966 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2967 break;
2968
2969 case TemplateArgument::Declaration:
2970 case TemplateArgument::Integral:
2971 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002972 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002973 break;
2974 }
2975}
2976
2977template<typename Derived>
2978bool TreeTransform<Derived>::TransformTemplateArgument(
2979 const TemplateArgumentLoc &Input,
2980 TemplateArgumentLoc &Output) {
2981 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002982 switch (Arg.getKind()) {
2983 case TemplateArgument::Null:
2984 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002985 Output = Input;
2986 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002987
Douglas Gregor670444e2009-08-04 22:27:00 +00002988 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002989 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002990 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002991 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002992
2993 DI = getDerived().TransformType(DI);
2994 if (!DI) return true;
2995
2996 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2997 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002998 }
Mike Stump1eb44332009-09-09 15:08:12 +00002999
Douglas Gregor670444e2009-08-04 22:27:00 +00003000 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00003001 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00003002 DeclarationName Name;
3003 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
3004 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00003005 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003006 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00003007 if (!D) return true;
3008
John McCall828bff22009-10-29 18:45:58 +00003009 Expr *SourceExpr = Input.getSourceDeclExpression();
3010 if (SourceExpr) {
3011 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003012 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00003013 ExprResult E = getDerived().TransformExpr(SourceExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003014 E = SemaRef.ActOnConstantExpression(E);
John McCall9ae2f072010-08-23 23:25:46 +00003015 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00003016 }
3017
3018 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00003019 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003020 }
Mike Stump1eb44332009-09-09 15:08:12 +00003021
Douglas Gregor788cd062009-11-11 01:00:40 +00003022 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003023 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3024 if (QualifierLoc) {
3025 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3026 if (!QualifierLoc)
3027 return true;
3028 }
3029
Douglas Gregor1d752d72011-03-02 18:46:51 +00003030 CXXScopeSpec SS;
3031 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003032 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003033 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3034 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003035 if (Template.isNull())
3036 return true;
Sean Huntc3021132010-05-05 15:23:54 +00003037
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003038 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003039 Input.getTemplateNameLoc());
3040 return false;
3041 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003042
3043 case TemplateArgument::TemplateExpansion:
3044 llvm_unreachable("Caller should expand pack expansions");
3045
Douglas Gregor670444e2009-08-04 22:27:00 +00003046 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003047 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003048 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003049 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003050
John McCall833ca992009-10-29 08:12:44 +00003051 Expr *InputExpr = Input.getSourceExpression();
3052 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3053
Chris Lattner223de242011-04-25 20:37:58 +00003054 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003055 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003056 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003057 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003058 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003059 }
Mike Stump1eb44332009-09-09 15:08:12 +00003060
Douglas Gregor670444e2009-08-04 22:27:00 +00003061 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00003062 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00003063 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00003064 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00003065 AEnd = Arg.pack_end();
3066 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00003067
John McCall833ca992009-10-29 08:12:44 +00003068 // FIXME: preserve source information here when we start
3069 // caring about parameter packs.
3070
John McCall828bff22009-10-29 18:45:58 +00003071 TemplateArgumentLoc InputArg;
3072 TemplateArgumentLoc OutputArg;
3073 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3074 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00003075 return true;
3076
John McCall828bff22009-10-29 18:45:58 +00003077 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00003078 }
Douglas Gregor910f8002010-11-07 23:05:16 +00003079
3080 TemplateArgument *TransformedArgsPtr
3081 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3082 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3083 TransformedArgsPtr);
3084 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3085 TransformedArgs.size()),
3086 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003087 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003088 }
3089 }
Mike Stump1eb44332009-09-09 15:08:12 +00003090
Douglas Gregor670444e2009-08-04 22:27:00 +00003091 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003092 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003093}
3094
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003095/// \brief Iterator adaptor that invents template argument location information
3096/// for each of the template arguments in its underlying iterator.
3097template<typename Derived, typename InputIterator>
3098class TemplateArgumentLocInventIterator {
3099 TreeTransform<Derived> &Self;
3100 InputIterator Iter;
3101
3102public:
3103 typedef TemplateArgumentLoc value_type;
3104 typedef TemplateArgumentLoc reference;
3105 typedef typename std::iterator_traits<InputIterator>::difference_type
3106 difference_type;
3107 typedef std::input_iterator_tag iterator_category;
3108
3109 class pointer {
3110 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003111
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003112 public:
3113 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3114
3115 const TemplateArgumentLoc *operator->() const { return &Arg; }
3116 };
3117
3118 TemplateArgumentLocInventIterator() { }
3119
3120 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3121 InputIterator Iter)
3122 : Self(Self), Iter(Iter) { }
3123
3124 TemplateArgumentLocInventIterator &operator++() {
3125 ++Iter;
3126 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003127 }
3128
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003129 TemplateArgumentLocInventIterator operator++(int) {
3130 TemplateArgumentLocInventIterator Old(*this);
3131 ++(*this);
3132 return Old;
3133 }
3134
3135 reference operator*() const {
3136 TemplateArgumentLoc Result;
3137 Self.InventTemplateArgumentLoc(*Iter, Result);
3138 return Result;
3139 }
3140
3141 pointer operator->() const { return pointer(**this); }
3142
3143 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3144 const TemplateArgumentLocInventIterator &Y) {
3145 return X.Iter == Y.Iter;
3146 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003147
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003148 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3149 const TemplateArgumentLocInventIterator &Y) {
3150 return X.Iter != Y.Iter;
3151 }
3152};
3153
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003154template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003155template<typename InputIterator>
3156bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3157 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003158 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003159 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003160 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003161 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003162
3163 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3164 // Unpack argument packs, which we translate them into separate
3165 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003166 // FIXME: We could do much better if we could guarantee that the
3167 // TemplateArgumentLocInfo for the pack expansion would be usable for
3168 // all of the template arguments in the argument pack.
3169 typedef TemplateArgumentLocInventIterator<Derived,
3170 TemplateArgument::pack_iterator>
3171 PackLocIterator;
3172 if (TransformTemplateArguments(PackLocIterator(*this,
3173 In.getArgument().pack_begin()),
3174 PackLocIterator(*this,
3175 In.getArgument().pack_end()),
3176 Outputs))
3177 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003178
3179 continue;
3180 }
3181
3182 if (In.getArgument().isPackExpansion()) {
3183 // We have a pack expansion, for which we will be substituting into
3184 // the pattern.
3185 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003186 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003187 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003188 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3189 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003190
Chris Lattner686775d2011-07-20 06:58:45 +00003191 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003192 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3193 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3194
3195 // Determine whether the set of unexpanded parameter packs can and should
3196 // be expanded.
3197 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003198 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003199 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003200 if (getDerived().TryExpandParameterPacks(Ellipsis,
3201 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003202 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003203 Expand,
3204 RetainExpansion,
3205 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003206 return true;
3207
3208 if (!Expand) {
3209 // The transform has determined that we should perform a simple
3210 // transformation on the pack expansion, producing another pack
3211 // expansion.
3212 TemplateArgumentLoc OutPattern;
3213 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3214 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3215 return true;
3216
Douglas Gregorcded4f62011-01-14 17:04:44 +00003217 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3218 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003219 if (Out.getArgument().isNull())
3220 return true;
3221
3222 Outputs.addArgument(Out);
3223 continue;
3224 }
3225
3226 // The transform has determined that we should perform an elementwise
3227 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003228 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003229 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3230
3231 if (getDerived().TransformTemplateArgument(Pattern, Out))
3232 return true;
3233
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003234 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003235 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3236 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003237 if (Out.getArgument().isNull())
3238 return true;
3239 }
3240
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003241 Outputs.addArgument(Out);
3242 }
3243
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003244 // If we're supposed to retain a pack expansion, do so by temporarily
3245 // forgetting the partially-substituted parameter pack.
3246 if (RetainExpansion) {
3247 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3248
3249 if (getDerived().TransformTemplateArgument(Pattern, Out))
3250 return true;
3251
Douglas Gregorcded4f62011-01-14 17:04:44 +00003252 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3253 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003254 if (Out.getArgument().isNull())
3255 return true;
3256
3257 Outputs.addArgument(Out);
3258 }
Douglas Gregord3731192011-01-10 07:32:04 +00003259
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003260 continue;
3261 }
3262
3263 // The simple case:
3264 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003265 return true;
3266
3267 Outputs.addArgument(Out);
3268 }
3269
3270 return false;
3271
3272}
3273
Douglas Gregor577f75a2009-08-04 16:50:30 +00003274//===----------------------------------------------------------------------===//
3275// Type transformation
3276//===----------------------------------------------------------------------===//
3277
3278template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003279QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003280 if (getDerived().AlreadyTransformed(T))
3281 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003282
John McCalla2becad2009-10-21 00:40:46 +00003283 // Temporary workaround. All of these transformations should
3284 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003285 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3286 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003287
John McCall43fed0d2010-11-12 08:19:04 +00003288 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003289
John McCalla2becad2009-10-21 00:40:46 +00003290 if (!NewDI)
3291 return QualType();
3292
3293 return NewDI->getType();
3294}
3295
3296template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003297TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003298 // Refine the base location to the type's location.
3299 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3300 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003301 if (getDerived().AlreadyTransformed(DI->getType()))
3302 return DI;
3303
3304 TypeLocBuilder TLB;
3305
3306 TypeLoc TL = DI->getTypeLoc();
3307 TLB.reserve(TL.getFullDataSize());
3308
John McCall43fed0d2010-11-12 08:19:04 +00003309 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003310 if (Result.isNull())
3311 return 0;
3312
John McCalla93c9342009-12-07 02:54:59 +00003313 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003314}
3315
3316template<typename Derived>
3317QualType
John McCall43fed0d2010-11-12 08:19:04 +00003318TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003319 switch (T.getTypeLocClass()) {
3320#define ABSTRACT_TYPELOC(CLASS, PARENT)
3321#define TYPELOC(CLASS, PARENT) \
3322 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003323 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003324#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003325 }
Mike Stump1eb44332009-09-09 15:08:12 +00003326
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003327 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003328}
3329
3330/// FIXME: By default, this routine adds type qualifiers only to types
3331/// that can have qualifiers, and silently suppresses those qualifiers
3332/// that are not permitted (e.g., qualifiers on reference or function
3333/// types). This is the right thing for template instantiation, but
3334/// probably not for other clients.
3335template<typename Derived>
3336QualType
3337TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003338 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003339 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003340
John McCall43fed0d2010-11-12 08:19:04 +00003341 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003342 if (Result.isNull())
3343 return QualType();
3344
3345 // Silently suppress qualifiers if the result type can't be qualified.
3346 // FIXME: this is the right thing for template instantiation, but
3347 // probably not for other clients.
3348 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003349 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003350
John McCallf85e1932011-06-15 23:02:42 +00003351 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003352 // resulting type.
3353 if (Quals.hasObjCLifetime()) {
3354 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3355 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003356 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003357 // Objective-C ARC:
3358 // A lifetime qualifier applied to a substituted template parameter
3359 // overrides the lifetime qualifier from the template argument.
3360 if (const SubstTemplateTypeParmType *SubstTypeParam
3361 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3362 QualType Replacement = SubstTypeParam->getReplacementType();
3363 Qualifiers Qs = Replacement.getQualifiers();
3364 Qs.removeObjCLifetime();
3365 Replacement
3366 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3367 Qs);
3368 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3369 SubstTypeParam->getReplacedParameter(),
3370 Replacement);
3371 TLB.TypeWasModifiedSafely(Result);
3372 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003373 // Otherwise, complain about the addition of a qualifier to an
3374 // already-qualified type.
3375 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003376 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003377 << Result << R;
3378
Douglas Gregore559ca12011-06-17 22:11:49 +00003379 Quals.removeObjCLifetime();
3380 }
3381 }
3382 }
John McCall28654742010-06-05 06:41:15 +00003383 if (!Quals.empty()) {
3384 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3385 TLB.push<QualifiedTypeLoc>(Result);
3386 // No location information to preserve.
3387 }
John McCalla2becad2009-10-21 00:40:46 +00003388
3389 return Result;
3390}
3391
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003392template<typename Derived>
3393TypeLoc
3394TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3395 QualType ObjectType,
3396 NamedDecl *UnqualLookup,
3397 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003398 QualType T = TL.getType();
3399 if (getDerived().AlreadyTransformed(T))
3400 return TL;
3401
3402 TypeLocBuilder TLB;
3403 QualType Result;
3404
3405 if (isa<TemplateSpecializationType>(T)) {
3406 TemplateSpecializationTypeLoc SpecTL
3407 = cast<TemplateSpecializationTypeLoc>(TL);
3408
3409 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003410 getDerived().TransformTemplateName(SS,
3411 SpecTL.getTypePtr()->getTemplateName(),
3412 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003413 ObjectType, UnqualLookup);
3414 if (Template.isNull())
3415 return TypeLoc();
3416
3417 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3418 Template);
3419 } else if (isa<DependentTemplateSpecializationType>(T)) {
3420 DependentTemplateSpecializationTypeLoc SpecTL
3421 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3422
Douglas Gregora88f09f2011-02-28 17:23:35 +00003423 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003424 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003425 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003426 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003427 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003428 if (Template.isNull())
3429 return TypeLoc();
3430
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003431 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003432 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003433 Template,
3434 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003435 } else {
3436 // Nothing special needs to be done for these.
3437 Result = getDerived().TransformType(TLB, TL);
3438 }
3439
3440 if (Result.isNull())
3441 return TypeLoc();
3442
3443 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3444}
3445
Douglas Gregorb71d8212011-03-02 18:32:08 +00003446template<typename Derived>
3447TypeSourceInfo *
3448TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3449 QualType ObjectType,
3450 NamedDecl *UnqualLookup,
3451 CXXScopeSpec &SS) {
3452 // FIXME: Painfully copy-paste from the above!
3453
3454 QualType T = TSInfo->getType();
3455 if (getDerived().AlreadyTransformed(T))
3456 return TSInfo;
3457
3458 TypeLocBuilder TLB;
3459 QualType Result;
3460
3461 TypeLoc TL = TSInfo->getTypeLoc();
3462 if (isa<TemplateSpecializationType>(T)) {
3463 TemplateSpecializationTypeLoc SpecTL
3464 = cast<TemplateSpecializationTypeLoc>(TL);
3465
3466 TemplateName Template
3467 = getDerived().TransformTemplateName(SS,
3468 SpecTL.getTypePtr()->getTemplateName(),
3469 SpecTL.getTemplateNameLoc(),
3470 ObjectType, UnqualLookup);
3471 if (Template.isNull())
3472 return 0;
3473
3474 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3475 Template);
3476 } else if (isa<DependentTemplateSpecializationType>(T)) {
3477 DependentTemplateSpecializationTypeLoc SpecTL
3478 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3479
3480 TemplateName Template
3481 = getDerived().RebuildTemplateName(SS,
3482 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003483 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003484 ObjectType, UnqualLookup);
3485 if (Template.isNull())
3486 return 0;
3487
3488 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3489 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003490 Template,
3491 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003492 } else {
3493 // Nothing special needs to be done for these.
3494 Result = getDerived().TransformType(TLB, TL);
3495 }
3496
3497 if (Result.isNull())
3498 return 0;
3499
3500 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3501}
3502
John McCalla2becad2009-10-21 00:40:46 +00003503template <class TyLoc> static inline
3504QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3505 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3506 NewT.setNameLoc(T.getNameLoc());
3507 return T.getType();
3508}
3509
John McCalla2becad2009-10-21 00:40:46 +00003510template<typename Derived>
3511QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003512 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003513 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3514 NewT.setBuiltinLoc(T.getBuiltinLoc());
3515 if (T.needsExtraLocalData())
3516 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3517 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003518}
Mike Stump1eb44332009-09-09 15:08:12 +00003519
Douglas Gregor577f75a2009-08-04 16:50:30 +00003520template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003521QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003522 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003523 // FIXME: recurse?
3524 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003525}
Mike Stump1eb44332009-09-09 15:08:12 +00003526
Douglas Gregor577f75a2009-08-04 16:50:30 +00003527template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003528QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003529 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003530 QualType PointeeType
3531 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003532 if (PointeeType.isNull())
3533 return QualType();
3534
3535 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003536 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003537 // A dependent pointer type 'T *' has is being transformed such
3538 // that an Objective-C class type is being replaced for 'T'. The
3539 // resulting pointer type is an ObjCObjectPointerType, not a
3540 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003541 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003542
John McCallc12c5bb2010-05-15 11:32:37 +00003543 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3544 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003545 return Result;
3546 }
John McCall43fed0d2010-11-12 08:19:04 +00003547
Douglas Gregor92e986e2010-04-22 16:44:27 +00003548 if (getDerived().AlwaysRebuild() ||
3549 PointeeType != TL.getPointeeLoc().getType()) {
3550 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3551 if (Result.isNull())
3552 return QualType();
3553 }
John McCallf85e1932011-06-15 23:02:42 +00003554
3555 // Objective-C ARC can add lifetime qualifiers to the type that we're
3556 // pointing to.
3557 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3558
Douglas Gregor92e986e2010-04-22 16:44:27 +00003559 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3560 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003561 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003562}
Mike Stump1eb44332009-09-09 15:08:12 +00003563
3564template<typename Derived>
3565QualType
John McCalla2becad2009-10-21 00:40:46 +00003566TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003567 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003568 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003569 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3570 if (PointeeType.isNull())
3571 return QualType();
3572
3573 QualType Result = TL.getType();
3574 if (getDerived().AlwaysRebuild() ||
3575 PointeeType != TL.getPointeeLoc().getType()) {
3576 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003577 TL.getSigilLoc());
3578 if (Result.isNull())
3579 return QualType();
3580 }
3581
Douglas Gregor39968ad2010-04-22 16:50:51 +00003582 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003583 NewT.setSigilLoc(TL.getSigilLoc());
3584 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003585}
3586
John McCall85737a72009-10-30 00:06:24 +00003587/// Transforms a reference type. Note that somewhat paradoxically we
3588/// don't care whether the type itself is an l-value type or an r-value
3589/// type; we only care if the type was *written* as an l-value type
3590/// or an r-value type.
3591template<typename Derived>
3592QualType
3593TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003594 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003595 const ReferenceType *T = TL.getTypePtr();
3596
3597 // Note that this works with the pointee-as-written.
3598 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3599 if (PointeeType.isNull())
3600 return QualType();
3601
3602 QualType Result = TL.getType();
3603 if (getDerived().AlwaysRebuild() ||
3604 PointeeType != T->getPointeeTypeAsWritten()) {
3605 Result = getDerived().RebuildReferenceType(PointeeType,
3606 T->isSpelledAsLValue(),
3607 TL.getSigilLoc());
3608 if (Result.isNull())
3609 return QualType();
3610 }
3611
John McCallf85e1932011-06-15 23:02:42 +00003612 // Objective-C ARC can add lifetime qualifiers to the type that we're
3613 // referring to.
3614 TLB.TypeWasModifiedSafely(
3615 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3616
John McCall85737a72009-10-30 00:06:24 +00003617 // r-value references can be rebuilt as l-value references.
3618 ReferenceTypeLoc NewTL;
3619 if (isa<LValueReferenceType>(Result))
3620 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3621 else
3622 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3623 NewTL.setSigilLoc(TL.getSigilLoc());
3624
3625 return Result;
3626}
3627
Mike Stump1eb44332009-09-09 15:08:12 +00003628template<typename Derived>
3629QualType
John McCalla2becad2009-10-21 00:40:46 +00003630TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003631 LValueReferenceTypeLoc TL) {
3632 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003633}
3634
Mike Stump1eb44332009-09-09 15:08:12 +00003635template<typename Derived>
3636QualType
John McCalla2becad2009-10-21 00:40:46 +00003637TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003638 RValueReferenceTypeLoc TL) {
3639 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003640}
Mike Stump1eb44332009-09-09 15:08:12 +00003641
Douglas Gregor577f75a2009-08-04 16:50:30 +00003642template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003643QualType
John McCalla2becad2009-10-21 00:40:46 +00003644TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003645 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003646 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003647 if (PointeeType.isNull())
3648 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003649
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003650 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3651 TypeSourceInfo* NewClsTInfo = 0;
3652 if (OldClsTInfo) {
3653 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3654 if (!NewClsTInfo)
3655 return QualType();
3656 }
3657
3658 const MemberPointerType *T = TL.getTypePtr();
3659 QualType OldClsType = QualType(T->getClass(), 0);
3660 QualType NewClsType;
3661 if (NewClsTInfo)
3662 NewClsType = NewClsTInfo->getType();
3663 else {
3664 NewClsType = getDerived().TransformType(OldClsType);
3665 if (NewClsType.isNull())
3666 return QualType();
3667 }
Mike Stump1eb44332009-09-09 15:08:12 +00003668
John McCalla2becad2009-10-21 00:40:46 +00003669 QualType Result = TL.getType();
3670 if (getDerived().AlwaysRebuild() ||
3671 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003672 NewClsType != OldClsType) {
3673 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003674 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003675 if (Result.isNull())
3676 return QualType();
3677 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003678
John McCalla2becad2009-10-21 00:40:46 +00003679 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3680 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003681 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003682
3683 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003684}
3685
Mike Stump1eb44332009-09-09 15:08:12 +00003686template<typename Derived>
3687QualType
John McCalla2becad2009-10-21 00:40:46 +00003688TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003689 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003690 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003691 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003692 if (ElementType.isNull())
3693 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003694
John McCalla2becad2009-10-21 00:40:46 +00003695 QualType Result = TL.getType();
3696 if (getDerived().AlwaysRebuild() ||
3697 ElementType != T->getElementType()) {
3698 Result = getDerived().RebuildConstantArrayType(ElementType,
3699 T->getSizeModifier(),
3700 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003701 T->getIndexTypeCVRQualifiers(),
3702 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003703 if (Result.isNull())
3704 return QualType();
3705 }
Eli Friedman457a3772012-01-25 22:19:07 +00003706
3707 // We might have either a ConstantArrayType or a VariableArrayType now:
3708 // a ConstantArrayType is allowed to have an element type which is a
3709 // VariableArrayType if the type is dependent. Fortunately, all array
3710 // types have the same location layout.
3711 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003712 NewTL.setLBracketLoc(TL.getLBracketLoc());
3713 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003714
John McCalla2becad2009-10-21 00:40:46 +00003715 Expr *Size = TL.getSizeExpr();
3716 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003717 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3718 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003719 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003720 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003721 }
3722 NewTL.setSizeExpr(Size);
3723
3724 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003725}
Mike Stump1eb44332009-09-09 15:08:12 +00003726
Douglas Gregor577f75a2009-08-04 16:50:30 +00003727template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003728QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003729 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003730 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003731 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003732 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003733 if (ElementType.isNull())
3734 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003735
John McCalla2becad2009-10-21 00:40:46 +00003736 QualType Result = TL.getType();
3737 if (getDerived().AlwaysRebuild() ||
3738 ElementType != T->getElementType()) {
3739 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003740 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003741 T->getIndexTypeCVRQualifiers(),
3742 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003743 if (Result.isNull())
3744 return QualType();
3745 }
Sean Huntc3021132010-05-05 15:23:54 +00003746
John McCalla2becad2009-10-21 00:40:46 +00003747 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3748 NewTL.setLBracketLoc(TL.getLBracketLoc());
3749 NewTL.setRBracketLoc(TL.getRBracketLoc());
3750 NewTL.setSizeExpr(0);
3751
3752 return Result;
3753}
3754
3755template<typename Derived>
3756QualType
3757TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003758 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003759 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003760 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3761 if (ElementType.isNull())
3762 return QualType();
3763
John McCall60d7b3a2010-08-24 06:29:42 +00003764 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003765 = getDerived().TransformExpr(T->getSizeExpr());
3766 if (SizeResult.isInvalid())
3767 return QualType();
3768
John McCall9ae2f072010-08-23 23:25:46 +00003769 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003770
3771 QualType Result = TL.getType();
3772 if (getDerived().AlwaysRebuild() ||
3773 ElementType != T->getElementType() ||
3774 Size != T->getSizeExpr()) {
3775 Result = getDerived().RebuildVariableArrayType(ElementType,
3776 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003777 Size,
John McCalla2becad2009-10-21 00:40:46 +00003778 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003779 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003780 if (Result.isNull())
3781 return QualType();
3782 }
Sean Huntc3021132010-05-05 15:23:54 +00003783
John McCalla2becad2009-10-21 00:40:46 +00003784 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3785 NewTL.setLBracketLoc(TL.getLBracketLoc());
3786 NewTL.setRBracketLoc(TL.getRBracketLoc());
3787 NewTL.setSizeExpr(Size);
3788
3789 return Result;
3790}
3791
3792template<typename Derived>
3793QualType
3794TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003795 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003796 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003797 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3798 if (ElementType.isNull())
3799 return QualType();
3800
Richard Smithf6702a32011-12-20 02:08:33 +00003801 // Array bounds are constant expressions.
3802 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3803 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003804
John McCall3b657512011-01-19 10:06:00 +00003805 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3806 Expr *origSize = TL.getSizeExpr();
3807 if (!origSize) origSize = T->getSizeExpr();
3808
3809 ExprResult sizeResult
3810 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003811 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003812 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003813 return QualType();
3814
John McCall3b657512011-01-19 10:06:00 +00003815 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003816
3817 QualType Result = TL.getType();
3818 if (getDerived().AlwaysRebuild() ||
3819 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003820 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003821 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3822 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003823 size,
John McCalla2becad2009-10-21 00:40:46 +00003824 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003825 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003826 if (Result.isNull())
3827 return QualType();
3828 }
John McCalla2becad2009-10-21 00:40:46 +00003829
3830 // We might have any sort of array type now, but fortunately they
3831 // all have the same location layout.
3832 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3833 NewTL.setLBracketLoc(TL.getLBracketLoc());
3834 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003835 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003836
3837 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003838}
Mike Stump1eb44332009-09-09 15:08:12 +00003839
3840template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003841QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003842 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003843 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003844 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003845
3846 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003847 QualType ElementType = getDerived().TransformType(T->getElementType());
3848 if (ElementType.isNull())
3849 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003850
Richard Smithf6702a32011-12-20 02:08:33 +00003851 // Vector sizes are constant expressions.
3852 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3853 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003854
John McCall60d7b3a2010-08-24 06:29:42 +00003855 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003856 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003857 if (Size.isInvalid())
3858 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003859
John McCalla2becad2009-10-21 00:40:46 +00003860 QualType Result = TL.getType();
3861 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003862 ElementType != T->getElementType() ||
3863 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003864 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003865 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003866 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003867 if (Result.isNull())
3868 return QualType();
3869 }
John McCalla2becad2009-10-21 00:40:46 +00003870
3871 // Result might be dependent or not.
3872 if (isa<DependentSizedExtVectorType>(Result)) {
3873 DependentSizedExtVectorTypeLoc NewTL
3874 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3875 NewTL.setNameLoc(TL.getNameLoc());
3876 } else {
3877 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3878 NewTL.setNameLoc(TL.getNameLoc());
3879 }
3880
3881 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003882}
Mike Stump1eb44332009-09-09 15:08:12 +00003883
3884template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003885QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003886 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003887 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003888 QualType ElementType = getDerived().TransformType(T->getElementType());
3889 if (ElementType.isNull())
3890 return QualType();
3891
John McCalla2becad2009-10-21 00:40:46 +00003892 QualType Result = TL.getType();
3893 if (getDerived().AlwaysRebuild() ||
3894 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003895 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003896 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003897 if (Result.isNull())
3898 return QualType();
3899 }
Sean Huntc3021132010-05-05 15:23:54 +00003900
John McCalla2becad2009-10-21 00:40:46 +00003901 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3902 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003903
John McCalla2becad2009-10-21 00:40:46 +00003904 return Result;
3905}
3906
3907template<typename Derived>
3908QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003909 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003910 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003911 QualType ElementType = getDerived().TransformType(T->getElementType());
3912 if (ElementType.isNull())
3913 return QualType();
3914
3915 QualType Result = TL.getType();
3916 if (getDerived().AlwaysRebuild() ||
3917 ElementType != T->getElementType()) {
3918 Result = getDerived().RebuildExtVectorType(ElementType,
3919 T->getNumElements(),
3920 /*FIXME*/ SourceLocation());
3921 if (Result.isNull())
3922 return QualType();
3923 }
Sean Huntc3021132010-05-05 15:23:54 +00003924
John McCalla2becad2009-10-21 00:40:46 +00003925 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3926 NewTL.setNameLoc(TL.getNameLoc());
3927
3928 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003929}
Mike Stump1eb44332009-09-09 15:08:12 +00003930
3931template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003932ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003933TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003934 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003935 llvm::Optional<unsigned> NumExpansions,
3936 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003937 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003938 TypeSourceInfo *NewDI = 0;
3939
3940 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3941 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003942 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003943 TypeLoc OldTL = OldDI->getTypeLoc();
3944 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3945
3946 TypeLocBuilder TLB;
3947 TypeLoc NewTL = OldDI->getTypeLoc();
3948 TLB.reserve(NewTL.getFullDataSize());
3949
3950 QualType Result = getDerived().TransformType(TLB,
3951 OldExpansionTL.getPatternLoc());
3952 if (Result.isNull())
3953 return 0;
3954
3955 Result = RebuildPackExpansionType(Result,
3956 OldExpansionTL.getPatternLoc().getSourceRange(),
3957 OldExpansionTL.getEllipsisLoc(),
3958 NumExpansions);
3959 if (Result.isNull())
3960 return 0;
3961
3962 PackExpansionTypeLoc NewExpansionTL
3963 = TLB.push<PackExpansionTypeLoc>(Result);
3964 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3965 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3966 } else
3967 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003968 if (!NewDI)
3969 return 0;
3970
John McCallfb44de92011-05-01 22:35:37 +00003971 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003972 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003973
3974 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3975 OldParm->getDeclContext(),
3976 OldParm->getInnerLocStart(),
3977 OldParm->getLocation(),
3978 OldParm->getIdentifier(),
3979 NewDI->getType(),
3980 NewDI,
3981 OldParm->getStorageClass(),
3982 OldParm->getStorageClassAsWritten(),
3983 /* DefArg */ NULL);
3984 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3985 OldParm->getFunctionScopeIndex() + indexAdjustment);
3986 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003987}
3988
3989template<typename Derived>
3990bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003991 TransformFunctionTypeParams(SourceLocation Loc,
3992 ParmVarDecl **Params, unsigned NumParams,
3993 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003994 SmallVectorImpl<QualType> &OutParamTypes,
3995 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003996 int indexAdjustment = 0;
3997
Douglas Gregora009b592011-01-07 00:20:55 +00003998 for (unsigned i = 0; i != NumParams; ++i) {
3999 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004000 assert(OldParm->getFunctionScopeIndex() == i);
4001
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004002 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004003 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004004 if (OldParm->isParameterPack()) {
4005 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004006 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004007
Douglas Gregor603cfb42011-01-05 23:12:31 +00004008 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004009 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4010 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
4011 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4012 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004013 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4014
Douglas Gregor603cfb42011-01-05 23:12:31 +00004015 // Determine whether we should expand the parameter packs.
4016 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004017 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004018 llvm::Optional<unsigned> OrigNumExpansions
4019 = ExpansionTL.getTypePtr()->getNumExpansions();
4020 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004021 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4022 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004023 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004024 ShouldExpand,
4025 RetainExpansion,
4026 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004027 return true;
4028 }
4029
4030 if (ShouldExpand) {
4031 // Expand the function parameter pack into multiple, separate
4032 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004033 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004034 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004035 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4036 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004037 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004038 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004039 OrigNumExpansions,
4040 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004041 if (!NewParm)
4042 return true;
4043
Douglas Gregora009b592011-01-07 00:20:55 +00004044 OutParamTypes.push_back(NewParm->getType());
4045 if (PVars)
4046 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004047 }
Douglas Gregord3731192011-01-10 07:32:04 +00004048
4049 // If we're supposed to retain a pack expansion, do so by temporarily
4050 // forgetting the partially-substituted parameter pack.
4051 if (RetainExpansion) {
4052 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4053 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004054 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004055 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004056 OrigNumExpansions,
4057 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004058 if (!NewParm)
4059 return true;
4060
4061 OutParamTypes.push_back(NewParm->getType());
4062 if (PVars)
4063 PVars->push_back(NewParm);
4064 }
4065
John McCallfb44de92011-05-01 22:35:37 +00004066 // The next parameter should have the same adjustment as the
4067 // last thing we pushed, but we post-incremented indexAdjustment
4068 // on every push. Also, if we push nothing, the adjustment should
4069 // go down by one.
4070 indexAdjustment--;
4071
Douglas Gregor603cfb42011-01-05 23:12:31 +00004072 // We're done with the pack expansion.
4073 continue;
4074 }
4075
4076 // We'll substitute the parameter now without expanding the pack
4077 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004078 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4079 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004080 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004081 NumExpansions,
4082 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004083 } else {
4084 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004085 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004086 llvm::Optional<unsigned>(),
4087 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004088 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004089
John McCall21ef0fa2010-03-11 09:03:00 +00004090 if (!NewParm)
4091 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004092
Douglas Gregora009b592011-01-07 00:20:55 +00004093 OutParamTypes.push_back(NewParm->getType());
4094 if (PVars)
4095 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004096 continue;
4097 }
John McCall21ef0fa2010-03-11 09:03:00 +00004098
4099 // Deal with the possibility that we don't have a parameter
4100 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004101 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004102 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004103 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004104 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004105 if (const PackExpansionType *Expansion
4106 = dyn_cast<PackExpansionType>(OldType)) {
4107 // We have a function parameter pack that may need to be expanded.
4108 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004109 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004110 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4111
4112 // Determine whether we should expand the parameter packs.
4113 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004114 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004115 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004116 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004117 ShouldExpand,
4118 RetainExpansion,
4119 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004120 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004121 }
4122
4123 if (ShouldExpand) {
4124 // Expand the function parameter pack into multiple, separate
4125 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004126 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004127 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4128 QualType NewType = getDerived().TransformType(Pattern);
4129 if (NewType.isNull())
4130 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004131
Douglas Gregora009b592011-01-07 00:20:55 +00004132 OutParamTypes.push_back(NewType);
4133 if (PVars)
4134 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004135 }
4136
4137 // We're done with the pack expansion.
4138 continue;
4139 }
4140
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004141 // If we're supposed to retain a pack expansion, do so by temporarily
4142 // forgetting the partially-substituted parameter pack.
4143 if (RetainExpansion) {
4144 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4145 QualType NewType = getDerived().TransformType(Pattern);
4146 if (NewType.isNull())
4147 return true;
4148
4149 OutParamTypes.push_back(NewType);
4150 if (PVars)
4151 PVars->push_back(0);
4152 }
Douglas Gregord3731192011-01-10 07:32:04 +00004153
Douglas Gregor603cfb42011-01-05 23:12:31 +00004154 // We'll substitute the parameter now without expanding the pack
4155 // expansion.
4156 OldType = Expansion->getPattern();
4157 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004158 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4159 NewType = getDerived().TransformType(OldType);
4160 } else {
4161 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004162 }
4163
Douglas Gregor603cfb42011-01-05 23:12:31 +00004164 if (NewType.isNull())
4165 return true;
4166
4167 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004168 NewType = getSema().Context.getPackExpansionType(NewType,
4169 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004170
Douglas Gregora009b592011-01-07 00:20:55 +00004171 OutParamTypes.push_back(NewType);
4172 if (PVars)
4173 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004174 }
4175
John McCallfb44de92011-05-01 22:35:37 +00004176#ifndef NDEBUG
4177 if (PVars) {
4178 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4179 if (ParmVarDecl *parm = (*PVars)[i])
4180 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004181 }
John McCallfb44de92011-05-01 22:35:37 +00004182#endif
4183
4184 return false;
4185}
John McCall21ef0fa2010-03-11 09:03:00 +00004186
4187template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004188QualType
John McCalla2becad2009-10-21 00:40:46 +00004189TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004190 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004191 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4192}
4193
4194template<typename Derived>
4195QualType
4196TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4197 FunctionProtoTypeLoc TL,
4198 CXXRecordDecl *ThisContext,
4199 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004200 // Transform the parameters and return type.
4201 //
Richard Smithe6975e92012-04-17 00:58:00 +00004202 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004203 // When the function has a trailing return type, we instantiate the
4204 // parameters before the return type, since the return type can then refer
4205 // to the parameters themselves (via decltype, sizeof, etc.).
4206 //
Chris Lattner686775d2011-07-20 06:58:45 +00004207 SmallVector<QualType, 4> ParamTypes;
4208 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004209 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004210
Douglas Gregordab60ad2010-10-01 18:44:50 +00004211 QualType ResultType;
4212
4213 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004214 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4215 TL.getParmArray(),
4216 TL.getNumArgs(),
4217 TL.getTypePtr()->arg_type_begin(),
4218 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004219 return QualType();
4220
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004221 {
4222 // C++11 [expr.prim.general]p3:
4223 // If a declaration declares a member function or member function
4224 // template of a class X, the expression this is a prvalue of type
4225 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
4226 // and the end of the function-definition, member-declarator, or
4227 // declarator.
4228 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
4229
4230 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4231 if (ResultType.isNull())
4232 return QualType();
4233 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004234 }
4235 else {
4236 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4237 if (ResultType.isNull())
4238 return QualType();
4239
Douglas Gregora009b592011-01-07 00:20:55 +00004240 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4241 TL.getParmArray(),
4242 TL.getNumArgs(),
4243 TL.getTypePtr()->arg_type_begin(),
4244 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004245 return QualType();
4246 }
4247
Richard Smithe6975e92012-04-17 00:58:00 +00004248 // FIXME: Need to transform the exception-specification too.
4249
John McCalla2becad2009-10-21 00:40:46 +00004250 QualType Result = TL.getType();
4251 if (getDerived().AlwaysRebuild() ||
4252 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004253 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004254 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4255 Result = getDerived().RebuildFunctionProtoType(ResultType,
4256 ParamTypes.data(),
4257 ParamTypes.size(),
4258 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004259 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004260 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004261 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004262 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004263 if (Result.isNull())
4264 return QualType();
4265 }
Mike Stump1eb44332009-09-09 15:08:12 +00004266
John McCalla2becad2009-10-21 00:40:46 +00004267 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004268 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4269 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004270 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004271 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4272 NewTL.setArg(i, ParamDecls[i]);
4273
4274 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004275}
Mike Stump1eb44332009-09-09 15:08:12 +00004276
Douglas Gregor577f75a2009-08-04 16:50:30 +00004277template<typename Derived>
4278QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004279 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004280 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004281 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004282 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4283 if (ResultType.isNull())
4284 return QualType();
4285
4286 QualType Result = TL.getType();
4287 if (getDerived().AlwaysRebuild() ||
4288 ResultType != T->getResultType())
4289 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4290
4291 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004292 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4293 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004294 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004295
4296 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004297}
Mike Stump1eb44332009-09-09 15:08:12 +00004298
John McCalled976492009-12-04 22:46:56 +00004299template<typename Derived> QualType
4300TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004301 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004302 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004303 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004304 if (!D)
4305 return QualType();
4306
4307 QualType Result = TL.getType();
4308 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4309 Result = getDerived().RebuildUnresolvedUsingType(D);
4310 if (Result.isNull())
4311 return QualType();
4312 }
4313
4314 // We might get an arbitrary type spec type back. We should at
4315 // least always get a type spec type, though.
4316 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4317 NewTL.setNameLoc(TL.getNameLoc());
4318
4319 return Result;
4320}
4321
Douglas Gregor577f75a2009-08-04 16:50:30 +00004322template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004323QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004324 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004325 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004326 TypedefNameDecl *Typedef
4327 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4328 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004329 if (!Typedef)
4330 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004331
John McCalla2becad2009-10-21 00:40:46 +00004332 QualType Result = TL.getType();
4333 if (getDerived().AlwaysRebuild() ||
4334 Typedef != T->getDecl()) {
4335 Result = getDerived().RebuildTypedefType(Typedef);
4336 if (Result.isNull())
4337 return QualType();
4338 }
Mike Stump1eb44332009-09-09 15:08:12 +00004339
John McCalla2becad2009-10-21 00:40:46 +00004340 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4341 NewTL.setNameLoc(TL.getNameLoc());
4342
4343 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004344}
Mike Stump1eb44332009-09-09 15:08:12 +00004345
Douglas Gregor577f75a2009-08-04 16:50:30 +00004346template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004347QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004348 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004349 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004350 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004351
John McCall60d7b3a2010-08-24 06:29:42 +00004352 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004353 if (E.isInvalid())
4354 return QualType();
4355
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004356 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4357 if (E.isInvalid())
4358 return QualType();
4359
John McCalla2becad2009-10-21 00:40:46 +00004360 QualType Result = TL.getType();
4361 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004362 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004363 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004364 if (Result.isNull())
4365 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004366 }
John McCalla2becad2009-10-21 00:40:46 +00004367 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004368
John McCalla2becad2009-10-21 00:40:46 +00004369 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004370 NewTL.setTypeofLoc(TL.getTypeofLoc());
4371 NewTL.setLParenLoc(TL.getLParenLoc());
4372 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004373
4374 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004375}
Mike Stump1eb44332009-09-09 15:08:12 +00004376
4377template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004378QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004379 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004380 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4381 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4382 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004383 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004384
John McCalla2becad2009-10-21 00:40:46 +00004385 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004386 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4387 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004388 if (Result.isNull())
4389 return QualType();
4390 }
Mike Stump1eb44332009-09-09 15:08:12 +00004391
John McCalla2becad2009-10-21 00:40:46 +00004392 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004393 NewTL.setTypeofLoc(TL.getTypeofLoc());
4394 NewTL.setLParenLoc(TL.getLParenLoc());
4395 NewTL.setRParenLoc(TL.getRParenLoc());
4396 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004397
4398 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004399}
Mike Stump1eb44332009-09-09 15:08:12 +00004400
4401template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004402QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004403 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004404 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004405
Douglas Gregor670444e2009-08-04 22:27:00 +00004406 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004407 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4408 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004409
John McCall60d7b3a2010-08-24 06:29:42 +00004410 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004411 if (E.isInvalid())
4412 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004413
Richard Smith76f3f692012-02-22 02:04:18 +00004414 E = getSema().ActOnDecltypeExpression(E.take());
4415 if (E.isInvalid())
4416 return QualType();
4417
John McCalla2becad2009-10-21 00:40:46 +00004418 QualType Result = TL.getType();
4419 if (getDerived().AlwaysRebuild() ||
4420 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004421 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004422 if (Result.isNull())
4423 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004424 }
John McCalla2becad2009-10-21 00:40:46 +00004425 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004426
John McCalla2becad2009-10-21 00:40:46 +00004427 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4428 NewTL.setNameLoc(TL.getNameLoc());
4429
4430 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004431}
4432
4433template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004434QualType TreeTransform<Derived>::TransformUnaryTransformType(
4435 TypeLocBuilder &TLB,
4436 UnaryTransformTypeLoc TL) {
4437 QualType Result = TL.getType();
4438 if (Result->isDependentType()) {
4439 const UnaryTransformType *T = TL.getTypePtr();
4440 QualType NewBase =
4441 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4442 Result = getDerived().RebuildUnaryTransformType(NewBase,
4443 T->getUTTKind(),
4444 TL.getKWLoc());
4445 if (Result.isNull())
4446 return QualType();
4447 }
4448
4449 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4450 NewTL.setKWLoc(TL.getKWLoc());
4451 NewTL.setParensRange(TL.getParensRange());
4452 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4453 return Result;
4454}
4455
4456template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004457QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4458 AutoTypeLoc TL) {
4459 const AutoType *T = TL.getTypePtr();
4460 QualType OldDeduced = T->getDeducedType();
4461 QualType NewDeduced;
4462 if (!OldDeduced.isNull()) {
4463 NewDeduced = getDerived().TransformType(OldDeduced);
4464 if (NewDeduced.isNull())
4465 return QualType();
4466 }
4467
4468 QualType Result = TL.getType();
4469 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4470 Result = getDerived().RebuildAutoType(NewDeduced);
4471 if (Result.isNull())
4472 return QualType();
4473 }
4474
4475 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4476 NewTL.setNameLoc(TL.getNameLoc());
4477
4478 return Result;
4479}
4480
4481template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004482QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004483 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004484 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004485 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004486 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4487 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004488 if (!Record)
4489 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004490
John McCalla2becad2009-10-21 00:40:46 +00004491 QualType Result = TL.getType();
4492 if (getDerived().AlwaysRebuild() ||
4493 Record != T->getDecl()) {
4494 Result = getDerived().RebuildRecordType(Record);
4495 if (Result.isNull())
4496 return QualType();
4497 }
Mike Stump1eb44332009-09-09 15:08:12 +00004498
John McCalla2becad2009-10-21 00:40:46 +00004499 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4500 NewTL.setNameLoc(TL.getNameLoc());
4501
4502 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004503}
Mike Stump1eb44332009-09-09 15:08:12 +00004504
4505template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004506QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004507 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004508 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004509 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004510 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4511 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004512 if (!Enum)
4513 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004514
John McCalla2becad2009-10-21 00:40:46 +00004515 QualType Result = TL.getType();
4516 if (getDerived().AlwaysRebuild() ||
4517 Enum != T->getDecl()) {
4518 Result = getDerived().RebuildEnumType(Enum);
4519 if (Result.isNull())
4520 return QualType();
4521 }
Mike Stump1eb44332009-09-09 15:08:12 +00004522
John McCalla2becad2009-10-21 00:40:46 +00004523 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4524 NewTL.setNameLoc(TL.getNameLoc());
4525
4526 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004527}
John McCall7da24312009-09-05 00:15:47 +00004528
John McCall3cb0ebd2010-03-10 03:28:59 +00004529template<typename Derived>
4530QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4531 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004532 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004533 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4534 TL.getTypePtr()->getDecl());
4535 if (!D) return QualType();
4536
4537 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4538 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4539 return T;
4540}
4541
Douglas Gregor577f75a2009-08-04 16:50:30 +00004542template<typename Derived>
4543QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004544 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004545 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004546 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004547}
4548
Mike Stump1eb44332009-09-09 15:08:12 +00004549template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004550QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004551 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004552 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004553 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4554
4555 // Substitute into the replacement type, which itself might involve something
4556 // that needs to be transformed. This only tends to occur with default
4557 // template arguments of template template parameters.
4558 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4559 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4560 if (Replacement.isNull())
4561 return QualType();
4562
4563 // Always canonicalize the replacement type.
4564 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4565 QualType Result
4566 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4567 Replacement);
4568
4569 // Propagate type-source information.
4570 SubstTemplateTypeParmTypeLoc NewTL
4571 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4572 NewTL.setNameLoc(TL.getNameLoc());
4573 return Result;
4574
John McCall49a832b2009-10-18 09:09:24 +00004575}
4576
4577template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004578QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4579 TypeLocBuilder &TLB,
4580 SubstTemplateTypeParmPackTypeLoc TL) {
4581 return TransformTypeSpecType(TLB, TL);
4582}
4583
4584template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004585QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004586 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004587 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004588 const TemplateSpecializationType *T = TL.getTypePtr();
4589
Douglas Gregor1d752d72011-03-02 18:46:51 +00004590 // The nested-name-specifier never matters in a TemplateSpecializationType,
4591 // because we can't have a dependent nested-name-specifier anyway.
4592 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004593 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004594 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4595 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004596 if (Template.isNull())
4597 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004598
John McCall43fed0d2010-11-12 08:19:04 +00004599 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4600}
4601
Eli Friedmanb001de72011-10-06 23:00:33 +00004602template<typename Derived>
4603QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4604 AtomicTypeLoc TL) {
4605 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4606 if (ValueType.isNull())
4607 return QualType();
4608
4609 QualType Result = TL.getType();
4610 if (getDerived().AlwaysRebuild() ||
4611 ValueType != TL.getValueLoc().getType()) {
4612 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4613 if (Result.isNull())
4614 return QualType();
4615 }
4616
4617 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4618 NewTL.setKWLoc(TL.getKWLoc());
4619 NewTL.setLParenLoc(TL.getLParenLoc());
4620 NewTL.setRParenLoc(TL.getRParenLoc());
4621
4622 return Result;
4623}
4624
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004625namespace {
4626 /// \brief Simple iterator that traverses the template arguments in a
4627 /// container that provides a \c getArgLoc() member function.
4628 ///
4629 /// This iterator is intended to be used with the iterator form of
4630 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4631 template<typename ArgLocContainer>
4632 class TemplateArgumentLocContainerIterator {
4633 ArgLocContainer *Container;
4634 unsigned Index;
4635
4636 public:
4637 typedef TemplateArgumentLoc value_type;
4638 typedef TemplateArgumentLoc reference;
4639 typedef int difference_type;
4640 typedef std::input_iterator_tag iterator_category;
4641
4642 class pointer {
4643 TemplateArgumentLoc Arg;
4644
4645 public:
4646 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4647
4648 const TemplateArgumentLoc *operator->() const {
4649 return &Arg;
4650 }
4651 };
4652
4653
4654 TemplateArgumentLocContainerIterator() {}
4655
4656 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4657 unsigned Index)
4658 : Container(&Container), Index(Index) { }
4659
4660 TemplateArgumentLocContainerIterator &operator++() {
4661 ++Index;
4662 return *this;
4663 }
4664
4665 TemplateArgumentLocContainerIterator operator++(int) {
4666 TemplateArgumentLocContainerIterator Old(*this);
4667 ++(*this);
4668 return Old;
4669 }
4670
4671 TemplateArgumentLoc operator*() const {
4672 return Container->getArgLoc(Index);
4673 }
4674
4675 pointer operator->() const {
4676 return pointer(Container->getArgLoc(Index));
4677 }
4678
4679 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004680 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004681 return X.Container == Y.Container && X.Index == Y.Index;
4682 }
4683
4684 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004685 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004686 return !(X == Y);
4687 }
4688 };
4689}
4690
4691
John McCall43fed0d2010-11-12 08:19:04 +00004692template <typename Derived>
4693QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4694 TypeLocBuilder &TLB,
4695 TemplateSpecializationTypeLoc TL,
4696 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004697 TemplateArgumentListInfo NewTemplateArgs;
4698 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4699 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004700 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4701 ArgIterator;
4702 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4703 ArgIterator(TL, TL.getNumArgs()),
4704 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004705 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004706
John McCall833ca992009-10-29 08:12:44 +00004707 // FIXME: maybe don't rebuild if all the template arguments are the same.
4708
4709 QualType Result =
4710 getDerived().RebuildTemplateSpecializationType(Template,
4711 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004712 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004713
4714 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004715 // Specializations of template template parameters are represented as
4716 // TemplateSpecializationTypes, and substitution of type alias templates
4717 // within a dependent context can transform them into
4718 // DependentTemplateSpecializationTypes.
4719 if (isa<DependentTemplateSpecializationType>(Result)) {
4720 DependentTemplateSpecializationTypeLoc NewTL
4721 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004722 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004723 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004724 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004725 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004726 NewTL.setLAngleLoc(TL.getLAngleLoc());
4727 NewTL.setRAngleLoc(TL.getRAngleLoc());
4728 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4729 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4730 return Result;
4731 }
4732
John McCall833ca992009-10-29 08:12:44 +00004733 TemplateSpecializationTypeLoc NewTL
4734 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004735 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004736 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4737 NewTL.setLAngleLoc(TL.getLAngleLoc());
4738 NewTL.setRAngleLoc(TL.getRAngleLoc());
4739 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4740 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004741 }
Mike Stump1eb44332009-09-09 15:08:12 +00004742
John McCall833ca992009-10-29 08:12:44 +00004743 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004744}
Mike Stump1eb44332009-09-09 15:08:12 +00004745
Douglas Gregora88f09f2011-02-28 17:23:35 +00004746template <typename Derived>
4747QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4748 TypeLocBuilder &TLB,
4749 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004750 TemplateName Template,
4751 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004752 TemplateArgumentListInfo NewTemplateArgs;
4753 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4754 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4755 typedef TemplateArgumentLocContainerIterator<
4756 DependentTemplateSpecializationTypeLoc> ArgIterator;
4757 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4758 ArgIterator(TL, TL.getNumArgs()),
4759 NewTemplateArgs))
4760 return QualType();
4761
4762 // FIXME: maybe don't rebuild if all the template arguments are the same.
4763
4764 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4765 QualType Result
4766 = getSema().Context.getDependentTemplateSpecializationType(
4767 TL.getTypePtr()->getKeyword(),
4768 DTN->getQualifier(),
4769 DTN->getIdentifier(),
4770 NewTemplateArgs);
4771
4772 DependentTemplateSpecializationTypeLoc NewTL
4773 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004774 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004775 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004776 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004777 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004778 NewTL.setLAngleLoc(TL.getLAngleLoc());
4779 NewTL.setRAngleLoc(TL.getRAngleLoc());
4780 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4781 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4782 return Result;
4783 }
4784
4785 QualType Result
4786 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004787 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004788 NewTemplateArgs);
4789
4790 if (!Result.isNull()) {
4791 /// FIXME: Wrap this in an elaborated-type-specifier?
4792 TemplateSpecializationTypeLoc NewTL
4793 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004794 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004795 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004796 NewTL.setLAngleLoc(TL.getLAngleLoc());
4797 NewTL.setRAngleLoc(TL.getRAngleLoc());
4798 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4799 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4800 }
4801
4802 return Result;
4803}
4804
Mike Stump1eb44332009-09-09 15:08:12 +00004805template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004806QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004807TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004808 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004809 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004810
Douglas Gregor9e876872011-03-01 18:12:44 +00004811 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004812 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004813 if (TL.getQualifierLoc()) {
4814 QualifierLoc
4815 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4816 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004817 return QualType();
4818 }
Mike Stump1eb44332009-09-09 15:08:12 +00004819
John McCall43fed0d2010-11-12 08:19:04 +00004820 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4821 if (NamedT.isNull())
4822 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004823
Richard Smith3e4c6c42011-05-05 21:57:07 +00004824 // C++0x [dcl.type.elab]p2:
4825 // If the identifier resolves to a typedef-name or the simple-template-id
4826 // resolves to an alias template specialization, the
4827 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004828 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4829 if (const TemplateSpecializationType *TST =
4830 NamedT->getAs<TemplateSpecializationType>()) {
4831 TemplateName Template = TST->getTemplateName();
4832 if (TypeAliasTemplateDecl *TAT =
4833 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4834 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4835 diag::err_tag_reference_non_tag) << 4;
4836 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4837 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004838 }
4839 }
4840
John McCalla2becad2009-10-21 00:40:46 +00004841 QualType Result = TL.getType();
4842 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004843 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004844 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004845 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004846 T->getKeyword(),
4847 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004848 if (Result.isNull())
4849 return QualType();
4850 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004851
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004852 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004853 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004854 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004855 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004856}
Mike Stump1eb44332009-09-09 15:08:12 +00004857
4858template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004859QualType TreeTransform<Derived>::TransformAttributedType(
4860 TypeLocBuilder &TLB,
4861 AttributedTypeLoc TL) {
4862 const AttributedType *oldType = TL.getTypePtr();
4863 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4864 if (modifiedType.isNull())
4865 return QualType();
4866
4867 QualType result = TL.getType();
4868
4869 // FIXME: dependent operand expressions?
4870 if (getDerived().AlwaysRebuild() ||
4871 modifiedType != oldType->getModifiedType()) {
4872 // TODO: this is really lame; we should really be rebuilding the
4873 // equivalent type from first principles.
4874 QualType equivalentType
4875 = getDerived().TransformType(oldType->getEquivalentType());
4876 if (equivalentType.isNull())
4877 return QualType();
4878 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4879 modifiedType,
4880 equivalentType);
4881 }
4882
4883 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4884 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4885 if (TL.hasAttrOperand())
4886 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4887 if (TL.hasAttrExprOperand())
4888 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4889 else if (TL.hasAttrEnumOperand())
4890 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4891
4892 return result;
4893}
4894
4895template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004896QualType
4897TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4898 ParenTypeLoc TL) {
4899 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4900 if (Inner.isNull())
4901 return QualType();
4902
4903 QualType Result = TL.getType();
4904 if (getDerived().AlwaysRebuild() ||
4905 Inner != TL.getInnerLoc().getType()) {
4906 Result = getDerived().RebuildParenType(Inner);
4907 if (Result.isNull())
4908 return QualType();
4909 }
4910
4911 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4912 NewTL.setLParenLoc(TL.getLParenLoc());
4913 NewTL.setRParenLoc(TL.getRParenLoc());
4914 return Result;
4915}
4916
4917template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004918QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004919 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004920 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004921
Douglas Gregor2494dd02011-03-01 01:34:45 +00004922 NestedNameSpecifierLoc QualifierLoc
4923 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4924 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004925 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004926
John McCall33500952010-06-11 00:33:02 +00004927 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004928 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004929 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004930 QualifierLoc,
4931 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004932 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004933 if (Result.isNull())
4934 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004935
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004936 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4937 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004938 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4939
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004940 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004941 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004942 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004943 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004944 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004945 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004946 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004947 NewTL.setNameLoc(TL.getNameLoc());
4948 }
John McCalla2becad2009-10-21 00:40:46 +00004949 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004950}
Mike Stump1eb44332009-09-09 15:08:12 +00004951
Douglas Gregor577f75a2009-08-04 16:50:30 +00004952template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004953QualType TreeTransform<Derived>::
4954 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004955 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004956 NestedNameSpecifierLoc QualifierLoc;
4957 if (TL.getQualifierLoc()) {
4958 QualifierLoc
4959 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4960 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004961 return QualType();
4962 }
4963
John McCall43fed0d2010-11-12 08:19:04 +00004964 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004965 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004966}
4967
4968template<typename Derived>
4969QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004970TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4971 DependentTemplateSpecializationTypeLoc TL,
4972 NestedNameSpecifierLoc QualifierLoc) {
4973 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4974
4975 TemplateArgumentListInfo NewTemplateArgs;
4976 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4977 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4978
4979 typedef TemplateArgumentLocContainerIterator<
4980 DependentTemplateSpecializationTypeLoc> ArgIterator;
4981 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4982 ArgIterator(TL, TL.getNumArgs()),
4983 NewTemplateArgs))
4984 return QualType();
4985
4986 QualType Result
4987 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4988 QualifierLoc,
4989 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004990 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004991 NewTemplateArgs);
4992 if (Result.isNull())
4993 return QualType();
4994
4995 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4996 QualType NamedT = ElabT->getNamedType();
4997
4998 // Copy information relevant to the template specialization.
4999 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005000 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005001 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005002 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005003 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5004 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005005 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005006 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005007
5008 // Copy information relevant to the elaborated type.
5009 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005010 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005011 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005012 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5013 DependentTemplateSpecializationTypeLoc SpecTL
5014 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005015 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005016 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005017 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005018 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005019 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5020 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005021 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005022 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005023 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005024 TemplateSpecializationTypeLoc SpecTL
5025 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005026 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005027 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005028 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5029 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005030 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005031 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005032 }
5033 return Result;
5034}
5035
5036template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005037QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5038 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005039 QualType Pattern
5040 = getDerived().TransformType(TLB, TL.getPatternLoc());
5041 if (Pattern.isNull())
5042 return QualType();
5043
5044 QualType Result = TL.getType();
5045 if (getDerived().AlwaysRebuild() ||
5046 Pattern != TL.getPatternLoc().getType()) {
5047 Result = getDerived().RebuildPackExpansionType(Pattern,
5048 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005049 TL.getEllipsisLoc(),
5050 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005051 if (Result.isNull())
5052 return QualType();
5053 }
5054
5055 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5056 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5057 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005058}
5059
5060template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005061QualType
5062TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005063 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005064 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005065 TLB.pushFullCopy(TL);
5066 return TL.getType();
5067}
5068
5069template<typename Derived>
5070QualType
5071TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005072 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005073 // ObjCObjectType is never dependent.
5074 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005075 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005076}
Mike Stump1eb44332009-09-09 15:08:12 +00005077
5078template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005079QualType
5080TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005081 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005082 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005083 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005084 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005085}
5086
Douglas Gregor577f75a2009-08-04 16:50:30 +00005087//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005088// Statement transformation
5089//===----------------------------------------------------------------------===//
5090template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005091StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005092TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005093 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005094}
5095
5096template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005097StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005098TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5099 return getDerived().TransformCompoundStmt(S, false);
5100}
5101
5102template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005103StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005104TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005105 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005106 Sema::CompoundScopeRAII CompoundScope(getSema());
5107
John McCall7114cba2010-08-27 19:56:05 +00005108 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005109 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005110 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00005111 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5112 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005113 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005114 if (Result.isInvalid()) {
5115 // Immediately fail if this was a DeclStmt, since it's very
5116 // likely that this will cause problems for future statements.
5117 if (isa<DeclStmt>(*B))
5118 return StmtError();
5119
5120 // Otherwise, just keep processing substatements and fail later.
5121 SubStmtInvalid = true;
5122 continue;
5123 }
Mike Stump1eb44332009-09-09 15:08:12 +00005124
Douglas Gregor43959a92009-08-20 07:17:43 +00005125 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5126 Statements.push_back(Result.takeAs<Stmt>());
5127 }
Mike Stump1eb44332009-09-09 15:08:12 +00005128
John McCall7114cba2010-08-27 19:56:05 +00005129 if (SubStmtInvalid)
5130 return StmtError();
5131
Douglas Gregor43959a92009-08-20 07:17:43 +00005132 if (!getDerived().AlwaysRebuild() &&
5133 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005134 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005135
5136 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5137 move_arg(Statements),
5138 S->getRBracLoc(),
5139 IsStmtExpr);
5140}
Mike Stump1eb44332009-09-09 15:08:12 +00005141
Douglas Gregor43959a92009-08-20 07:17:43 +00005142template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005143StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005144TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005145 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005146 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005147 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5148 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005149
Eli Friedman264c1f82009-11-19 03:14:00 +00005150 // Transform the left-hand case value.
5151 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005152 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005153 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005154 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005155
Eli Friedman264c1f82009-11-19 03:14:00 +00005156 // Transform the right-hand case value (for the GNU case-range extension).
5157 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005158 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005159 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005160 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005161 }
Mike Stump1eb44332009-09-09 15:08:12 +00005162
Douglas Gregor43959a92009-08-20 07:17:43 +00005163 // Build the case statement.
5164 // Case statements are always rebuilt so that they will attached to their
5165 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005166 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005167 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005168 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005169 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005170 S->getColonLoc());
5171 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005172 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005173
Douglas Gregor43959a92009-08-20 07:17:43 +00005174 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005175 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005176 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005177 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005178
Douglas Gregor43959a92009-08-20 07:17:43 +00005179 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005180 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005181}
5182
5183template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005184StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005185TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005186 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005187 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005188 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005189 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005190
Douglas Gregor43959a92009-08-20 07:17:43 +00005191 // Default statements are always rebuilt
5192 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005193 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005194}
Mike Stump1eb44332009-09-09 15:08:12 +00005195
Douglas Gregor43959a92009-08-20 07:17:43 +00005196template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005197StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005198TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005199 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005200 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005201 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005202
Chris Lattner57ad3782011-02-17 20:34:02 +00005203 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5204 S->getDecl());
5205 if (!LD)
5206 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005207
5208
Douglas Gregor43959a92009-08-20 07:17:43 +00005209 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005210 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005211 cast<LabelDecl>(LD), SourceLocation(),
5212 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005213}
Mike Stump1eb44332009-09-09 15:08:12 +00005214
Douglas Gregor43959a92009-08-20 07:17:43 +00005215template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005216StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005217TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5218 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5219 if (SubStmt.isInvalid())
5220 return StmtError();
5221
5222 // TODO: transform attributes
5223 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5224 return S;
5225
5226 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5227 S->getAttrs(),
5228 SubStmt.get());
5229}
5230
5231template<typename Derived>
5232StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005233TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005234 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005235 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005236 VarDecl *ConditionVar = 0;
5237 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005238 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005239 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005240 getDerived().TransformDefinition(
5241 S->getConditionVariable()->getLocation(),
5242 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005243 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005244 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005245 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005246 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005247
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005248 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005249 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005250
5251 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005252 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005253 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5254 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005255 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005256 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005257
John McCall9ae2f072010-08-23 23:25:46 +00005258 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005259 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005260 }
Sean Huntc3021132010-05-05 15:23:54 +00005261
John McCall9ae2f072010-08-23 23:25:46 +00005262 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5263 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005264 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005265
Douglas Gregor43959a92009-08-20 07:17:43 +00005266 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005267 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005268 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005269 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005270
Douglas Gregor43959a92009-08-20 07:17:43 +00005271 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005272 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005273 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005274 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005275
Douglas Gregor43959a92009-08-20 07:17:43 +00005276 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005277 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005278 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005279 Then.get() == S->getThen() &&
5280 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005281 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005282
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005283 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005284 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005285 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005286}
5287
5288template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005289StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005290TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005291 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005292 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005293 VarDecl *ConditionVar = 0;
5294 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005295 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005296 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005297 getDerived().TransformDefinition(
5298 S->getConditionVariable()->getLocation(),
5299 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005300 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005301 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005302 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005303 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005304
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005305 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005306 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005307 }
Mike Stump1eb44332009-09-09 15:08:12 +00005308
Douglas Gregor43959a92009-08-20 07:17:43 +00005309 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005310 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005311 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005312 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005313 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005314 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005315
Douglas Gregor43959a92009-08-20 07:17:43 +00005316 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005317 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005318 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005319 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005320
Douglas Gregor43959a92009-08-20 07:17:43 +00005321 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005322 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5323 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005324}
Mike Stump1eb44332009-09-09 15:08:12 +00005325
Douglas Gregor43959a92009-08-20 07:17:43 +00005326template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005327StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005328TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005329 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005330 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005331 VarDecl *ConditionVar = 0;
5332 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005333 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005334 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005335 getDerived().TransformDefinition(
5336 S->getConditionVariable()->getLocation(),
5337 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005338 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005339 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005340 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005341 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005342
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005343 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005344 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005345
5346 if (S->getCond()) {
5347 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005348 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5349 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005350 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005351 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005352 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005353 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005354 }
Mike Stump1eb44332009-09-09 15:08:12 +00005355
John McCall9ae2f072010-08-23 23:25:46 +00005356 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5357 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005358 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005359
Douglas Gregor43959a92009-08-20 07:17:43 +00005360 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005361 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005362 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005363 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005364
Douglas Gregor43959a92009-08-20 07:17:43 +00005365 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005366 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005367 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005368 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005369 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005370
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005371 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005372 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005373}
Mike Stump1eb44332009-09-09 15:08:12 +00005374
Douglas Gregor43959a92009-08-20 07:17:43 +00005375template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005376StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005377TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005378 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005379 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005380 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005381 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005382
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005383 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005384 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005385 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005386 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005387
Douglas Gregor43959a92009-08-20 07:17:43 +00005388 if (!getDerived().AlwaysRebuild() &&
5389 Cond.get() == S->getCond() &&
5390 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005391 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005392
John McCall9ae2f072010-08-23 23:25:46 +00005393 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5394 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005395 S->getRParenLoc());
5396}
Mike Stump1eb44332009-09-09 15:08:12 +00005397
Douglas Gregor43959a92009-08-20 07:17:43 +00005398template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005399StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005400TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005401 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005402 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005403 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005404 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005405
Douglas Gregor43959a92009-08-20 07:17:43 +00005406 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005407 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005408 VarDecl *ConditionVar = 0;
5409 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005410 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005411 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005412 getDerived().TransformDefinition(
5413 S->getConditionVariable()->getLocation(),
5414 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005415 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005416 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005417 } else {
5418 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005419
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005420 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005421 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005422
5423 if (S->getCond()) {
5424 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005425 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5426 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005427 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005428 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005429
John McCall9ae2f072010-08-23 23:25:46 +00005430 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005431 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005432 }
Mike Stump1eb44332009-09-09 15:08:12 +00005433
John McCall9ae2f072010-08-23 23:25:46 +00005434 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5435 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005436 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005437
Douglas Gregor43959a92009-08-20 07:17:43 +00005438 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005439 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005440 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005441 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005442
John McCall9ae2f072010-08-23 23:25:46 +00005443 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5444 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005445 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005446
Douglas Gregor43959a92009-08-20 07:17:43 +00005447 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005448 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005449 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005450 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005451
Douglas Gregor43959a92009-08-20 07:17:43 +00005452 if (!getDerived().AlwaysRebuild() &&
5453 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005454 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005455 Inc.get() == S->getInc() &&
5456 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005457 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005458
Douglas Gregor43959a92009-08-20 07:17:43 +00005459 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005460 Init.get(), FullCond, ConditionVar,
5461 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005462}
5463
5464template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005465StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005466TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005467 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5468 S->getLabel());
5469 if (!LD)
5470 return StmtError();
5471
Douglas Gregor43959a92009-08-20 07:17:43 +00005472 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005473 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005474 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005475}
5476
5477template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005478StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005479TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005480 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005481 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005482 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005483 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005484
Douglas Gregor43959a92009-08-20 07:17:43 +00005485 if (!getDerived().AlwaysRebuild() &&
5486 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005487 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005488
5489 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005490 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005491}
5492
5493template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005494StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005495TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005496 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005497}
Mike Stump1eb44332009-09-09 15:08:12 +00005498
Douglas Gregor43959a92009-08-20 07:17:43 +00005499template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005500StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005501TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005502 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005503}
Mike Stump1eb44332009-09-09 15:08:12 +00005504
Douglas Gregor43959a92009-08-20 07:17:43 +00005505template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005506StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005507TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005508 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005509 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005510 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005511
Mike Stump1eb44332009-09-09 15:08:12 +00005512 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005513 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005514 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005515}
Mike Stump1eb44332009-09-09 15:08:12 +00005516
Douglas Gregor43959a92009-08-20 07:17:43 +00005517template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005518StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005519TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005520 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005521 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005522 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5523 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005524 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5525 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005526 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005527 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005528
Douglas Gregor43959a92009-08-20 07:17:43 +00005529 if (Transformed != *D)
5530 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005531
Douglas Gregor43959a92009-08-20 07:17:43 +00005532 Decls.push_back(Transformed);
5533 }
Mike Stump1eb44332009-09-09 15:08:12 +00005534
Douglas Gregor43959a92009-08-20 07:17:43 +00005535 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005536 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005537
5538 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005539 S->getStartLoc(), S->getEndLoc());
5540}
Mike Stump1eb44332009-09-09 15:08:12 +00005541
Douglas Gregor43959a92009-08-20 07:17:43 +00005542template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005543StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005544TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005545
John McCallca0408f2010-08-23 06:44:23 +00005546 ASTOwningVector<Expr*> Constraints(getSema());
5547 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005548 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005549
John McCall60d7b3a2010-08-24 06:29:42 +00005550 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005551 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005552
5553 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005554
Anders Carlsson703e3942010-01-24 05:50:09 +00005555 // Go through the outputs.
5556 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005557 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005558
Anders Carlsson703e3942010-01-24 05:50:09 +00005559 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005560 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005561
Anders Carlsson703e3942010-01-24 05:50:09 +00005562 // Transform the output expr.
5563 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005564 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005565 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005566 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005567
Anders Carlsson703e3942010-01-24 05:50:09 +00005568 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005569
John McCall9ae2f072010-08-23 23:25:46 +00005570 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005571 }
Sean Huntc3021132010-05-05 15:23:54 +00005572
Anders Carlsson703e3942010-01-24 05:50:09 +00005573 // Go through the inputs.
5574 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005575 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005576
Anders Carlsson703e3942010-01-24 05:50:09 +00005577 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005578 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005579
Anders Carlsson703e3942010-01-24 05:50:09 +00005580 // Transform the input expr.
5581 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005582 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005583 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005584 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005585
Anders Carlsson703e3942010-01-24 05:50:09 +00005586 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005587
John McCall9ae2f072010-08-23 23:25:46 +00005588 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005589 }
Sean Huntc3021132010-05-05 15:23:54 +00005590
Anders Carlsson703e3942010-01-24 05:50:09 +00005591 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005592 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005593
5594 // Go through the clobbers.
5595 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005596 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005597
5598 // No need to transform the asm string literal.
5599 AsmString = SemaRef.Owned(S->getAsmString());
5600
5601 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5602 S->isSimple(),
5603 S->isVolatile(),
5604 S->getNumOutputs(),
5605 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005606 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005607 move_arg(Constraints),
5608 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005609 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005610 move_arg(Clobbers),
5611 S->getRParenLoc(),
5612 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005613}
5614
Chad Rosier8cd64b42012-06-11 20:47:18 +00005615template<typename Derived>
5616StmtResult
5617TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
5618 // No need to transform the asm string literal.
5619 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(),
5620 *S->getAsmString(),
5621 S->getEndLoc());
5622}
Douglas Gregor43959a92009-08-20 07:17:43 +00005623
5624template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005625StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005626TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005627 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005628 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005629 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005630 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005631
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005632 // Transform the @catch statements (if present).
5633 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005634 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005635 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005636 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005637 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005638 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005639 if (Catch.get() != S->getCatchStmt(I))
5640 AnyCatchChanged = true;
5641 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005642 }
Sean Huntc3021132010-05-05 15:23:54 +00005643
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005644 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005645 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005646 if (S->getFinallyStmt()) {
5647 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5648 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005649 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005650 }
5651
5652 // If nothing changed, just retain this statement.
5653 if (!getDerived().AlwaysRebuild() &&
5654 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005655 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005656 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005657 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005658
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005659 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005660 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5661 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005662}
Mike Stump1eb44332009-09-09 15:08:12 +00005663
Douglas Gregor43959a92009-08-20 07:17:43 +00005664template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005665StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005666TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005667 // Transform the @catch parameter, if there is one.
5668 VarDecl *Var = 0;
5669 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5670 TypeSourceInfo *TSInfo = 0;
5671 if (FromVar->getTypeSourceInfo()) {
5672 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5673 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005674 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005675 }
Sean Huntc3021132010-05-05 15:23:54 +00005676
Douglas Gregorbe270a02010-04-26 17:57:08 +00005677 QualType T;
5678 if (TSInfo)
5679 T = TSInfo->getType();
5680 else {
5681 T = getDerived().TransformType(FromVar->getType());
5682 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005683 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005684 }
Sean Huntc3021132010-05-05 15:23:54 +00005685
Douglas Gregorbe270a02010-04-26 17:57:08 +00005686 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5687 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005688 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005689 }
Sean Huntc3021132010-05-05 15:23:54 +00005690
John McCall60d7b3a2010-08-24 06:29:42 +00005691 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005692 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005693 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005694
5695 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005696 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005697 Var, 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>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005703 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005704 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005705 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005706 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005707
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005708 // If nothing changed, just retain this statement.
5709 if (!getDerived().AlwaysRebuild() &&
5710 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005711 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005712
5713 // Build a new statement.
5714 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005715 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005716}
Mike Stump1eb44332009-09-09 15:08:12 +00005717
Douglas Gregor43959a92009-08-20 07:17:43 +00005718template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005719StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005720TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005721 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005722 if (S->getThrowExpr()) {
5723 Operand = getDerived().TransformExpr(S->getThrowExpr());
5724 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005725 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005726 }
Sean Huntc3021132010-05-05 15:23:54 +00005727
Douglas Gregord1377b22010-04-22 21:44:01 +00005728 if (!getDerived().AlwaysRebuild() &&
5729 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005730 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005731
John McCall9ae2f072010-08-23 23:25:46 +00005732 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005733}
Mike Stump1eb44332009-09-09 15:08:12 +00005734
Douglas Gregor43959a92009-08-20 07:17:43 +00005735template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005736StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005737TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005738 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005739 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005740 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005741 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005742 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005743 Object =
5744 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5745 Object.get());
5746 if (Object.isInvalid())
5747 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005748
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005749 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005750 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005751 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005752 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005753
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005754 // If nothing change, just retain the current statement.
5755 if (!getDerived().AlwaysRebuild() &&
5756 Object.get() == S->getSynchExpr() &&
5757 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005758 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005759
5760 // Build a new statement.
5761 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005762 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005763}
5764
5765template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005766StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005767TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5768 ObjCAutoreleasePoolStmt *S) {
5769 // Transform the body.
5770 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5771 if (Body.isInvalid())
5772 return StmtError();
5773
5774 // If nothing changed, just retain this statement.
5775 if (!getDerived().AlwaysRebuild() &&
5776 Body.get() == S->getSubStmt())
5777 return SemaRef.Owned(S);
5778
5779 // Build a new statement.
5780 return getDerived().RebuildObjCAutoreleasePoolStmt(
5781 S->getAtLoc(), Body.get());
5782}
5783
5784template<typename Derived>
5785StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005786TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005787 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005788 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005789 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005790 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005791 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005792
Douglas Gregorc3203e72010-04-22 23:10:45 +00005793 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005794 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005795 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005796 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005797 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5798 Collection.take());
5799 if (Collection.isInvalid())
5800 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005801
Douglas Gregorc3203e72010-04-22 23:10:45 +00005802 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005803 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005804 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005805 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005806
Douglas Gregorc3203e72010-04-22 23:10:45 +00005807 // If nothing changed, just retain this statement.
5808 if (!getDerived().AlwaysRebuild() &&
5809 Element.get() == S->getElement() &&
5810 Collection.get() == S->getCollection() &&
5811 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005812 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005813
Douglas Gregorc3203e72010-04-22 23:10:45 +00005814 // Build a new statement.
5815 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5816 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005817 Element.get(),
5818 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005819 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005820 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005821}
5822
5823
5824template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005825StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005826TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5827 // Transform the exception declaration, if any.
5828 VarDecl *Var = 0;
5829 if (S->getExceptionDecl()) {
5830 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005831 TypeSourceInfo *T = getDerived().TransformType(
5832 ExceptionDecl->getTypeSourceInfo());
5833 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005834 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005835
Douglas Gregor83cb9422010-09-09 17:09:21 +00005836 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005837 ExceptionDecl->getInnerLocStart(),
5838 ExceptionDecl->getLocation(),
5839 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005840 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005841 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005842 }
Mike Stump1eb44332009-09-09 15:08:12 +00005843
Douglas Gregor43959a92009-08-20 07:17:43 +00005844 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005845 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005846 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005847 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005848
Douglas Gregor43959a92009-08-20 07:17:43 +00005849 if (!getDerived().AlwaysRebuild() &&
5850 !Var &&
5851 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005852 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005853
5854 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5855 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005856 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005857}
Mike Stump1eb44332009-09-09 15:08:12 +00005858
Douglas Gregor43959a92009-08-20 07:17:43 +00005859template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005860StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005861TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5862 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005863 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005864 = getDerived().TransformCompoundStmt(S->getTryBlock());
5865 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005866 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005867
Douglas Gregor43959a92009-08-20 07:17:43 +00005868 // Transform the handlers.
5869 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005870 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005871 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005872 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005873 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5874 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005875 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005876
Douglas Gregor43959a92009-08-20 07:17:43 +00005877 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5878 Handlers.push_back(Handler.takeAs<Stmt>());
5879 }
Mike Stump1eb44332009-09-09 15:08:12 +00005880
Douglas Gregor43959a92009-08-20 07:17:43 +00005881 if (!getDerived().AlwaysRebuild() &&
5882 TryBlock.get() == S->getTryBlock() &&
5883 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005884 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005885
John McCall9ae2f072010-08-23 23:25:46 +00005886 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005887 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005888}
Mike Stump1eb44332009-09-09 15:08:12 +00005889
Richard Smithad762fc2011-04-14 22:09:26 +00005890template<typename Derived>
5891StmtResult
5892TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5893 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5894 if (Range.isInvalid())
5895 return StmtError();
5896
5897 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5898 if (BeginEnd.isInvalid())
5899 return StmtError();
5900
5901 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5902 if (Cond.isInvalid())
5903 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005904 if (Cond.get())
5905 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5906 if (Cond.isInvalid())
5907 return StmtError();
5908 if (Cond.get())
5909 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005910
5911 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5912 if (Inc.isInvalid())
5913 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005914 if (Inc.get())
5915 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005916
5917 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5918 if (LoopVar.isInvalid())
5919 return StmtError();
5920
5921 StmtResult NewStmt = S;
5922 if (getDerived().AlwaysRebuild() ||
5923 Range.get() != S->getRangeStmt() ||
5924 BeginEnd.get() != S->getBeginEndStmt() ||
5925 Cond.get() != S->getCond() ||
5926 Inc.get() != S->getInc() ||
5927 LoopVar.get() != S->getLoopVarStmt())
5928 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5929 S->getColonLoc(), Range.get(),
5930 BeginEnd.get(), Cond.get(),
5931 Inc.get(), LoopVar.get(),
5932 S->getRParenLoc());
5933
5934 StmtResult Body = getDerived().TransformStmt(S->getBody());
5935 if (Body.isInvalid())
5936 return StmtError();
5937
5938 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5939 // it now so we have a new statement to attach the body to.
5940 if (Body.get() != S->getBody() && NewStmt.get() == S)
5941 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5942 S->getColonLoc(), Range.get(),
5943 BeginEnd.get(), Cond.get(),
5944 Inc.get(), LoopVar.get(),
5945 S->getRParenLoc());
5946
5947 if (NewStmt.get() == S)
5948 return SemaRef.Owned(S);
5949
5950 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5951}
5952
John Wiegley28bbe4b2011-04-28 01:08:34 +00005953template<typename Derived>
5954StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005955TreeTransform<Derived>::TransformMSDependentExistsStmt(
5956 MSDependentExistsStmt *S) {
5957 // Transform the nested-name-specifier, if any.
5958 NestedNameSpecifierLoc QualifierLoc;
5959 if (S->getQualifierLoc()) {
5960 QualifierLoc
5961 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5962 if (!QualifierLoc)
5963 return StmtError();
5964 }
5965
5966 // Transform the declaration name.
5967 DeclarationNameInfo NameInfo = S->getNameInfo();
5968 if (NameInfo.getName()) {
5969 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5970 if (!NameInfo.getName())
5971 return StmtError();
5972 }
5973
5974 // Check whether anything changed.
5975 if (!getDerived().AlwaysRebuild() &&
5976 QualifierLoc == S->getQualifierLoc() &&
5977 NameInfo.getName() == S->getNameInfo().getName())
5978 return S;
5979
5980 // Determine whether this name exists, if we can.
5981 CXXScopeSpec SS;
5982 SS.Adopt(QualifierLoc);
5983 bool Dependent = false;
5984 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5985 case Sema::IER_Exists:
5986 if (S->isIfExists())
5987 break;
5988
5989 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5990
5991 case Sema::IER_DoesNotExist:
5992 if (S->isIfNotExists())
5993 break;
5994
5995 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5996
5997 case Sema::IER_Dependent:
5998 Dependent = true;
5999 break;
Douglas Gregor65019ac2011-10-25 03:44:56 +00006000
6001 case Sema::IER_Error:
6002 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006003 }
6004
6005 // We need to continue with the instantiation, so do so now.
6006 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6007 if (SubStmt.isInvalid())
6008 return StmtError();
6009
6010 // If we have resolved the name, just transform to the substatement.
6011 if (!Dependent)
6012 return SubStmt;
6013
6014 // The name is still dependent, so build a dependent expression again.
6015 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6016 S->isIfExists(),
6017 QualifierLoc,
6018 NameInfo,
6019 SubStmt.get());
6020}
6021
6022template<typename Derived>
6023StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006024TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6025 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6026 if(TryBlock.isInvalid()) return StmtError();
6027
6028 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6029 if(!getDerived().AlwaysRebuild() &&
6030 TryBlock.get() == S->getTryBlock() &&
6031 Handler.get() == S->getHandler())
6032 return SemaRef.Owned(S);
6033
6034 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6035 S->getTryLoc(),
6036 TryBlock.take(),
6037 Handler.take());
6038}
6039
6040template<typename Derived>
6041StmtResult
6042TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6043 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6044 if(Block.isInvalid()) return StmtError();
6045
6046 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6047 Block.take());
6048}
6049
6050template<typename Derived>
6051StmtResult
6052TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6053 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6054 if(FilterExpr.isInvalid()) return StmtError();
6055
6056 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6057 if(Block.isInvalid()) return StmtError();
6058
6059 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6060 FilterExpr.take(),
6061 Block.take());
6062}
6063
6064template<typename Derived>
6065StmtResult
6066TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6067 if(isa<SEHFinallyStmt>(Handler))
6068 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6069 else
6070 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6071}
6072
Douglas Gregor43959a92009-08-20 07:17:43 +00006073//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006074// Expression transformation
6075//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006076template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006077ExprResult
John McCall454feb92009-12-08 09:21:05 +00006078TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006079 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006080}
Mike Stump1eb44332009-09-09 15:08:12 +00006081
6082template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006083ExprResult
John McCall454feb92009-12-08 09:21:05 +00006084TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006085 NestedNameSpecifierLoc QualifierLoc;
6086 if (E->getQualifierLoc()) {
6087 QualifierLoc
6088 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6089 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006090 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006091 }
John McCalldbd872f2009-12-08 09:08:17 +00006092
6093 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006094 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6095 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006096 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006097 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006098
John McCallec8045d2010-08-17 21:27:17 +00006099 DeclarationNameInfo NameInfo = E->getNameInfo();
6100 if (NameInfo.getName()) {
6101 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6102 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006103 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006104 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006105
6106 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006107 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006108 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006109 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006110 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006111
6112 // Mark it referenced in the new context regardless.
6113 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006114 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006115
John McCall3fa5cae2010-10-26 07:05:15 +00006116 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006117 }
John McCalldbd872f2009-12-08 09:08:17 +00006118
6119 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006120 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006121 TemplateArgs = &TransArgs;
6122 TransArgs.setLAngleLoc(E->getLAngleLoc());
6123 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006124 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6125 E->getNumTemplateArgs(),
6126 TransArgs))
6127 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006128 }
6129
Douglas Gregor40d96a62011-02-28 21:54:11 +00006130 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
6131 TemplateArgs);
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>::TransformIntegerLiteral(IntegerLiteral *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>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006143 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006144}
Mike Stump1eb44332009-09-09 15:08:12 +00006145
Douglas Gregorb98b1992009-08-11 05:31:07 +00006146template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006147ExprResult
John McCall454feb92009-12-08 09:21:05 +00006148TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006149 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006150}
Mike Stump1eb44332009-09-09 15:08:12 +00006151
Douglas Gregorb98b1992009-08-11 05:31:07 +00006152template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006153ExprResult
John McCall454feb92009-12-08 09:21:05 +00006154TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006155 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006156}
Mike Stump1eb44332009-09-09 15:08:12 +00006157
Douglas Gregorb98b1992009-08-11 05:31:07 +00006158template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006159ExprResult
John McCall454feb92009-12-08 09:21:05 +00006160TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006161 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006162}
6163
6164template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006165ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006166TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6167 return SemaRef.MaybeBindToTemporary(E);
6168}
6169
6170template<typename Derived>
6171ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006172TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6173 ExprResult ControllingExpr =
6174 getDerived().TransformExpr(E->getControllingExpr());
6175 if (ControllingExpr.isInvalid())
6176 return ExprError();
6177
Chris Lattner686775d2011-07-20 06:58:45 +00006178 SmallVector<Expr *, 4> AssocExprs;
6179 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006180 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6181 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6182 if (TS) {
6183 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6184 if (!AssocType)
6185 return ExprError();
6186 AssocTypes.push_back(AssocType);
6187 } else {
6188 AssocTypes.push_back(0);
6189 }
6190
6191 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6192 if (AssocExpr.isInvalid())
6193 return ExprError();
6194 AssocExprs.push_back(AssocExpr.release());
6195 }
6196
6197 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6198 E->getDefaultLoc(),
6199 E->getRParenLoc(),
6200 ControllingExpr.release(),
6201 AssocTypes.data(),
6202 AssocExprs.data(),
6203 E->getNumAssocs());
6204}
6205
6206template<typename Derived>
6207ExprResult
John McCall454feb92009-12-08 09:21:05 +00006208TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006209 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006210 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006211 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006212
Douglas Gregorb98b1992009-08-11 05:31:07 +00006213 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006214 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006215
John McCall9ae2f072010-08-23 23:25:46 +00006216 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006217 E->getRParen());
6218}
6219
Mike Stump1eb44332009-09-09 15:08:12 +00006220template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006221ExprResult
John McCall454feb92009-12-08 09:21:05 +00006222TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006223 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006224 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006225 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006226
Douglas Gregorb98b1992009-08-11 05:31:07 +00006227 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006228 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006229
Douglas Gregorb98b1992009-08-11 05:31:07 +00006230 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6231 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006232 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006233}
Mike Stump1eb44332009-09-09 15:08:12 +00006234
Douglas Gregorb98b1992009-08-11 05:31:07 +00006235template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006236ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006237TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6238 // Transform the type.
6239 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6240 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006241 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006242
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006243 // Transform all of the components into components similar to what the
6244 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00006245 // FIXME: It would be slightly more efficient in the non-dependent case to
6246 // just map FieldDecls, rather than requiring the rebuilder to look for
6247 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006248 // template code that we don't care.
6249 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006250 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006251 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006252 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006253 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6254 const Node &ON = E->getComponent(I);
6255 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006256 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006257 Comp.LocStart = ON.getSourceRange().getBegin();
6258 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006259 switch (ON.getKind()) {
6260 case Node::Array: {
6261 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006262 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006263 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006264 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006265
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006266 ExprChanged = ExprChanged || Index.get() != FromIndex;
6267 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006268 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006269 break;
6270 }
Sean Huntc3021132010-05-05 15:23:54 +00006271
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006272 case Node::Field:
6273 case Node::Identifier:
6274 Comp.isBrackets = false;
6275 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006276 if (!Comp.U.IdentInfo)
6277 continue;
Sean Huntc3021132010-05-05 15:23:54 +00006278
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006279 break;
Sean Huntc3021132010-05-05 15:23:54 +00006280
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006281 case Node::Base:
6282 // Will be recomputed during the rebuild.
6283 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006284 }
Sean Huntc3021132010-05-05 15:23:54 +00006285
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006286 Components.push_back(Comp);
6287 }
Sean Huntc3021132010-05-05 15:23:54 +00006288
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006289 // If nothing changed, retain the existing expression.
6290 if (!getDerived().AlwaysRebuild() &&
6291 Type == E->getTypeSourceInfo() &&
6292 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006293 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006294
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006295 // Build a new offsetof expression.
6296 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6297 Components.data(), Components.size(),
6298 E->getRParenLoc());
6299}
6300
6301template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006302ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006303TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6304 assert(getDerived().AlreadyTransformed(E->getType()) &&
6305 "opaque value expression requires transformation");
6306 return SemaRef.Owned(E);
6307}
6308
6309template<typename Derived>
6310ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006311TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006312 // Rebuild the syntactic form. The original syntactic form has
6313 // opaque-value expressions in it, so strip those away and rebuild
6314 // the result. This is a really awful way of doing this, but the
6315 // better solution (rebuilding the semantic expressions and
6316 // rebinding OVEs as necessary) doesn't work; we'd need
6317 // TreeTransform to not strip away implicit conversions.
6318 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6319 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006320 if (result.isInvalid()) return ExprError();
6321
6322 // If that gives us a pseudo-object result back, the pseudo-object
6323 // expression must have been an lvalue-to-rvalue conversion which we
6324 // should reapply.
6325 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6326 result = SemaRef.checkPseudoObjectRValue(result.take());
6327
6328 return result;
6329}
6330
6331template<typename Derived>
6332ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006333TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6334 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006335 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006336 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006337
John McCalla93c9342009-12-07 02:54:59 +00006338 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006339 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006340 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006341
John McCall5ab75172009-11-04 07:28:41 +00006342 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006343 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006344
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006345 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6346 E->getKind(),
6347 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006348 }
Mike Stump1eb44332009-09-09 15:08:12 +00006349
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006350 // C++0x [expr.sizeof]p1:
6351 // The operand is either an expression, which is an unevaluated operand
6352 // [...]
6353 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006354
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006355 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6356 if (SubExpr.isInvalid())
6357 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006358
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006359 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6360 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006361
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006362 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6363 E->getOperatorLoc(),
6364 E->getKind(),
6365 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006366}
Mike Stump1eb44332009-09-09 15:08:12 +00006367
Douglas Gregorb98b1992009-08-11 05:31:07 +00006368template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006369ExprResult
John McCall454feb92009-12-08 09:21:05 +00006370TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006371 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006372 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006373 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006374
John McCall60d7b3a2010-08-24 06:29:42 +00006375 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006376 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006377 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006378
6379
Douglas Gregorb98b1992009-08-11 05:31:07 +00006380 if (!getDerived().AlwaysRebuild() &&
6381 LHS.get() == E->getLHS() &&
6382 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006383 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006384
John McCall9ae2f072010-08-23 23:25:46 +00006385 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006386 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006387 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006388 E->getRBracketLoc());
6389}
Mike Stump1eb44332009-09-09 15:08:12 +00006390
6391template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006392ExprResult
John McCall454feb92009-12-08 09:21:05 +00006393TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006394 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006395 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006396 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006397 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006398
6399 // Transform arguments.
6400 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006401 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006402 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6403 &ArgChanged))
6404 return ExprError();
6405
Douglas Gregorb98b1992009-08-11 05:31:07 +00006406 if (!getDerived().AlwaysRebuild() &&
6407 Callee.get() == E->getCallee() &&
6408 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006409 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006410
Douglas Gregorb98b1992009-08-11 05:31:07 +00006411 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006412 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006413 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006414 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006415 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006416 E->getRParenLoc());
6417}
Mike Stump1eb44332009-09-09 15:08:12 +00006418
6419template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006420ExprResult
John McCall454feb92009-12-08 09:21:05 +00006421TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006422 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006423 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006424 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006425
Douglas Gregor40d96a62011-02-28 21:54:11 +00006426 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006427 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006428 QualifierLoc
6429 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6430
6431 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006432 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006433 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006434 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006435
Eli Friedmanf595cc42009-12-04 06:40:45 +00006436 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006437 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6438 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006439 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006440 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006441
John McCall6bb80172010-03-30 21:47:33 +00006442 NamedDecl *FoundDecl = E->getFoundDecl();
6443 if (FoundDecl == E->getMemberDecl()) {
6444 FoundDecl = Member;
6445 } else {
6446 FoundDecl = cast_or_null<NamedDecl>(
6447 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6448 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006449 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006450 }
6451
Douglas Gregorb98b1992009-08-11 05:31:07 +00006452 if (!getDerived().AlwaysRebuild() &&
6453 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006454 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006455 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006456 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006457 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006458
Anders Carlsson1f240322009-12-22 05:24:09 +00006459 // Mark it referenced in the new context regardless.
6460 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006461 SemaRef.MarkMemberReferenced(E);
6462
John McCall3fa5cae2010-10-26 07:05:15 +00006463 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006464 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006465
John McCalld5532b62009-11-23 01:53:49 +00006466 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006467 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006468 TransArgs.setLAngleLoc(E->getLAngleLoc());
6469 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006470 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6471 E->getNumTemplateArgs(),
6472 TransArgs))
6473 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006474 }
Sean Huntc3021132010-05-05 15:23:54 +00006475
Douglas Gregorb98b1992009-08-11 05:31:07 +00006476 // FIXME: Bogus source location for the operator
6477 SourceLocation FakeOperatorLoc
6478 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6479
John McCallc2233c52010-01-15 08:34:02 +00006480 // FIXME: to do this check properly, we will need to preserve the
6481 // first-qualifier-in-scope here, just in case we had a dependent
6482 // base (and therefore couldn't do the check) and a
6483 // nested-name-qualifier (and therefore could do the lookup).
6484 NamedDecl *FirstQualifierInScope = 0;
6485
John McCall9ae2f072010-08-23 23:25:46 +00006486 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006487 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006488 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006489 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006490 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006491 Member,
John McCall6bb80172010-03-30 21:47:33 +00006492 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006493 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006494 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006495 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006496}
Mike Stump1eb44332009-09-09 15:08:12 +00006497
Douglas Gregorb98b1992009-08-11 05:31:07 +00006498template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006499ExprResult
John McCall454feb92009-12-08 09:21:05 +00006500TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006501 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006502 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006503 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006504
John McCall60d7b3a2010-08-24 06:29:42 +00006505 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006506 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006507 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006508
Douglas Gregorb98b1992009-08-11 05:31:07 +00006509 if (!getDerived().AlwaysRebuild() &&
6510 LHS.get() == E->getLHS() &&
6511 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006512 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006513
Douglas Gregorb98b1992009-08-11 05:31:07 +00006514 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006515 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006516}
6517
Mike Stump1eb44332009-09-09 15:08:12 +00006518template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006519ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006520TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006521 CompoundAssignOperator *E) {
6522 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006523}
Mike Stump1eb44332009-09-09 15:08:12 +00006524
Douglas Gregorb98b1992009-08-11 05:31:07 +00006525template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006526ExprResult TreeTransform<Derived>::
6527TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6528 // Just rebuild the common and RHS expressions and see whether we
6529 // get any changes.
6530
6531 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6532 if (commonExpr.isInvalid())
6533 return ExprError();
6534
6535 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6536 if (rhs.isInvalid())
6537 return ExprError();
6538
6539 if (!getDerived().AlwaysRebuild() &&
6540 commonExpr.get() == e->getCommon() &&
6541 rhs.get() == e->getFalseExpr())
6542 return SemaRef.Owned(e);
6543
6544 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6545 e->getQuestionLoc(),
6546 0,
6547 e->getColonLoc(),
6548 rhs.get());
6549}
6550
6551template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006552ExprResult
John McCall454feb92009-12-08 09:21:05 +00006553TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006554 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006555 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006556 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006557
John McCall60d7b3a2010-08-24 06:29:42 +00006558 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006559 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006560 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006561
John McCall60d7b3a2010-08-24 06:29:42 +00006562 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006563 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006564 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006565
Douglas Gregorb98b1992009-08-11 05:31:07 +00006566 if (!getDerived().AlwaysRebuild() &&
6567 Cond.get() == E->getCond() &&
6568 LHS.get() == E->getLHS() &&
6569 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006570 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006571
John McCall9ae2f072010-08-23 23:25:46 +00006572 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006573 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006574 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006575 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006576 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006577}
Mike Stump1eb44332009-09-09 15:08:12 +00006578
6579template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006580ExprResult
John McCall454feb92009-12-08 09:21:05 +00006581TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006582 // Implicit casts are eliminated during transformation, since they
6583 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006584 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006585}
Mike Stump1eb44332009-09-09 15:08:12 +00006586
Douglas Gregorb98b1992009-08-11 05:31:07 +00006587template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006588ExprResult
John McCall454feb92009-12-08 09:21:05 +00006589TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006590 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6591 if (!Type)
6592 return ExprError();
6593
John McCall60d7b3a2010-08-24 06:29:42 +00006594 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006595 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006596 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006597 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006598
Douglas Gregorb98b1992009-08-11 05:31:07 +00006599 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006600 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006601 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006602 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006603
John McCall9d125032010-01-15 18:39:57 +00006604 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006605 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006606 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006607 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006608}
Mike Stump1eb44332009-09-09 15:08:12 +00006609
Douglas Gregorb98b1992009-08-11 05:31:07 +00006610template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006611ExprResult
John McCall454feb92009-12-08 09:21:05 +00006612TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006613 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6614 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6615 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006616 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006617
John McCall60d7b3a2010-08-24 06:29:42 +00006618 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006619 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006620 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006621
Douglas Gregorb98b1992009-08-11 05:31:07 +00006622 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006623 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006624 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006625 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006626
John McCall1d7d8d62010-01-19 22:33:45 +00006627 // Note: the expression type doesn't necessarily match the
6628 // type-as-written, but that's okay, because it should always be
6629 // derivable from the initializer.
6630
John McCall42f56b52010-01-18 19:35:47 +00006631 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006632 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006633 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006634}
Mike Stump1eb44332009-09-09 15:08:12 +00006635
Douglas Gregorb98b1992009-08-11 05:31:07 +00006636template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006637ExprResult
John McCall454feb92009-12-08 09:21:05 +00006638TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006639 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006641 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006642
Douglas Gregorb98b1992009-08-11 05:31:07 +00006643 if (!getDerived().AlwaysRebuild() &&
6644 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006645 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006646
Douglas Gregorb98b1992009-08-11 05:31:07 +00006647 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006648 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006649 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006650 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006651 E->getAccessorLoc(),
6652 E->getAccessor());
6653}
Mike Stump1eb44332009-09-09 15:08:12 +00006654
Douglas Gregorb98b1992009-08-11 05:31:07 +00006655template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006656ExprResult
John McCall454feb92009-12-08 09:21:05 +00006657TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006658 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006659
John McCallca0408f2010-08-23 06:44:23 +00006660 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006661 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6662 Inits, &InitChanged))
6663 return ExprError();
6664
Douglas Gregorb98b1992009-08-11 05:31:07 +00006665 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006666 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006667
Douglas Gregorb98b1992009-08-11 05:31:07 +00006668 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006669 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006670}
Mike Stump1eb44332009-09-09 15:08:12 +00006671
Douglas Gregorb98b1992009-08-11 05:31:07 +00006672template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006673ExprResult
John McCall454feb92009-12-08 09:21:05 +00006674TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006675 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006676
Douglas Gregor43959a92009-08-20 07:17:43 +00006677 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006678 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006679 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006680 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006681
Douglas Gregor43959a92009-08-20 07:17:43 +00006682 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006683 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006684 bool ExprChanged = false;
6685 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6686 DEnd = E->designators_end();
6687 D != DEnd; ++D) {
6688 if (D->isFieldDesignator()) {
6689 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6690 D->getDotLoc(),
6691 D->getFieldLoc()));
6692 continue;
6693 }
Mike Stump1eb44332009-09-09 15:08:12 +00006694
Douglas Gregorb98b1992009-08-11 05:31:07 +00006695 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006696 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006697 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006698 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006699
6700 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006701 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006702
Douglas Gregorb98b1992009-08-11 05:31:07 +00006703 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6704 ArrayExprs.push_back(Index.release());
6705 continue;
6706 }
Mike Stump1eb44332009-09-09 15:08:12 +00006707
Douglas Gregorb98b1992009-08-11 05:31:07 +00006708 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006709 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006710 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6711 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006712 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006713
John McCall60d7b3a2010-08-24 06:29:42 +00006714 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006715 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006716 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006717
6718 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006719 End.get(),
6720 D->getLBracketLoc(),
6721 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006722
Douglas Gregorb98b1992009-08-11 05:31:07 +00006723 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6724 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006725
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726 ArrayExprs.push_back(Start.release());
6727 ArrayExprs.push_back(End.release());
6728 }
Mike Stump1eb44332009-09-09 15:08:12 +00006729
Douglas Gregorb98b1992009-08-11 05:31:07 +00006730 if (!getDerived().AlwaysRebuild() &&
6731 Init.get() == E->getInit() &&
6732 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006733 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006734
Douglas Gregorb98b1992009-08-11 05:31:07 +00006735 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6736 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006737 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006738}
Mike Stump1eb44332009-09-09 15:08:12 +00006739
Douglas Gregorb98b1992009-08-11 05:31:07 +00006740template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006741ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006742TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006743 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006744 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006745
Douglas Gregor5557b252009-10-28 00:29:27 +00006746 // FIXME: Will we ever have proper type location here? Will we actually
6747 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006748 QualType T = getDerived().TransformType(E->getType());
6749 if (T.isNull())
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() &&
6753 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006754 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006755
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756 return getDerived().RebuildImplicitValueInitExpr(T);
6757}
Mike Stump1eb44332009-09-09 15:08:12 +00006758
Douglas Gregorb98b1992009-08-11 05:31:07 +00006759template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006760ExprResult
John McCall454feb92009-12-08 09:21:05 +00006761TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006762 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6763 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006764 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006765
John McCall60d7b3a2010-08-24 06:29:42 +00006766 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006767 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006768 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006769
Douglas Gregorb98b1992009-08-11 05:31:07 +00006770 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006771 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006772 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006773 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006774
John McCall9ae2f072010-08-23 23:25:46 +00006775 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006776 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006777}
6778
6779template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006780ExprResult
John McCall454feb92009-12-08 09:21:05 +00006781TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006782 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006783 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006784 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6785 &ArgumentChanged))
6786 return ExprError();
6787
Douglas Gregorb98b1992009-08-11 05:31:07 +00006788 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6789 move_arg(Inits),
6790 E->getRParenLoc());
6791}
Mike Stump1eb44332009-09-09 15:08:12 +00006792
Douglas Gregorb98b1992009-08-11 05:31:07 +00006793/// \brief Transform an address-of-label expression.
6794///
6795/// By default, the transformation of an address-of-label expression always
6796/// rebuilds the expression, so that the label identifier can be resolved to
6797/// the corresponding label statement by semantic analysis.
6798template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006799ExprResult
John McCall454feb92009-12-08 09:21:05 +00006800TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006801 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6802 E->getLabel());
6803 if (!LD)
6804 return ExprError();
6805
Douglas Gregorb98b1992009-08-11 05:31:07 +00006806 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006807 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006808}
Mike Stump1eb44332009-09-09 15:08:12 +00006809
6810template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006811ExprResult
John McCall454feb92009-12-08 09:21:05 +00006812TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006813 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006814 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006815 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006816 if (SubStmt.isInvalid()) {
6817 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006818 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006819 }
Mike Stump1eb44332009-09-09 15:08:12 +00006820
Douglas Gregorb98b1992009-08-11 05:31:07 +00006821 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006822 SubStmt.get() == E->getSubStmt()) {
6823 // Calling this an 'error' is unintuitive, but it does the right thing.
6824 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006825 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006826 }
Mike Stump1eb44332009-09-09 15:08:12 +00006827
6828 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006829 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006830 E->getRParenLoc());
6831}
Mike Stump1eb44332009-09-09 15:08:12 +00006832
Douglas Gregorb98b1992009-08-11 05:31:07 +00006833template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006834ExprResult
John McCall454feb92009-12-08 09:21:05 +00006835TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006836 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006837 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006838 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006839
John McCall60d7b3a2010-08-24 06:29:42 +00006840 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006841 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006842 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006843
John McCall60d7b3a2010-08-24 06:29:42 +00006844 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006845 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006846 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006847
Douglas Gregorb98b1992009-08-11 05:31:07 +00006848 if (!getDerived().AlwaysRebuild() &&
6849 Cond.get() == E->getCond() &&
6850 LHS.get() == E->getLHS() &&
6851 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006852 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006853
Douglas Gregorb98b1992009-08-11 05:31:07 +00006854 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006855 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006856 E->getRParenLoc());
6857}
Mike Stump1eb44332009-09-09 15:08:12 +00006858
Douglas Gregorb98b1992009-08-11 05:31:07 +00006859template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006860ExprResult
John McCall454feb92009-12-08 09:21:05 +00006861TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006862 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006863}
6864
6865template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006866ExprResult
John McCall454feb92009-12-08 09:21:05 +00006867TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006868 switch (E->getOperator()) {
6869 case OO_New:
6870 case OO_Delete:
6871 case OO_Array_New:
6872 case OO_Array_Delete:
6873 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Sean Huntc3021132010-05-05 15:23:54 +00006874
Douglas Gregor668d6d92009-12-13 20:44:55 +00006875 case OO_Call: {
6876 // This is a call to an object's operator().
6877 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6878
6879 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006880 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006881 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006882 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006883
6884 // FIXME: Poor location information
6885 SourceLocation FakeLParenLoc
6886 = SemaRef.PP.getLocForEndOfToken(
6887 static_cast<Expr *>(Object.get())->getLocEnd());
6888
6889 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006890 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006891 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6892 Args))
6893 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006894
John McCall9ae2f072010-08-23 23:25:46 +00006895 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006896 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006897 E->getLocEnd());
6898 }
6899
6900#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6901 case OO_##Name:
6902#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6903#include "clang/Basic/OperatorKinds.def"
6904 case OO_Subscript:
6905 // Handled below.
6906 break;
6907
6908 case OO_Conditional:
6909 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006910
6911 case OO_None:
6912 case NUM_OVERLOADED_OPERATORS:
6913 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006914 }
6915
John McCall60d7b3a2010-08-24 06:29:42 +00006916 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006917 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006918 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006919
John McCall60d7b3a2010-08-24 06:29:42 +00006920 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006921 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006922 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006923
John McCall60d7b3a2010-08-24 06:29:42 +00006924 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006925 if (E->getNumArgs() == 2) {
6926 Second = getDerived().TransformExpr(E->getArg(1));
6927 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006928 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006929 }
Mike Stump1eb44332009-09-09 15:08:12 +00006930
Douglas Gregorb98b1992009-08-11 05:31:07 +00006931 if (!getDerived().AlwaysRebuild() &&
6932 Callee.get() == E->getCallee() &&
6933 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006934 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006935 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006936
Douglas Gregorb98b1992009-08-11 05:31:07 +00006937 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6938 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006939 Callee.get(),
6940 First.get(),
6941 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006942}
Mike Stump1eb44332009-09-09 15:08:12 +00006943
Douglas Gregorb98b1992009-08-11 05:31:07 +00006944template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006945ExprResult
John McCall454feb92009-12-08 09:21:05 +00006946TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6947 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006948}
Mike Stump1eb44332009-09-09 15:08:12 +00006949
Douglas Gregorb98b1992009-08-11 05:31:07 +00006950template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006951ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006952TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6953 // Transform the callee.
6954 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6955 if (Callee.isInvalid())
6956 return ExprError();
6957
6958 // Transform exec config.
6959 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6960 if (EC.isInvalid())
6961 return ExprError();
6962
6963 // Transform arguments.
6964 bool ArgChanged = false;
6965 ASTOwningVector<Expr*> Args(SemaRef);
6966 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6967 &ArgChanged))
6968 return ExprError();
6969
6970 if (!getDerived().AlwaysRebuild() &&
6971 Callee.get() == E->getCallee() &&
6972 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006973 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006974
6975 // FIXME: Wrong source location information for the '('.
6976 SourceLocation FakeLParenLoc
6977 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6978 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6979 move_arg(Args),
6980 E->getRParenLoc(), EC.get());
6981}
6982
6983template<typename Derived>
6984ExprResult
John McCall454feb92009-12-08 09:21:05 +00006985TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006986 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6987 if (!Type)
6988 return ExprError();
6989
John McCall60d7b3a2010-08-24 06:29:42 +00006990 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006991 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006992 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006993 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006994
Douglas Gregorb98b1992009-08-11 05:31:07 +00006995 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006996 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006997 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006998 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006999
Douglas Gregorb98b1992009-08-11 05:31:07 +00007000 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00007001 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007002 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
7003 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
7004 SourceLocation FakeRParenLoc
7005 = SemaRef.PP.getLocForEndOfToken(
7006 E->getSubExpr()->getSourceRange().getEnd());
7007 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007008 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007009 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007010 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007011 FakeRAngleLoc,
7012 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007013 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007014 FakeRParenLoc);
7015}
Mike Stump1eb44332009-09-09 15:08:12 +00007016
Douglas Gregorb98b1992009-08-11 05:31:07 +00007017template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007018ExprResult
John McCall454feb92009-12-08 09:21:05 +00007019TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7020 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007021}
Mike Stump1eb44332009-09-09 15:08:12 +00007022
7023template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007024ExprResult
John McCall454feb92009-12-08 09:21:05 +00007025TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7026 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007027}
7028
Douglas Gregorb98b1992009-08-11 05:31:07 +00007029template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007030ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007032 CXXReinterpretCastExpr *E) {
7033 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007034}
Mike Stump1eb44332009-09-09 15:08:12 +00007035
Douglas Gregorb98b1992009-08-11 05:31:07 +00007036template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007037ExprResult
John McCall454feb92009-12-08 09:21:05 +00007038TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7039 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007040}
Mike Stump1eb44332009-09-09 15:08:12 +00007041
Douglas Gregorb98b1992009-08-11 05:31:07 +00007042template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007043ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007044TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007045 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007046 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7047 if (!Type)
7048 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007049
John McCall60d7b3a2010-08-24 06:29:42 +00007050 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007051 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007052 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007053 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007054
Douglas Gregorb98b1992009-08-11 05:31:07 +00007055 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007056 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007057 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007058 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007059
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007060 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007061 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007062 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007063 E->getRParenLoc());
7064}
Mike Stump1eb44332009-09-09 15:08:12 +00007065
Douglas Gregorb98b1992009-08-11 05:31:07 +00007066template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007067ExprResult
John McCall454feb92009-12-08 09:21:05 +00007068TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007069 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007070 TypeSourceInfo *TInfo
7071 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7072 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007073 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007074
Douglas Gregorb98b1992009-08-11 05:31:07 +00007075 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007076 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007077 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007078
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007079 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7080 E->getLocStart(),
7081 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007082 E->getLocEnd());
7083 }
Mike Stump1eb44332009-09-09 15:08:12 +00007084
Eli Friedmanef331b72012-01-20 01:26:23 +00007085 // We don't know whether the subexpression is potentially evaluated until
7086 // after we perform semantic analysis. We speculatively assume it is
7087 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007088 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00007089 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00007090
John McCall60d7b3a2010-08-24 06:29:42 +00007091 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007092 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007093 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007094
Douglas Gregorb98b1992009-08-11 05:31:07 +00007095 if (!getDerived().AlwaysRebuild() &&
7096 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007097 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007098
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007099 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7100 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007101 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007102 E->getLocEnd());
7103}
7104
7105template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007106ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007107TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7108 if (E->isTypeOperand()) {
7109 TypeSourceInfo *TInfo
7110 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7111 if (!TInfo)
7112 return ExprError();
7113
7114 if (!getDerived().AlwaysRebuild() &&
7115 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007116 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007117
Douglas Gregor3c52a212011-03-06 17:40:41 +00007118 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007119 E->getLocStart(),
7120 TInfo,
7121 E->getLocEnd());
7122 }
7123
Francois Pichet01b7c302010-09-08 12:20:18 +00007124 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7125
7126 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7127 if (SubExpr.isInvalid())
7128 return ExprError();
7129
7130 if (!getDerived().AlwaysRebuild() &&
7131 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007132 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007133
7134 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7135 E->getLocStart(),
7136 SubExpr.get(),
7137 E->getLocEnd());
7138}
7139
7140template<typename Derived>
7141ExprResult
John McCall454feb92009-12-08 09:21:05 +00007142TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007143 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007144}
Mike Stump1eb44332009-09-09 15:08:12 +00007145
Douglas Gregorb98b1992009-08-11 05:31:07 +00007146template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007147ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007148TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007149 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007150 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007151}
Mike Stump1eb44332009-09-09 15:08:12 +00007152
Douglas Gregorb98b1992009-08-11 05:31:07 +00007153template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007154ExprResult
John McCall454feb92009-12-08 09:21:05 +00007155TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007156 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007157 QualType T;
7158 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7159 T = MD->getThisType(getSema().Context);
7160 else
7161 T = getSema().Context.getPointerType(
7162 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007163
Douglas Gregorec79d872012-02-24 17:41:38 +00007164 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7165 // Make sure that we capture 'this'.
7166 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007167 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007168 }
7169
Douglas Gregor828a1972010-01-07 23:12:05 +00007170 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007171}
Mike Stump1eb44332009-09-09 15:08:12 +00007172
Douglas Gregorb98b1992009-08-11 05:31:07 +00007173template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007174ExprResult
John McCall454feb92009-12-08 09:21:05 +00007175TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007176 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007177 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007178 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007179
Douglas Gregorb98b1992009-08-11 05:31:07 +00007180 if (!getDerived().AlwaysRebuild() &&
7181 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007182 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007183
Douglas Gregorbca01b42011-07-06 22:04:06 +00007184 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7185 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007186}
Mike Stump1eb44332009-09-09 15:08:12 +00007187
Douglas Gregorb98b1992009-08-11 05:31:07 +00007188template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007189ExprResult
John McCall454feb92009-12-08 09:21:05 +00007190TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007191 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007192 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7193 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007194 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007195 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007196
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007197 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007198 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007199 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007200
Douglas Gregor036aed12009-12-23 23:03:06 +00007201 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007202}
Mike Stump1eb44332009-09-09 15:08:12 +00007203
Douglas Gregorb98b1992009-08-11 05:31:07 +00007204template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007205ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007206TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7207 CXXScalarValueInitExpr *E) {
7208 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7209 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007210 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00007211
Douglas Gregorb98b1992009-08-11 05:31:07 +00007212 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007213 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007214 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007215
Douglas Gregorab6677e2010-09-08 00:15:04 +00007216 return getDerived().RebuildCXXScalarValueInitExpr(T,
7217 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007218 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007219}
Mike Stump1eb44332009-09-09 15:08:12 +00007220
Douglas Gregorb98b1992009-08-11 05:31:07 +00007221template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007222ExprResult
John McCall454feb92009-12-08 09:21:05 +00007223TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007224 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007225 TypeSourceInfo *AllocTypeInfo
7226 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7227 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007228 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007229
Douglas Gregorb98b1992009-08-11 05:31:07 +00007230 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007231 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007232 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007233 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007234
Douglas Gregorb98b1992009-08-11 05:31:07 +00007235 // Transform the placement arguments (if any).
7236 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007237 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007238 if (getDerived().TransformExprs(E->getPlacementArgs(),
7239 E->getNumPlacementArgs(), true,
7240 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007241 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007242
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007243 // Transform the initializer (if any).
7244 Expr *OldInit = E->getInitializer();
7245 ExprResult NewInit;
7246 if (OldInit)
7247 NewInit = getDerived().TransformExpr(OldInit);
7248 if (NewInit.isInvalid())
7249 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007250
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007251 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007252 FunctionDecl *OperatorNew = 0;
7253 if (E->getOperatorNew()) {
7254 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007255 getDerived().TransformDecl(E->getLocStart(),
7256 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007257 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007258 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007259 }
7260
7261 FunctionDecl *OperatorDelete = 0;
7262 if (E->getOperatorDelete()) {
7263 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007264 getDerived().TransformDecl(E->getLocStart(),
7265 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007266 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007267 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007268 }
Sean Huntc3021132010-05-05 15:23:54 +00007269
Douglas Gregorb98b1992009-08-11 05:31:07 +00007270 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007271 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007272 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007273 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007274 OperatorNew == E->getOperatorNew() &&
7275 OperatorDelete == E->getOperatorDelete() &&
7276 !ArgumentChanged) {
7277 // Mark any declarations we need as referenced.
7278 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007279 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007280 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007281 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007282 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007283
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007284 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007285 QualType ElementType
7286 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7287 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7288 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7289 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007290 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007291 }
7292 }
7293 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007294
John McCall3fa5cae2010-10-26 07:05:15 +00007295 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007296 }
Mike Stump1eb44332009-09-09 15:08:12 +00007297
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007298 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007299 if (!ArraySize.get()) {
7300 // If no array size was specified, but the new expression was
7301 // instantiated with an array type (e.g., "new T" where T is
7302 // instantiated with "int[4]"), extract the outer bound from the
7303 // array type as our array size. We do this with constant and
7304 // dependently-sized array types.
7305 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7306 if (!ArrayT) {
7307 // Do nothing
7308 } else if (const ConstantArrayType *ConsArrayT
7309 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007310 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007311 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7312 ConsArrayT->getSize(),
7313 SemaRef.Context.getSizeType(),
7314 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007315 AllocType = ConsArrayT->getElementType();
7316 } else if (const DependentSizedArrayType *DepArrayT
7317 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7318 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007319 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007320 AllocType = DepArrayT->getElementType();
7321 }
7322 }
7323 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007324
Douglas Gregorb98b1992009-08-11 05:31:07 +00007325 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7326 E->isGlobalNew(),
7327 /*FIXME:*/E->getLocStart(),
7328 move_arg(PlacementArgs),
7329 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007330 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007331 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007332 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007333 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007334 E->getDirectInitRange(),
7335 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007336}
Mike Stump1eb44332009-09-09 15:08:12 +00007337
Douglas Gregorb98b1992009-08-11 05:31:07 +00007338template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007339ExprResult
John McCall454feb92009-12-08 09:21:05 +00007340TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007341 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007342 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007343 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007344
Douglas Gregor1af74512010-02-26 00:38:10 +00007345 // Transform the delete operator, if known.
7346 FunctionDecl *OperatorDelete = 0;
7347 if (E->getOperatorDelete()) {
7348 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007349 getDerived().TransformDecl(E->getLocStart(),
7350 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007351 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007352 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007353 }
Sean Huntc3021132010-05-05 15:23:54 +00007354
Douglas Gregorb98b1992009-08-11 05:31:07 +00007355 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007356 Operand.get() == E->getArgument() &&
7357 OperatorDelete == E->getOperatorDelete()) {
7358 // Mark any declarations we need as referenced.
7359 // FIXME: instantiation-specific.
7360 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007361 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007362
7363 if (!E->getArgument()->isTypeDependent()) {
7364 QualType Destroyed = SemaRef.Context.getBaseElementType(
7365 E->getDestroyedType());
7366 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7367 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Eli Friedman5f2987c2012-02-02 03:46:19 +00007368 SemaRef.MarkFunctionReferenced(E->getLocStart(),
7369 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007370 }
7371 }
7372
John McCall3fa5cae2010-10-26 07:05:15 +00007373 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007374 }
Mike Stump1eb44332009-09-09 15:08:12 +00007375
Douglas Gregorb98b1992009-08-11 05:31:07 +00007376 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7377 E->isGlobalDelete(),
7378 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007379 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007380}
Mike Stump1eb44332009-09-09 15:08:12 +00007381
Douglas Gregorb98b1992009-08-11 05:31:07 +00007382template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007383ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007384TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007385 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007386 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007387 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007388 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007389
John McCallb3d87482010-08-24 05:47:05 +00007390 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007391 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007392 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007393 E->getOperatorLoc(),
7394 E->isArrow()? tok::arrow : tok::period,
7395 ObjectTypePtr,
7396 MayBePseudoDestructor);
7397 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007398 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007399
John McCallb3d87482010-08-24 05:47:05 +00007400 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007401 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7402 if (QualifierLoc) {
7403 QualifierLoc
7404 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7405 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007406 return ExprError();
7407 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007408 CXXScopeSpec SS;
7409 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007410
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007411 PseudoDestructorTypeStorage Destroyed;
7412 if (E->getDestroyedTypeInfo()) {
7413 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007414 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007415 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007416 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007417 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007418 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007419 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007420 // We aren't likely to be able to resolve the identifier down to a type
7421 // now anyway, so just retain the identifier.
7422 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7423 E->getDestroyedTypeLoc());
7424 } else {
7425 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007426 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007427 *E->getDestroyedTypeIdentifier(),
7428 E->getDestroyedTypeLoc(),
7429 /*Scope=*/0,
7430 SS, ObjectTypePtr,
7431 false);
7432 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007433 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007434
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007435 Destroyed
7436 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7437 E->getDestroyedTypeLoc());
7438 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007439
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007440 TypeSourceInfo *ScopeTypeInfo = 0;
7441 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007442 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007443 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007444 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007445 }
Sean Huntc3021132010-05-05 15:23:54 +00007446
John McCall9ae2f072010-08-23 23:25:46 +00007447 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007448 E->getOperatorLoc(),
7449 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007450 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007451 ScopeTypeInfo,
7452 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007453 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007454 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007455}
Mike Stump1eb44332009-09-09 15:08:12 +00007456
Douglas Gregora71d8192009-09-04 17:36:40 +00007457template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007458ExprResult
John McCallba135432009-11-21 08:51:07 +00007459TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007460 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007461 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7462 Sema::LookupOrdinaryName);
7463
7464 // Transform all the decls.
7465 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7466 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007467 NamedDecl *InstD = static_cast<NamedDecl*>(
7468 getDerived().TransformDecl(Old->getNameLoc(),
7469 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007470 if (!InstD) {
7471 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7472 // This can happen because of dependent hiding.
7473 if (isa<UsingShadowDecl>(*I))
7474 continue;
7475 else
John McCallf312b1e2010-08-26 23:41:50 +00007476 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007477 }
John McCallf7a1a742009-11-24 19:00:30 +00007478
7479 // Expand using declarations.
7480 if (isa<UsingDecl>(InstD)) {
7481 UsingDecl *UD = cast<UsingDecl>(InstD);
7482 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7483 E = UD->shadow_end(); I != E; ++I)
7484 R.addDecl(*I);
7485 continue;
7486 }
7487
7488 R.addDecl(InstD);
7489 }
7490
7491 // Resolve a kind, but don't do any further analysis. If it's
7492 // ambiguous, the callee needs to deal with it.
7493 R.resolveKind();
7494
7495 // Rebuild the nested-name qualifier, if present.
7496 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007497 if (Old->getQualifierLoc()) {
7498 NestedNameSpecifierLoc QualifierLoc
7499 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7500 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007501 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007502
Douglas Gregor4c9be892011-02-28 20:01:57 +00007503 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007504 }
7505
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007506 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007507 CXXRecordDecl *NamingClass
7508 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7509 Old->getNameLoc(),
7510 Old->getNamingClass()));
7511 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007512 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007513
Douglas Gregor66c45152010-04-27 16:10:10 +00007514 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007515 }
7516
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007517 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7518
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007519 // If we have neither explicit template arguments, nor the template keyword,
7520 // it's a normal declaration name.
7521 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007522 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7523
7524 // If we have template arguments, rebuild them, then rebuild the
7525 // templateid expression.
7526 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007527 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7528 Old->getNumTemplateArgs(),
7529 TransArgs))
7530 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007531
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007532 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007533 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007534}
Mike Stump1eb44332009-09-09 15:08:12 +00007535
Douglas Gregorb98b1992009-08-11 05:31:07 +00007536template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007537ExprResult
John McCall454feb92009-12-08 09:21:05 +00007538TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007539 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7540 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007541 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007542
Douglas Gregorb98b1992009-08-11 05:31:07 +00007543 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007544 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007545 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007546
Mike Stump1eb44332009-09-09 15:08:12 +00007547 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007548 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007549 T,
7550 E->getLocEnd());
7551}
Mike Stump1eb44332009-09-09 15:08:12 +00007552
Douglas Gregorb98b1992009-08-11 05:31:07 +00007553template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007554ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007555TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7556 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7557 if (!LhsT)
7558 return ExprError();
7559
7560 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7561 if (!RhsT)
7562 return ExprError();
7563
7564 if (!getDerived().AlwaysRebuild() &&
7565 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7566 return SemaRef.Owned(E);
7567
7568 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7569 E->getLocStart(),
7570 LhsT, RhsT,
7571 E->getLocEnd());
7572}
7573
7574template<typename Derived>
7575ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007576TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7577 bool ArgChanged = false;
7578 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7579 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7580 TypeSourceInfo *From = E->getArg(I);
7581 TypeLoc FromTL = From->getTypeLoc();
7582 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7583 TypeLocBuilder TLB;
7584 TLB.reserve(FromTL.getFullDataSize());
7585 QualType To = getDerived().TransformType(TLB, FromTL);
7586 if (To.isNull())
7587 return ExprError();
7588
7589 if (To == From->getType())
7590 Args.push_back(From);
7591 else {
7592 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7593 ArgChanged = true;
7594 }
7595 continue;
7596 }
7597
7598 ArgChanged = true;
7599
7600 // We have a pack expansion. Instantiate it.
7601 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
7602 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7603 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7604 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
7605
7606 // Determine whether the set of unexpanded parameter packs can and should
7607 // be expanded.
7608 bool Expand = true;
7609 bool RetainExpansion = false;
7610 llvm::Optional<unsigned> OrigNumExpansions
7611 = ExpansionTL.getTypePtr()->getNumExpansions();
7612 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7613 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7614 PatternTL.getSourceRange(),
7615 Unexpanded,
7616 Expand, RetainExpansion,
7617 NumExpansions))
7618 return ExprError();
7619
7620 if (!Expand) {
7621 // The transform has determined that we should perform a simple
7622 // transformation on the pack expansion, producing another pack
7623 // expansion.
7624 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7625
7626 TypeLocBuilder TLB;
7627 TLB.reserve(From->getTypeLoc().getFullDataSize());
7628
7629 QualType To = getDerived().TransformType(TLB, PatternTL);
7630 if (To.isNull())
7631 return ExprError();
7632
7633 To = getDerived().RebuildPackExpansionType(To,
7634 PatternTL.getSourceRange(),
7635 ExpansionTL.getEllipsisLoc(),
7636 NumExpansions);
7637 if (To.isNull())
7638 return ExprError();
7639
7640 PackExpansionTypeLoc ToExpansionTL
7641 = TLB.push<PackExpansionTypeLoc>(To);
7642 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7643 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7644 continue;
7645 }
7646
7647 // Expand the pack expansion by substituting for each argument in the
7648 // pack(s).
7649 for (unsigned I = 0; I != *NumExpansions; ++I) {
7650 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7651 TypeLocBuilder TLB;
7652 TLB.reserve(PatternTL.getFullDataSize());
7653 QualType To = getDerived().TransformType(TLB, PatternTL);
7654 if (To.isNull())
7655 return ExprError();
7656
7657 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7658 }
7659
7660 if (!RetainExpansion)
7661 continue;
7662
7663 // If we're supposed to retain a pack expansion, do so by temporarily
7664 // forgetting the partially-substituted parameter pack.
7665 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7666
7667 TypeLocBuilder TLB;
7668 TLB.reserve(From->getTypeLoc().getFullDataSize());
7669
7670 QualType To = getDerived().TransformType(TLB, PatternTL);
7671 if (To.isNull())
7672 return ExprError();
7673
7674 To = getDerived().RebuildPackExpansionType(To,
7675 PatternTL.getSourceRange(),
7676 ExpansionTL.getEllipsisLoc(),
7677 NumExpansions);
7678 if (To.isNull())
7679 return ExprError();
7680
7681 PackExpansionTypeLoc ToExpansionTL
7682 = TLB.push<PackExpansionTypeLoc>(To);
7683 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7684 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7685 }
7686
7687 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7688 return SemaRef.Owned(E);
7689
7690 return getDerived().RebuildTypeTrait(E->getTrait(),
7691 E->getLocStart(),
7692 Args,
7693 E->getLocEnd());
7694}
7695
7696template<typename Derived>
7697ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007698TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7699 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7700 if (!T)
7701 return ExprError();
7702
7703 if (!getDerived().AlwaysRebuild() &&
7704 T == E->getQueriedTypeSourceInfo())
7705 return SemaRef.Owned(E);
7706
7707 ExprResult SubExpr;
7708 {
7709 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7710 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7711 if (SubExpr.isInvalid())
7712 return ExprError();
7713
7714 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7715 return SemaRef.Owned(E);
7716 }
7717
7718 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7719 E->getLocStart(),
7720 T,
7721 SubExpr.get(),
7722 E->getLocEnd());
7723}
7724
7725template<typename Derived>
7726ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007727TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7728 ExprResult SubExpr;
7729 {
7730 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7731 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7732 if (SubExpr.isInvalid())
7733 return ExprError();
7734
7735 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7736 return SemaRef.Owned(E);
7737 }
7738
7739 return getDerived().RebuildExpressionTrait(
7740 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7741}
7742
7743template<typename Derived>
7744ExprResult
John McCall865d4472009-11-19 22:55:06 +00007745TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007746 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007747 NestedNameSpecifierLoc QualifierLoc
7748 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7749 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007750 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007751 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007752
John McCall43fed0d2010-11-12 08:19:04 +00007753 // TODO: If this is a conversion-function-id, verify that the
7754 // destination type name (if present) resolves the same way after
7755 // instantiation as it did in the local scope.
7756
Abramo Bagnara25777432010-08-11 22:01:17 +00007757 DeclarationNameInfo NameInfo
7758 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7759 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007760 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007761
John McCallf7a1a742009-11-24 19:00:30 +00007762 if (!E->hasExplicitTemplateArgs()) {
7763 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007764 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007765 // Note: it is sufficient to compare the Name component of NameInfo:
7766 // if name has not changed, DNLoc has not changed either.
7767 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007768 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007769
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007770 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007771 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007772 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007773 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007774 }
John McCalld5532b62009-11-23 01:53:49 +00007775
7776 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007777 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7778 E->getNumTemplateArgs(),
7779 TransArgs))
7780 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007781
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007782 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007783 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007784 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007785 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007786}
7787
7788template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007789ExprResult
John McCall454feb92009-12-08 09:21:05 +00007790TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007791 // CXXConstructExprs are always implicit, so when we have a
7792 // 1-argument construction we just transform that argument.
7793 if (E->getNumArgs() == 1 ||
7794 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7795 return getDerived().TransformExpr(E->getArg(0));
7796
Douglas Gregorb98b1992009-08-11 05:31:07 +00007797 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7798
7799 QualType T = getDerived().TransformType(E->getType());
7800 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007801 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007802
7803 CXXConstructorDecl *Constructor
7804 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007805 getDerived().TransformDecl(E->getLocStart(),
7806 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007807 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007808 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007809
Douglas Gregorb98b1992009-08-11 05:31:07 +00007810 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007811 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007812 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7813 &ArgumentChanged))
7814 return ExprError();
7815
Douglas Gregorb98b1992009-08-11 05:31:07 +00007816 if (!getDerived().AlwaysRebuild() &&
7817 T == E->getType() &&
7818 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007819 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007820 // Mark the constructor as referenced.
7821 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007822 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007823 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007824 }
Mike Stump1eb44332009-09-09 15:08:12 +00007825
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007826 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7827 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007828 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007829 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007830 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007831 E->getConstructionKind(),
7832 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007833}
Mike Stump1eb44332009-09-09 15:08:12 +00007834
Douglas Gregorb98b1992009-08-11 05:31:07 +00007835/// \brief Transform a C++ temporary-binding expression.
7836///
Douglas Gregor51326552009-12-24 18:51:59 +00007837/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7838/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007839template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007840ExprResult
John McCall454feb92009-12-08 09:21:05 +00007841TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007842 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007843}
Mike Stump1eb44332009-09-09 15:08:12 +00007844
John McCall4765fa02010-12-06 08:20:24 +00007845/// \brief Transform a C++ expression that contains cleanups that should
7846/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007847///
John McCall4765fa02010-12-06 08:20:24 +00007848/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007849/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007850template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007851ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007852TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007853 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007854}
Mike Stump1eb44332009-09-09 15:08:12 +00007855
Douglas Gregorb98b1992009-08-11 05:31:07 +00007856template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007857ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007858TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007859 CXXTemporaryObjectExpr *E) {
7860 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7861 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007862 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007863
Douglas Gregorb98b1992009-08-11 05:31:07 +00007864 CXXConstructorDecl *Constructor
7865 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007866 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007867 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007868 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007869 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007870
Douglas Gregorb98b1992009-08-11 05:31:07 +00007871 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007872 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007873 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007874 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7875 &ArgumentChanged))
7876 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007877
Douglas Gregorb98b1992009-08-11 05:31:07 +00007878 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007879 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007880 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007881 !ArgumentChanged) {
7882 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007883 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007884 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007885 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007886
7887 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7888 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007889 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007890 E->getLocEnd());
7891}
Mike Stump1eb44332009-09-09 15:08:12 +00007892
Douglas Gregorb98b1992009-08-11 05:31:07 +00007893template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007894ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007895TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007896 // Create the local class that will describe the lambda.
7897 CXXRecordDecl *Class
Douglas Gregorf54486a2012-04-04 17:40:10 +00007898 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7899 /*KnownDependent=*/false);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007900 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7901
7902 // Transform the type of the lambda parameters and start the definition of
7903 // the lambda itself.
7904 TypeSourceInfo *MethodTy
7905 = TransformType(E->getCallOperator()->getTypeSourceInfo());
7906 if (!MethodTy)
7907 return ExprError();
7908
Douglas Gregorc6889e72012-02-14 22:28:59 +00007909 // Transform lambda parameters.
7910 bool Invalid = false;
7911 llvm::SmallVector<QualType, 4> ParamTypes;
7912 llvm::SmallVector<ParmVarDecl *, 4> Params;
7913 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7914 E->getCallOperator()->param_begin(),
7915 E->getCallOperator()->param_size(),
7916 0, ParamTypes, &Params))
7917 Invalid = true;
7918
Douglas Gregordfca6f52012-02-13 22:00:16 +00007919 // Build the call operator.
Douglas Gregorf54486a2012-04-04 17:40:10 +00007920 // Note: Once a lambda mangling number and context declaration have been
7921 // assigned, they never change.
7922 unsigned ManglingNumber = E->getLambdaClass()->getLambdaManglingNumber();
7923 Decl *ContextDecl = E->getLambdaClass()->getLambdaContextDecl();
Douglas Gregordfca6f52012-02-13 22:00:16 +00007924 CXXMethodDecl *CallOperator
7925 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
7926 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007927 E->getCallOperator()->getLocEnd(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00007928 Params, ManglingNumber, ContextDecl);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007929 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
7930
Douglas Gregord5387e82012-02-14 00:00:48 +00007931 // FIXME: Instantiation-specific.
7932 CallOperator->setInstantiationOfMemberFunction(E->getCallOperator(),
7933 TSK_ImplicitInstantiation);
7934
7935 // Introduce the context of the call operator.
7936 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7937
Douglas Gregordfca6f52012-02-13 22:00:16 +00007938 // Enter the scope of the lambda.
7939 sema::LambdaScopeInfo *LSI
7940 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7941 E->getCaptureDefault(),
7942 E->hasExplicitParameters(),
7943 E->hasExplicitResultType(),
7944 E->isMutable());
7945
7946 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00007947 bool FinishedExplicitCaptures = false;
7948 for (LambdaExpr::capture_iterator C = E->capture_begin(),
7949 CEnd = E->capture_end();
7950 C != CEnd; ++C) {
7951 // When we hit the first implicit capture, tell Sema that we've finished
7952 // the list of explicit captures.
7953 if (!FinishedExplicitCaptures && C->isImplicit()) {
7954 getSema().finishLambdaExplicitCaptures(LSI);
7955 FinishedExplicitCaptures = true;
7956 }
7957
7958 // Capturing 'this' is trivial.
7959 if (C->capturesThis()) {
7960 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7961 continue;
7962 }
7963
Douglas Gregora7365242012-02-14 19:27:52 +00007964 // Determine the capture kind for Sema.
7965 Sema::TryCaptureKind Kind
7966 = C->isImplicit()? Sema::TryCapture_Implicit
7967 : C->getCaptureKind() == LCK_ByCopy
7968 ? Sema::TryCapture_ExplicitByVal
7969 : Sema::TryCapture_ExplicitByRef;
7970 SourceLocation EllipsisLoc;
7971 if (C->isPackExpansion()) {
7972 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7973 bool ShouldExpand = false;
7974 bool RetainExpansion = false;
7975 llvm::Optional<unsigned> NumExpansions;
7976 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7977 C->getLocation(),
7978 Unexpanded,
7979 ShouldExpand, RetainExpansion,
7980 NumExpansions))
7981 return ExprError();
7982
7983 if (ShouldExpand) {
7984 // The transform has determined that we should perform an expansion;
7985 // transform and capture each of the arguments.
7986 // expansion of the pattern. Do so.
7987 VarDecl *Pack = C->getCapturedVar();
7988 for (unsigned I = 0; I != *NumExpansions; ++I) {
7989 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7990 VarDecl *CapturedVar
7991 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7992 Pack));
7993 if (!CapturedVar) {
7994 Invalid = true;
7995 continue;
7996 }
7997
7998 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007999 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregora7365242012-02-14 19:27:52 +00008000 }
8001 continue;
8002 }
8003
8004 EllipsisLoc = C->getEllipsisLoc();
8005 }
8006
Douglas Gregordfca6f52012-02-13 22:00:16 +00008007 // Transform the captured variable.
8008 VarDecl *CapturedVar
8009 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
8010 C->getCapturedVar()));
8011 if (!CapturedVar) {
8012 Invalid = true;
8013 continue;
8014 }
Douglas Gregora7365242012-02-14 19:27:52 +00008015
Douglas Gregordfca6f52012-02-13 22:00:16 +00008016 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008017 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008018 }
8019 if (!FinishedExplicitCaptures)
8020 getSema().finishLambdaExplicitCaptures(LSI);
8021
Douglas Gregordfca6f52012-02-13 22:00:16 +00008022
8023 // Enter a new evaluation context to insulate the lambda from any
8024 // cleanups from the enclosing full-expression.
8025 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
8026
8027 if (Invalid) {
8028 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
8029 /*IsInstantiation=*/true);
8030 return ExprError();
8031 }
8032
8033 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008034 StmtResult Body = getDerived().TransformStmt(E->getBody());
8035 if (Body.isInvalid()) {
8036 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
8037 /*IsInstantiation=*/true);
8038 return ExprError();
8039 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008040
Douglas Gregordfca6f52012-02-13 22:00:16 +00008041 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008042 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008043}
8044
8045template<typename Derived>
8046ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008047TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008048 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008049 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8050 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008051 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008052
Douglas Gregorb98b1992009-08-11 05:31:07 +00008053 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008054 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008055 Args.reserve(E->arg_size());
8056 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
8057 &ArgumentChanged))
8058 return ExprError();
8059
Douglas Gregorb98b1992009-08-11 05:31:07 +00008060 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008061 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008062 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008063 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008064
Douglas Gregorb98b1992009-08-11 05:31:07 +00008065 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008066 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008067 E->getLParenLoc(),
8068 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00008069 E->getRParenLoc());
8070}
Mike Stump1eb44332009-09-09 15:08:12 +00008071
Douglas Gregorb98b1992009-08-11 05:31:07 +00008072template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008073ExprResult
John McCall865d4472009-11-19 22:55:06 +00008074TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008075 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008076 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008077 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008078 Expr *OldBase;
8079 QualType BaseType;
8080 QualType ObjectType;
8081 if (!E->isImplicitAccess()) {
8082 OldBase = E->getBase();
8083 Base = getDerived().TransformExpr(OldBase);
8084 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008085 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008086
John McCallaa81e162009-12-01 22:10:20 +00008087 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008088 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008089 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008090 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008091 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008092 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008093 ObjectTy,
8094 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008095 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008096 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008097
John McCallb3d87482010-08-24 05:47:05 +00008098 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008099 BaseType = ((Expr*) Base.get())->getType();
8100 } else {
8101 OldBase = 0;
8102 BaseType = getDerived().TransformType(E->getBaseType());
8103 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8104 }
Mike Stump1eb44332009-09-09 15:08:12 +00008105
Douglas Gregor6cd21982009-10-20 05:58:46 +00008106 // Transform the first part of the nested-name-specifier that qualifies
8107 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008108 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008109 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008110 E->getFirstQualifierFoundInScope(),
8111 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008112
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008113 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008114 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008115 QualifierLoc
8116 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8117 ObjectType,
8118 FirstQualifierInScope);
8119 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008120 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008121 }
Mike Stump1eb44332009-09-09 15:08:12 +00008122
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008123 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8124
John McCall43fed0d2010-11-12 08:19:04 +00008125 // TODO: If this is a conversion-function-id, verify that the
8126 // destination type name (if present) resolves the same way after
8127 // instantiation as it did in the local scope.
8128
Abramo Bagnara25777432010-08-11 22:01:17 +00008129 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008130 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008131 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008132 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008133
John McCallaa81e162009-12-01 22:10:20 +00008134 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008135 // This is a reference to a member without an explicitly-specified
8136 // template argument list. Optimize for this common case.
8137 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008138 Base.get() == OldBase &&
8139 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008140 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008141 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008142 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008143 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008144
John McCall9ae2f072010-08-23 23:25:46 +00008145 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008146 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008147 E->isArrow(),
8148 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008149 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008150 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008151 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008152 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008153 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008154 }
8155
John McCalld5532b62009-11-23 01:53:49 +00008156 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008157 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8158 E->getNumTemplateArgs(),
8159 TransArgs))
8160 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008161
John McCall9ae2f072010-08-23 23:25:46 +00008162 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008163 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008164 E->isArrow(),
8165 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008166 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008167 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008168 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008169 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008170 &TransArgs);
8171}
8172
8173template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008174ExprResult
John McCall454feb92009-12-08 09:21:05 +00008175TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008176 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008177 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008178 QualType BaseType;
8179 if (!Old->isImplicitAccess()) {
8180 Base = getDerived().TransformExpr(Old->getBase());
8181 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008182 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008183 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8184 Old->isArrow());
8185 if (Base.isInvalid())
8186 return ExprError();
8187 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008188 } else {
8189 BaseType = getDerived().TransformType(Old->getBaseType());
8190 }
John McCall129e2df2009-11-30 22:42:35 +00008191
Douglas Gregor4c9be892011-02-28 20:01:57 +00008192 NestedNameSpecifierLoc QualifierLoc;
8193 if (Old->getQualifierLoc()) {
8194 QualifierLoc
8195 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8196 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008197 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008198 }
8199
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008200 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8201
Abramo Bagnara25777432010-08-11 22:01:17 +00008202 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008203 Sema::LookupOrdinaryName);
8204
8205 // Transform all the decls.
8206 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8207 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008208 NamedDecl *InstD = static_cast<NamedDecl*>(
8209 getDerived().TransformDecl(Old->getMemberLoc(),
8210 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008211 if (!InstD) {
8212 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8213 // This can happen because of dependent hiding.
8214 if (isa<UsingShadowDecl>(*I))
8215 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008216 else {
8217 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008218 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008219 }
John McCall9f54ad42009-12-10 09:41:52 +00008220 }
John McCall129e2df2009-11-30 22:42:35 +00008221
8222 // Expand using declarations.
8223 if (isa<UsingDecl>(InstD)) {
8224 UsingDecl *UD = cast<UsingDecl>(InstD);
8225 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8226 E = UD->shadow_end(); I != E; ++I)
8227 R.addDecl(*I);
8228 continue;
8229 }
8230
8231 R.addDecl(InstD);
8232 }
8233
8234 R.resolveKind();
8235
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008236 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008237 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00008238 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008239 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008240 Old->getMemberLoc(),
8241 Old->getNamingClass()));
8242 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008243 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008244
Douglas Gregor66c45152010-04-27 16:10:10 +00008245 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008246 }
Sean Huntc3021132010-05-05 15:23:54 +00008247
John McCall129e2df2009-11-30 22:42:35 +00008248 TemplateArgumentListInfo TransArgs;
8249 if (Old->hasExplicitTemplateArgs()) {
8250 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8251 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008252 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8253 Old->getNumTemplateArgs(),
8254 TransArgs))
8255 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008256 }
John McCallc2233c52010-01-15 08:34:02 +00008257
8258 // FIXME: to do this check properly, we will need to preserve the
8259 // first-qualifier-in-scope here, just in case we had a dependent
8260 // base (and therefore couldn't do the check) and a
8261 // nested-name-qualifier (and therefore could do the lookup).
8262 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00008263
John McCall9ae2f072010-08-23 23:25:46 +00008264 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008265 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008266 Old->getOperatorLoc(),
8267 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008268 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008269 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008270 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008271 R,
8272 (Old->hasExplicitTemplateArgs()
8273 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008274}
8275
8276template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008277ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008278TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008279 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008280 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8281 if (SubExpr.isInvalid())
8282 return ExprError();
8283
8284 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008285 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008286
8287 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8288}
8289
8290template<typename Derived>
8291ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008292TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008293 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8294 if (Pattern.isInvalid())
8295 return ExprError();
8296
8297 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8298 return SemaRef.Owned(E);
8299
Douglas Gregor67fd1252011-01-14 21:20:45 +00008300 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8301 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008302}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008303
8304template<typename Derived>
8305ExprResult
8306TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8307 // If E is not value-dependent, then nothing will change when we transform it.
8308 // Note: This is an instantiation-centric view.
8309 if (!E->isValueDependent())
8310 return SemaRef.Owned(E);
8311
8312 // Note: None of the implementations of TryExpandParameterPacks can ever
8313 // produce a diagnostic when given only a single unexpanded parameter pack,
8314 // so
8315 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8316 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008317 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008318 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00008319 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008320 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008321 ShouldExpand, RetainExpansion,
8322 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008323 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00008324
Douglas Gregor089e8932011-10-10 18:59:29 +00008325 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008326 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00008327
8328 NamedDecl *Pack = E->getPack();
8329 if (!ShouldExpand) {
8330 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
8331 Pack));
8332 if (!Pack)
8333 return ExprError();
8334 }
8335
Douglas Gregoree8aff02011-01-04 17:33:58 +00008336
8337 // We now know the length of the parameter pack, so build a new expression
8338 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00008339 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00008340 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008341 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008342}
8343
Douglas Gregorbe230c32011-01-03 17:17:50 +00008344template<typename Derived>
8345ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008346TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8347 SubstNonTypeTemplateParmPackExpr *E) {
8348 // Default behavior is to do nothing with this transformation.
8349 return SemaRef.Owned(E);
8350}
8351
8352template<typename Derived>
8353ExprResult
John McCall91a57552011-07-15 05:09:51 +00008354TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8355 SubstNonTypeTemplateParmExpr *E) {
8356 // Default behavior is to do nothing with this transformation.
8357 return SemaRef.Owned(E);
8358}
8359
8360template<typename Derived>
8361ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008362TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8363 MaterializeTemporaryExpr *E) {
8364 return getDerived().TransformExpr(E->GetTemporaryExpr());
8365}
8366
8367template<typename Derived>
8368ExprResult
John McCall454feb92009-12-08 09:21:05 +00008369TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008370 return SemaRef.MaybeBindToTemporary(E);
8371}
8372
8373template<typename Derived>
8374ExprResult
8375TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008376 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008377}
8378
8379template<typename Derived>
8380ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008381TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8382 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8383 if (SubExpr.isInvalid())
8384 return ExprError();
8385
8386 if (!getDerived().AlwaysRebuild() &&
8387 SubExpr.get() == E->getSubExpr())
8388 return SemaRef.Owned(E);
8389
8390 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008391}
8392
8393template<typename Derived>
8394ExprResult
8395TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8396 // Transform each of the elements.
8397 llvm::SmallVector<Expr *, 8> Elements;
8398 bool ArgChanged = false;
8399 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
8400 /*IsCall=*/false, Elements, &ArgChanged))
8401 return ExprError();
8402
8403 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8404 return SemaRef.MaybeBindToTemporary(E);
8405
8406 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8407 Elements.data(),
8408 Elements.size());
8409}
8410
8411template<typename Derived>
8412ExprResult
8413TreeTransform<Derived>::TransformObjCDictionaryLiteral(
8414 ObjCDictionaryLiteral *E) {
8415 // Transform each of the elements.
8416 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8417 bool ArgChanged = false;
8418 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8419 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
8420
8421 if (OrigElement.isPackExpansion()) {
8422 // This key/value element is a pack expansion.
8423 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8424 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8425 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8426 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8427
8428 // Determine whether the set of unexpanded parameter packs can
8429 // and should be expanded.
8430 bool Expand = true;
8431 bool RetainExpansion = false;
8432 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8433 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8434 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8435 OrigElement.Value->getLocEnd());
8436 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8437 PatternRange,
8438 Unexpanded,
8439 Expand, RetainExpansion,
8440 NumExpansions))
8441 return ExprError();
8442
8443 if (!Expand) {
8444 // The transform has determined that we should perform a simple
8445 // transformation on the pack expansion, producing another pack
8446 // expansion.
8447 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8448 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8449 if (Key.isInvalid())
8450 return ExprError();
8451
8452 if (Key.get() != OrigElement.Key)
8453 ArgChanged = true;
8454
8455 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8456 if (Value.isInvalid())
8457 return ExprError();
8458
8459 if (Value.get() != OrigElement.Value)
8460 ArgChanged = true;
8461
8462 ObjCDictionaryElement Expansion = {
8463 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8464 };
8465 Elements.push_back(Expansion);
8466 continue;
8467 }
8468
8469 // Record right away that the argument was changed. This needs
8470 // to happen even if the array expands to nothing.
8471 ArgChanged = true;
8472
8473 // The transform has determined that we should perform an elementwise
8474 // expansion of the pattern. Do so.
8475 for (unsigned I = 0; I != *NumExpansions; ++I) {
8476 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8477 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8478 if (Key.isInvalid())
8479 return ExprError();
8480
8481 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8482 if (Value.isInvalid())
8483 return ExprError();
8484
8485 ObjCDictionaryElement Element = {
8486 Key.get(), Value.get(), SourceLocation(), NumExpansions
8487 };
8488
8489 // If any unexpanded parameter packs remain, we still have a
8490 // pack expansion.
8491 if (Key.get()->containsUnexpandedParameterPack() ||
8492 Value.get()->containsUnexpandedParameterPack())
8493 Element.EllipsisLoc = OrigElement.EllipsisLoc;
8494
8495 Elements.push_back(Element);
8496 }
8497
8498 // We've finished with this pack expansion.
8499 continue;
8500 }
8501
8502 // Transform and check key.
8503 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8504 if (Key.isInvalid())
8505 return ExprError();
8506
8507 if (Key.get() != OrigElement.Key)
8508 ArgChanged = true;
8509
8510 // Transform and check value.
8511 ExprResult Value
8512 = getDerived().TransformExpr(OrigElement.Value);
8513 if (Value.isInvalid())
8514 return ExprError();
8515
8516 if (Value.get() != OrigElement.Value)
8517 ArgChanged = true;
8518
8519 ObjCDictionaryElement Element = {
8520 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8521 };
8522 Elements.push_back(Element);
8523 }
8524
8525 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8526 return SemaRef.MaybeBindToTemporary(E);
8527
8528 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8529 Elements.data(),
8530 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008531}
8532
Mike Stump1eb44332009-09-09 15:08:12 +00008533template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008534ExprResult
John McCall454feb92009-12-08 09:21:05 +00008535TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008536 TypeSourceInfo *EncodedTypeInfo
8537 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8538 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008539 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008540
Douglas Gregorb98b1992009-08-11 05:31:07 +00008541 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008542 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008543 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008544
8545 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008546 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008547 E->getRParenLoc());
8548}
Mike Stump1eb44332009-09-09 15:08:12 +00008549
Douglas Gregorb98b1992009-08-11 05:31:07 +00008550template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008551ExprResult TreeTransform<Derived>::
8552TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8553 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8554 if (result.isInvalid()) return ExprError();
8555 Expr *subExpr = result.take();
8556
8557 if (!getDerived().AlwaysRebuild() &&
8558 subExpr == E->getSubExpr())
8559 return SemaRef.Owned(E);
8560
8561 return SemaRef.Owned(new(SemaRef.Context)
8562 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8563}
8564
8565template<typename Derived>
8566ExprResult TreeTransform<Derived>::
8567TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
8568 TypeSourceInfo *TSInfo
8569 = getDerived().TransformType(E->getTypeInfoAsWritten());
8570 if (!TSInfo)
8571 return ExprError();
8572
8573 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
8574 if (Result.isInvalid())
8575 return ExprError();
8576
8577 if (!getDerived().AlwaysRebuild() &&
8578 TSInfo == E->getTypeInfoAsWritten() &&
8579 Result.get() == E->getSubExpr())
8580 return SemaRef.Owned(E);
8581
8582 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
8583 E->getBridgeKeywordLoc(), TSInfo,
8584 Result.get());
8585}
8586
8587template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008588ExprResult
John McCall454feb92009-12-08 09:21:05 +00008589TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008590 // Transform arguments.
8591 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008592 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008593 Args.reserve(E->getNumArgs());
8594 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
8595 &ArgChanged))
8596 return ExprError();
8597
Douglas Gregor92e986e2010-04-22 16:44:27 +00008598 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8599 // Class message: transform the receiver type.
8600 TypeSourceInfo *ReceiverTypeInfo
8601 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8602 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008603 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008604
Douglas Gregor92e986e2010-04-22 16:44:27 +00008605 // If nothing changed, just retain the existing message send.
8606 if (!getDerived().AlwaysRebuild() &&
8607 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008608 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008609
8610 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008611 SmallVector<SourceLocation, 16> SelLocs;
8612 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008613 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8614 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008615 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008616 E->getMethodDecl(),
8617 E->getLeftLoc(),
8618 move_arg(Args),
8619 E->getRightLoc());
8620 }
8621
8622 // Instance message: transform the receiver
8623 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8624 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008625 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008626 = getDerived().TransformExpr(E->getInstanceReceiver());
8627 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008628 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008629
8630 // If nothing changed, just retain the existing message send.
8631 if (!getDerived().AlwaysRebuild() &&
8632 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008633 return SemaRef.MaybeBindToTemporary(E);
Sean Huntc3021132010-05-05 15:23:54 +00008634
Douglas Gregor92e986e2010-04-22 16:44:27 +00008635 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008636 SmallVector<SourceLocation, 16> SelLocs;
8637 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008638 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008639 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008640 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008641 E->getMethodDecl(),
8642 E->getLeftLoc(),
8643 move_arg(Args),
8644 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008645}
8646
Mike Stump1eb44332009-09-09 15:08:12 +00008647template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008648ExprResult
John McCall454feb92009-12-08 09:21:05 +00008649TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008650 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008651}
8652
Mike Stump1eb44332009-09-09 15:08:12 +00008653template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008654ExprResult
John McCall454feb92009-12-08 09:21:05 +00008655TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008656 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008657}
8658
Mike Stump1eb44332009-09-09 15:08:12 +00008659template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008660ExprResult
John McCall454feb92009-12-08 09:21:05 +00008661TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008662 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008663 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008664 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008665 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008666
8667 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008668
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008669 // If nothing changed, just retain the existing expression.
8670 if (!getDerived().AlwaysRebuild() &&
8671 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008672 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008673
John McCall9ae2f072010-08-23 23:25:46 +00008674 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008675 E->getLocation(),
8676 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008677}
8678
Mike Stump1eb44332009-09-09 15:08:12 +00008679template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008680ExprResult
John McCall454feb92009-12-08 09:21:05 +00008681TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008682 // 'super' and types never change. Property never changes. Just
8683 // retain the existing expression.
8684 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008685 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00008686
Douglas Gregore3303542010-04-26 20:47:02 +00008687 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008688 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008689 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008690 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008691
Douglas Gregore3303542010-04-26 20:47:02 +00008692 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008693
Douglas Gregore3303542010-04-26 20:47:02 +00008694 // If nothing changed, just retain the existing expression.
8695 if (!getDerived().AlwaysRebuild() &&
8696 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008697 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008698
John McCall12f78a62010-12-02 01:19:52 +00008699 if (E->isExplicitProperty())
8700 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8701 E->getExplicitProperty(),
8702 E->getLocation());
8703
8704 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008705 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008706 E->getImplicitPropertyGetter(),
8707 E->getImplicitPropertySetter(),
8708 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008709}
8710
Mike Stump1eb44332009-09-09 15:08:12 +00008711template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008712ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008713TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8714 // Transform the base expression.
8715 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8716 if (Base.isInvalid())
8717 return ExprError();
8718
8719 // Transform the key expression.
8720 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8721 if (Key.isInvalid())
8722 return ExprError();
8723
8724 // If nothing changed, just retain the existing expression.
8725 if (!getDerived().AlwaysRebuild() &&
8726 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8727 return SemaRef.Owned(E);
8728
8729 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
8730 Base.get(), Key.get(),
8731 E->getAtIndexMethodDecl(),
8732 E->setAtIndexMethodDecl());
8733}
8734
8735template<typename Derived>
8736ExprResult
John McCall454feb92009-12-08 09:21:05 +00008737TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008738 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008739 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008740 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008741 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008742
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008743 // If nothing changed, just retain the existing expression.
8744 if (!getDerived().AlwaysRebuild() &&
8745 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008746 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008747
John McCall9ae2f072010-08-23 23:25:46 +00008748 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008749 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008750}
8751
Mike Stump1eb44332009-09-09 15:08:12 +00008752template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008753ExprResult
John McCall454feb92009-12-08 09:21:05 +00008754TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008755 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008756 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008757 SubExprs.reserve(E->getNumSubExprs());
8758 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8759 SubExprs, &ArgumentChanged))
8760 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008761
Douglas Gregorb98b1992009-08-11 05:31:07 +00008762 if (!getDerived().AlwaysRebuild() &&
8763 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008764 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008765
Douglas Gregorb98b1992009-08-11 05:31:07 +00008766 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8767 move_arg(SubExprs),
8768 E->getRParenLoc());
8769}
8770
Mike Stump1eb44332009-09-09 15:08:12 +00008771template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008772ExprResult
John McCall454feb92009-12-08 09:21:05 +00008773TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008774 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008775
John McCallc6ac9c32011-02-04 18:33:18 +00008776 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8777 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8778
8779 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008780 blockScope->TheDecl->setBlockMissingReturnType(
8781 oldBlock->blockMissingReturnType());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008782
Chris Lattner686775d2011-07-20 06:58:45 +00008783 SmallVector<ParmVarDecl*, 4> params;
8784 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008785
8786 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008787 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8788 oldBlock->param_begin(),
8789 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008790 0, paramTypes, &params)) {
8791 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008792 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008793 }
John McCallc6ac9c32011-02-04 18:33:18 +00008794
8795 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008796 QualType exprResultType =
8797 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008798
8799 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008800 if (exprResultType->isObjCObjectType()) {
John McCallc6ac9c32011-02-04 18:33:18 +00008801 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008802 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008803 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008804 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008805 return ExprError();
8806 }
John McCall711c52b2011-01-05 12:14:39 +00008807
John McCallc6ac9c32011-02-04 18:33:18 +00008808 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008809 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008810 paramTypes.data(),
8811 paramTypes.size(),
8812 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008813 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008814 exprFunctionType->getExtInfo());
8815 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008816
8817 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008818 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008819 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008820
8821 if (!oldBlock->blockMissingReturnType()) {
8822 blockScope->HasImplicitReturnType = false;
8823 blockScope->ReturnType = exprResultType;
8824 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008825
John McCall711c52b2011-01-05 12:14:39 +00008826 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008827 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008828 if (body.isInvalid()) {
8829 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008830 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008831 }
John McCall711c52b2011-01-05 12:14:39 +00008832
John McCallc6ac9c32011-02-04 18:33:18 +00008833#ifndef NDEBUG
8834 // In builds with assertions, make sure that we captured everything we
8835 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008836 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8837 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8838 e = oldBlock->capture_end(); i != e; ++i) {
8839 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008840
Douglas Gregorfc921372011-05-20 15:32:55 +00008841 // Ignore parameter packs.
8842 if (isa<ParmVarDecl>(oldCapture) &&
8843 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8844 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008845
Douglas Gregorfc921372011-05-20 15:32:55 +00008846 VarDecl *newCapture =
8847 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8848 oldCapture));
8849 assert(blockScope->CaptureMap.count(newCapture));
8850 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008851 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008852 }
8853#endif
8854
8855 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8856 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008857}
8858
Mike Stump1eb44332009-09-09 15:08:12 +00008859template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008860ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008861TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008862 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008863}
Eli Friedman276b0612011-10-11 02:20:01 +00008864
8865template<typename Derived>
8866ExprResult
8867TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008868 QualType RetTy = getDerived().TransformType(E->getType());
8869 bool ArgumentChanged = false;
8870 ASTOwningVector<Expr*> SubExprs(SemaRef);
8871 SubExprs.reserve(E->getNumSubExprs());
8872 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8873 SubExprs, &ArgumentChanged))
8874 return ExprError();
8875
8876 if (!getDerived().AlwaysRebuild() &&
8877 !ArgumentChanged)
8878 return SemaRef.Owned(E);
8879
8880 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8881 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008882}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008883
Douglas Gregorb98b1992009-08-11 05:31:07 +00008884//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008885// Type reconstruction
8886//===----------------------------------------------------------------------===//
8887
Mike Stump1eb44332009-09-09 15:08:12 +00008888template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008889QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8890 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008891 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008892 getDerived().getBaseEntity());
8893}
8894
Mike Stump1eb44332009-09-09 15:08:12 +00008895template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008896QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8897 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008898 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008899 getDerived().getBaseEntity());
8900}
8901
Mike Stump1eb44332009-09-09 15:08:12 +00008902template<typename Derived>
8903QualType
John McCall85737a72009-10-30 00:06:24 +00008904TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8905 bool WrittenAsLValue,
8906 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008907 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008908 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008909}
8910
8911template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008912QualType
John McCall85737a72009-10-30 00:06:24 +00008913TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8914 QualType ClassType,
8915 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008916 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008917 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008918}
8919
8920template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008921QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008922TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8923 ArrayType::ArraySizeModifier SizeMod,
8924 const llvm::APInt *Size,
8925 Expr *SizeExpr,
8926 unsigned IndexTypeQuals,
8927 SourceRange BracketsRange) {
8928 if (SizeExpr || !Size)
8929 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8930 IndexTypeQuals, BracketsRange,
8931 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008932
8933 QualType Types[] = {
8934 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8935 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8936 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008937 };
8938 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8939 QualType SizeType;
8940 for (unsigned I = 0; I != NumTypes; ++I)
8941 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8942 SizeType = Types[I];
8943 break;
8944 }
Mike Stump1eb44332009-09-09 15:08:12 +00008945
Eli Friedman01f276d2012-01-25 23:20:27 +00008946 // Note that we can return a VariableArrayType here in the case where
8947 // the element type was a dependent VariableArrayType.
8948 IntegerLiteral *ArraySize
8949 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8950 /*FIXME*/BracketsRange.getBegin());
8951 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008952 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008953 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008954}
Mike Stump1eb44332009-09-09 15:08:12 +00008955
Douglas Gregor577f75a2009-08-04 16:50:30 +00008956template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008957QualType
8958TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008959 ArrayType::ArraySizeModifier SizeMod,
8960 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008961 unsigned IndexTypeQuals,
8962 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008963 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008964 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008965}
8966
8967template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008968QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008969TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008970 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008971 unsigned IndexTypeQuals,
8972 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008973 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008974 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008975}
Mike Stump1eb44332009-09-09 15:08:12 +00008976
Douglas Gregor577f75a2009-08-04 16:50:30 +00008977template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008978QualType
8979TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008980 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008981 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008982 unsigned IndexTypeQuals,
8983 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008984 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008985 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008986 IndexTypeQuals, BracketsRange);
8987}
8988
8989template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008990QualType
8991TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008992 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008993 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008994 unsigned IndexTypeQuals,
8995 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008996 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008997 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008998 IndexTypeQuals, BracketsRange);
8999}
9000
9001template<typename Derived>
9002QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009003 unsigned NumElements,
9004 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009005 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009006 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009007}
Mike Stump1eb44332009-09-09 15:08:12 +00009008
Douglas Gregor577f75a2009-08-04 16:50:30 +00009009template<typename Derived>
9010QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9011 unsigned NumElements,
9012 SourceLocation AttributeLoc) {
9013 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9014 NumElements, true);
9015 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009016 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9017 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009018 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009019}
Mike Stump1eb44332009-09-09 15:08:12 +00009020
Douglas Gregor577f75a2009-08-04 16:50:30 +00009021template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009022QualType
9023TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009024 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009025 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009026 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009027}
Mike Stump1eb44332009-09-09 15:08:12 +00009028
Douglas Gregor577f75a2009-08-04 16:50:30 +00009029template<typename Derived>
9030QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00009031 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009032 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00009033 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009034 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00009035 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00009036 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00009037 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00009038 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009039 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009040 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009041 getDerived().getBaseEntity(),
9042 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009043}
Mike Stump1eb44332009-09-09 15:08:12 +00009044
Douglas Gregor577f75a2009-08-04 16:50:30 +00009045template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009046QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9047 return SemaRef.Context.getFunctionNoProtoType(T);
9048}
9049
9050template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009051QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9052 assert(D && "no decl found");
9053 if (D->isInvalidDecl()) return QualType();
9054
Douglas Gregor92e986e2010-04-22 16:44:27 +00009055 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009056 TypeDecl *Ty;
9057 if (isa<UsingDecl>(D)) {
9058 UsingDecl *Using = cast<UsingDecl>(D);
9059 assert(Using->isTypeName() &&
9060 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9061
9062 // A valid resolved using typename decl points to exactly one type decl.
9063 assert(++Using->shadow_begin() == Using->shadow_end());
9064 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00009065
John McCalled976492009-12-04 22:46:56 +00009066 } else {
9067 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9068 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9069 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9070 }
9071
9072 return SemaRef.Context.getTypeDeclType(Ty);
9073}
9074
9075template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009076QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9077 SourceLocation Loc) {
9078 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009079}
9080
9081template<typename Derived>
9082QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9083 return SemaRef.Context.getTypeOfType(Underlying);
9084}
9085
9086template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009087QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9088 SourceLocation Loc) {
9089 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009090}
9091
9092template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009093QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9094 UnaryTransformType::UTTKind UKind,
9095 SourceLocation Loc) {
9096 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9097}
9098
9099template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009100QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009101 TemplateName Template,
9102 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009103 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009104 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009105}
Mike Stump1eb44332009-09-09 15:08:12 +00009106
Douglas Gregordcee1a12009-08-06 05:28:30 +00009107template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009108QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9109 SourceLocation KWLoc) {
9110 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9111}
9112
9113template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009114TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009115TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009116 bool TemplateKW,
9117 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009118 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009119 Template);
9120}
9121
9122template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009123TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009124TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9125 const IdentifierInfo &Name,
9126 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009127 QualType ObjectType,
9128 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009129 UnqualifiedId TemplateName;
9130 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009131 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009132 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009133 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009134 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009135 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009136 /*EnteringContext=*/false,
9137 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009138 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009139}
Mike Stump1eb44332009-09-09 15:08:12 +00009140
Douglas Gregorb98b1992009-08-11 05:31:07 +00009141template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009142TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009143TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009144 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009145 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009146 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009147 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009148 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009149 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009150 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009151 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009152 Sema::TemplateTy Template;
9153 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009154 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009155 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009156 /*EnteringContext=*/false,
9157 Template);
9158 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009159}
Sean Huntc3021132010-05-05 15:23:54 +00009160
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009161template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009162ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009163TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9164 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009165 Expr *OrigCallee,
9166 Expr *First,
9167 Expr *Second) {
9168 Expr *Callee = OrigCallee->IgnoreParenCasts();
9169 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009170
Douglas Gregorb98b1992009-08-11 05:31:07 +00009171 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009172 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009173 if (!First->getType()->isOverloadableType() &&
9174 !Second->getType()->isOverloadableType())
9175 return getSema().CreateBuiltinArraySubscriptExpr(First,
9176 Callee->getLocStart(),
9177 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009178 } else if (Op == OO_Arrow) {
9179 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009180 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9181 } else if (Second == 0 || isPostIncDec) {
9182 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009183 // The argument is not of overloadable type, so try to create a
9184 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009185 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009186 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009187
John McCall9ae2f072010-08-23 23:25:46 +00009188 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009189 }
9190 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009191 if (!First->getType()->isOverloadableType() &&
9192 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009193 // Neither of the arguments is an overloadable type, so try to
9194 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009195 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009196 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009197 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009198 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009199 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009200
Douglas Gregorb98b1992009-08-11 05:31:07 +00009201 return move(Result);
9202 }
9203 }
Mike Stump1eb44332009-09-09 15:08:12 +00009204
9205 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009206 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009207 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009208
John McCall9ae2f072010-08-23 23:25:46 +00009209 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009210 assert(ULE->requiresADL());
9211
9212 // FIXME: Do we have to check
9213 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009214 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009215 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009216 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00009217 }
Mike Stump1eb44332009-09-09 15:08:12 +00009218
Douglas Gregorb98b1992009-08-11 05:31:07 +00009219 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009220 Expr *Args[2] = { First, Second };
9221 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009222
Douglas Gregorb98b1992009-08-11 05:31:07 +00009223 // Create the overloaded operator invocation for unary operators.
9224 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009225 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009226 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009227 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009228 }
Mike Stump1eb44332009-09-09 15:08:12 +00009229
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009230 if (Op == OO_Subscript) {
9231 SourceLocation LBrace;
9232 SourceLocation RBrace;
9233
9234 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9235 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9236 LBrace = SourceLocation::getFromRawEncoding(
9237 NameLoc.CXXOperatorName.BeginOpNameLoc);
9238 RBrace = SourceLocation::getFromRawEncoding(
9239 NameLoc.CXXOperatorName.EndOpNameLoc);
9240 } else {
9241 LBrace = Callee->getLocStart();
9242 RBrace = OpLoc;
9243 }
9244
9245 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9246 First, Second);
9247 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009248
Douglas Gregorb98b1992009-08-11 05:31:07 +00009249 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009250 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009251 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009252 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9253 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009254 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009255
Mike Stump1eb44332009-09-09 15:08:12 +00009256 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009257}
Mike Stump1eb44332009-09-09 15:08:12 +00009258
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009259template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009260ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009261TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009262 SourceLocation OperatorLoc,
9263 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009264 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009265 TypeSourceInfo *ScopeType,
9266 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009267 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009268 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009269 QualType BaseType = Base->getType();
9270 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009271 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00009272 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009273 !BaseType->getAs<PointerType>()->getPointeeType()
9274 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009275 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009276 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009277 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009278 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009279 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009280 /*FIXME?*/true);
9281 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009282
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009283 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009284 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9285 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9286 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9287 NameInfo.setNamedTypeInfo(DestroyedType);
9288
Richard Smith6314db92012-05-15 06:15:11 +00009289 // The scope type is now known to be a valid nested name specifier
9290 // component. Tack it on to the end of the nested name specifier.
9291 if (ScopeType)
9292 SS.Extend(SemaRef.Context, SourceLocation(),
9293 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009294
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009295 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009296 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009297 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009298 SS, TemplateKWLoc,
9299 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009300 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009301 /*TemplateArgs*/ 0);
9302}
9303
Douglas Gregor577f75a2009-08-04 16:50:30 +00009304} // end namespace clang
9305
9306#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H