blob: ec02661218f4cb55d3ffdf286cc98e5128c01591 [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 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000227 /// \param ShouldExpand Will be set to \c true if the transformer should
228 /// expand the corresponding pack expansions into separate arguments. When
229 /// set, \c NumExpansions must also be set.
230 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000231 /// \param RetainExpansion Whether the caller should add an unexpanded
232 /// pack expansion after all of the expanded arguments. This is used
233 /// when extending explicitly-specified template argument packs per
234 /// C++0x [temp.arg.explicit]p9.
235 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000236 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000237 /// the expanded form of the corresponding pack expansion. This is both an
238 /// input and an output parameter, which can be set by the caller if the
239 /// number of expansions is known a priori (e.g., due to a prior substitution)
240 /// and will be set by the callee when the number of expansions is known.
241 /// The callee must set this value when \c ShouldExpand is \c true; it may
242 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000243 ///
244 /// \returns true if an error occurred (e.g., because the parameter packs
245 /// are to be instantiated with arguments of different lengths), false
246 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
247 /// must be set.
248 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
249 SourceRange PatternRange,
David Blaikiea71f9d02011-09-22 02:34:54 +0000250 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000251 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000252 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000253 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000254 ShouldExpand = false;
255 return false;
256 }
257
Douglas Gregord3731192011-01-10 07:32:04 +0000258 /// \brief "Forget" about the partially-substituted pack template argument,
259 /// when performing an instantiation that must preserve the parameter pack
260 /// use.
261 ///
262 /// This routine is meant to be overridden by the template instantiator.
263 TemplateArgument ForgetPartiallySubstitutedPack() {
264 return TemplateArgument();
265 }
266
267 /// \brief "Remember" the partially-substituted pack template argument
268 /// after performing an instantiation that must preserve the parameter pack
269 /// use.
270 ///
271 /// This routine is meant to be overridden by the template instantiator.
272 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
273
Douglas Gregor12c9c002011-01-07 16:43:16 +0000274 /// \brief Note to the derived class when a function parameter pack is
275 /// being expanded.
276 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
277
Douglas Gregor577f75a2009-08-04 16:50:30 +0000278 /// \brief Transforms the given type into another type.
279 ///
John McCalla2becad2009-10-21 00:40:46 +0000280 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000281 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000282 /// function. This is expensive, but we don't mind, because
283 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000284 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000285 ///
286 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000287 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000288
John McCalla2becad2009-10-21 00:40:46 +0000289 /// \brief Transforms the given type-with-location into a new
290 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000291 ///
John McCalla2becad2009-10-21 00:40:46 +0000292 /// By default, this routine transforms a type by delegating to the
293 /// appropriate TransformXXXType to build a new type. Subclasses
294 /// may override this function (to take over all type
295 /// transformations) or some set of the TransformXXXType functions
296 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000297 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000298
299 /// \brief Transform the given type-with-location into a new
300 /// type, collecting location information in the given builder
301 /// as necessary.
302 ///
John McCall43fed0d2010-11-12 08:19:04 +0000303 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000304
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000305 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000306 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000307 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000308 /// appropriate TransformXXXStmt function to transform a specific kind of
309 /// statement or the TransformExpr() function to transform an expression.
310 /// Subclasses may override this function to transform statements using some
311 /// other mechanism.
312 ///
313 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000314 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000315
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000316 /// \brief Transform the given expression.
317 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000318 /// By default, this routine transforms an expression by delegating to the
319 /// appropriate TransformXXXExpr function to build a new expression.
320 /// Subclasses may override this function to transform expressions using some
321 /// other mechanism.
322 ///
323 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000324 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000325
Douglas Gregoraa165f82011-01-03 19:04:46 +0000326 /// \brief Transform the given list of expressions.
327 ///
328 /// This routine transforms a list of expressions by invoking
329 /// \c TransformExpr() for each subexpression. However, it also provides
330 /// support for variadic templates by expanding any pack expansions (if the
331 /// derived class permits such expansion) along the way. When pack expansions
332 /// are present, the number of outputs may not equal the number of inputs.
333 ///
334 /// \param Inputs The set of expressions to be transformed.
335 ///
336 /// \param NumInputs The number of expressions in \c Inputs.
337 ///
338 /// \param IsCall If \c true, then this transform is being performed on
339 /// function-call arguments, and any arguments that should be dropped, will
340 /// be.
341 ///
342 /// \param Outputs The transformed input expressions will be added to this
343 /// vector.
344 ///
345 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
346 /// due to transformation.
347 ///
348 /// \returns true if an error occurred, false otherwise.
349 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000350 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000351 bool *ArgChanged = 0);
352
Douglas Gregor577f75a2009-08-04 16:50:30 +0000353 /// \brief Transform the given declaration, which is referenced from a type
354 /// or expression.
355 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000356 /// By default, acts as the identity function on declarations, unless the
357 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000358 /// may override this function to provide alternate behavior.
Douglas Gregordfca6f52012-02-13 22:00:16 +0000359 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
360 llvm::DenseMap<Decl *, Decl *>::iterator Known
361 = TransformedLocalDecls.find(D);
362 if (Known != TransformedLocalDecls.end())
363 return Known->second;
364
365 return D;
366 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000367
Douglas Gregordfca6f52012-02-13 22:00:16 +0000368 /// \brief Transform the attributes associated with the given declaration and
369 /// place them on the new declaration.
370 ///
371 /// By default, this operation does nothing. Subclasses may override this
372 /// behavior to transform attributes.
373 void transformAttrs(Decl *Old, Decl *New) { }
374
375 /// \brief Note that a local declaration has been transformed by this
376 /// transformer.
377 ///
378 /// Local declarations are typically transformed via a call to
379 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
380 /// the transformer itself has to transform the declarations. This routine
381 /// can be overridden by a subclass that keeps track of such mappings.
382 void transformedLocalDecl(Decl *Old, Decl *New) {
383 TransformedLocalDecls[Old] = New;
384 }
385
Douglas Gregor43959a92009-08-20 07:17:43 +0000386 /// \brief Transform the definition of the given declaration.
387 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000388 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000389 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000390 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
391 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000392 }
Mike Stump1eb44332009-09-09 15:08:12 +0000393
Douglas Gregor6cd21982009-10-20 05:58:46 +0000394 /// \brief Transform the given declaration, which was the first part of a
395 /// nested-name-specifier in a member access expression.
396 ///
Sean Huntc3021132010-05-05 15:23:54 +0000397 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000398 /// identifier in a nested-name-specifier of a member access expression, e.g.,
399 /// the \c T in \c x->T::member
400 ///
401 /// By default, invokes TransformDecl() to transform the declaration.
402 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000403 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
404 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000405 }
Sean Huntc3021132010-05-05 15:23:54 +0000406
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000407 /// \brief Transform the given nested-name-specifier with source-location
408 /// information.
409 ///
410 /// By default, transforms all of the types and declarations within the
411 /// nested-name-specifier. Subclasses may override this function to provide
412 /// alternate behavior.
413 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
414 NestedNameSpecifierLoc NNS,
415 QualType ObjectType = QualType(),
416 NamedDecl *FirstQualifierInScope = 0);
417
Douglas Gregor81499bb2009-09-03 22:13:48 +0000418 /// \brief Transform the given declaration name.
419 ///
420 /// By default, transforms the types of conversion function, constructor,
421 /// and destructor names and then (if needed) rebuilds the declaration name.
422 /// Identifiers and selectors are returned unmodified. Sublcasses may
423 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000424 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000425 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000426
Douglas Gregor577f75a2009-08-04 16:50:30 +0000427 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000428 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000429 /// \param SS The nested-name-specifier that qualifies the template
430 /// name. This nested-name-specifier must already have been transformed.
431 ///
432 /// \param Name The template name to transform.
433 ///
434 /// \param NameLoc The source location of the template name.
435 ///
436 /// \param ObjectType If we're translating a template name within a member
437 /// access expression, this is the type of the object whose member template
438 /// is being referenced.
439 ///
440 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
441 /// also refers to a name within the current (lexical) scope, this is the
442 /// declaration it refers to.
443 ///
444 /// By default, transforms the template name by transforming the declarations
445 /// and nested-name-specifiers that occur within the template name.
446 /// Subclasses may override this function to provide alternate behavior.
447 TemplateName TransformTemplateName(CXXScopeSpec &SS,
448 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000449 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000450 QualType ObjectType = QualType(),
451 NamedDecl *FirstQualifierInScope = 0);
452
Douglas Gregor577f75a2009-08-04 16:50:30 +0000453 /// \brief Transform the given template argument.
454 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000455 /// By default, this operation transforms the type, expression, or
456 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000457 /// new template argument from the transformed result. Subclasses may
458 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000459 ///
460 /// Returns true if there was an error.
461 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
462 TemplateArgumentLoc &Output);
463
Douglas Gregorfcc12532010-12-20 17:31:10 +0000464 /// \brief Transform the given set of template arguments.
465 ///
466 /// By default, this operation transforms all of the template arguments
467 /// in the input set using \c TransformTemplateArgument(), and appends
468 /// the transformed arguments to the output list.
469 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000470 /// Note that this overload of \c TransformTemplateArguments() is merely
471 /// a convenience function. Subclasses that wish to override this behavior
472 /// should override the iterator-based member template version.
473 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000474 /// \param Inputs The set of template arguments to be transformed.
475 ///
476 /// \param NumInputs The number of template arguments in \p Inputs.
477 ///
478 /// \param Outputs The set of transformed template arguments output by this
479 /// routine.
480 ///
481 /// Returns true if an error occurred.
482 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
483 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000484 TemplateArgumentListInfo &Outputs) {
485 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
486 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000487
488 /// \brief Transform the given set of template arguments.
489 ///
490 /// By default, this operation transforms all of the template arguments
491 /// in the input set using \c TransformTemplateArgument(), and appends
492 /// the transformed arguments to the output list.
493 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000494 /// \param First An iterator to the first template argument.
495 ///
496 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000497 ///
498 /// \param Outputs The set of transformed template arguments output by this
499 /// routine.
500 ///
501 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000502 template<typename InputIterator>
503 bool TransformTemplateArguments(InputIterator First,
504 InputIterator Last,
505 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000506
John McCall833ca992009-10-29 08:12:44 +0000507 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
508 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
509 TemplateArgumentLoc &ArgLoc);
510
John McCalla93c9342009-12-07 02:54:59 +0000511 /// \brief Fakes up a TypeSourceInfo for a type.
512 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
513 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000514 getDerived().getBaseLocation());
515 }
Mike Stump1eb44332009-09-09 15:08:12 +0000516
John McCalla2becad2009-10-21 00:40:46 +0000517#define ABSTRACT_TYPELOC(CLASS, PARENT)
518#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000519 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000520#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000521
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000522 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
523 FunctionProtoTypeLoc TL,
524 CXXRecordDecl *ThisContext,
525 unsigned ThisTypeQuals);
526
John Wiegley28bbe4b2011-04-28 01:08:34 +0000527 StmtResult
528 TransformSEHHandler(Stmt *Handler);
529
John McCall43fed0d2010-11-12 08:19:04 +0000530 QualType
531 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
532 TemplateSpecializationTypeLoc TL,
533 TemplateName Template);
534
535 QualType
536 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
537 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000538 TemplateName Template,
539 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000540
541 QualType
542 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000543 DependentTemplateSpecializationTypeLoc TL,
544 NestedNameSpecifierLoc QualifierLoc);
545
John McCall21ef0fa2010-03-11 09:03:00 +0000546 /// \brief Transforms the parameters of a function type into the
547 /// given vectors.
548 ///
549 /// The result vectors should be kept in sync; null entries in the
550 /// variables vector are acceptable.
551 ///
552 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000553 bool TransformFunctionTypeParams(SourceLocation Loc,
554 ParmVarDecl **Params, unsigned NumParams,
555 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000556 SmallVectorImpl<QualType> &PTypes,
557 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000558
559 /// \brief Transforms a single function-type parameter. Return null
560 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000561 ///
562 /// \param indexAdjustment - A number to add to the parameter's
563 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000564 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000565 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000566 llvm::Optional<unsigned> NumExpansions,
567 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000568
John McCall43fed0d2010-11-12 08:19:04 +0000569 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000570
John McCall60d7b3a2010-08-24 06:29:42 +0000571 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
572 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000573
Douglas Gregor43959a92009-08-20 07:17:43 +0000574#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000575 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000576#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000577 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000578#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000579#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000580
Douglas Gregor577f75a2009-08-04 16:50:30 +0000581 /// \brief Build a new pointer type given its pointee type.
582 ///
583 /// By default, performs semantic analysis when building the pointer type.
584 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000585 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000586
587 /// \brief Build a new block pointer type given its pointee type.
588 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000589 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000590 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000591 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000592
John McCall85737a72009-10-30 00:06:24 +0000593 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000594 ///
John McCall85737a72009-10-30 00:06:24 +0000595 /// By default, performs semantic analysis when building the
596 /// reference type. Subclasses may override this routine to provide
597 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000598 ///
John McCall85737a72009-10-30 00:06:24 +0000599 /// \param LValue whether the type was written with an lvalue sigil
600 /// or an rvalue sigil.
601 QualType RebuildReferenceType(QualType ReferentType,
602 bool LValue,
603 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000604
Douglas Gregor577f75a2009-08-04 16:50:30 +0000605 /// \brief Build a new member pointer type given the pointee type and the
606 /// class type it refers into.
607 ///
608 /// By default, performs semantic analysis when building the member pointer
609 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000610 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
611 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000612
Douglas Gregor577f75a2009-08-04 16:50:30 +0000613 /// \brief Build a new array type given the element type, size
614 /// modifier, size of the array (if known), size expression, and index type
615 /// qualifiers.
616 ///
617 /// By default, performs semantic analysis when building the array type.
618 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000619 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000620 QualType RebuildArrayType(QualType ElementType,
621 ArrayType::ArraySizeModifier SizeMod,
622 const llvm::APInt *Size,
623 Expr *SizeExpr,
624 unsigned IndexTypeQuals,
625 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000626
Douglas Gregor577f75a2009-08-04 16:50:30 +0000627 /// \brief Build a new constant array type given the element type, size
628 /// modifier, (known) size of the array, and index type qualifiers.
629 ///
630 /// By default, performs semantic analysis when building the array type.
631 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000632 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000633 ArrayType::ArraySizeModifier SizeMod,
634 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000635 unsigned IndexTypeQuals,
636 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000637
Douglas Gregor577f75a2009-08-04 16:50:30 +0000638 /// \brief Build a new incomplete array type given the element type, size
639 /// modifier, and index type qualifiers.
640 ///
641 /// By default, performs semantic analysis when building the array type.
642 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000643 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000644 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000645 unsigned IndexTypeQuals,
646 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000647
Mike Stump1eb44332009-09-09 15:08:12 +0000648 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000649 /// size modifier, size expression, and index type qualifiers.
650 ///
651 /// By default, performs semantic analysis when building the array type.
652 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000653 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000654 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000655 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000656 unsigned IndexTypeQuals,
657 SourceRange BracketsRange);
658
Mike Stump1eb44332009-09-09 15:08:12 +0000659 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000660 /// size modifier, size expression, and index type qualifiers.
661 ///
662 /// By default, performs semantic analysis when building the array type.
663 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000664 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000665 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000666 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000667 unsigned IndexTypeQuals,
668 SourceRange BracketsRange);
669
670 /// \brief Build a new vector type given the element type and
671 /// number of elements.
672 ///
673 /// By default, performs semantic analysis when building the vector type.
674 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000675 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000676 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000677
Douglas Gregor577f75a2009-08-04 16:50:30 +0000678 /// \brief Build a new extended vector type given the element type and
679 /// number of elements.
680 ///
681 /// By default, performs semantic analysis when building the vector type.
682 /// Subclasses may override this routine to provide different behavior.
683 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
684 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000685
686 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000687 /// given the element type and number of elements.
688 ///
689 /// By default, performs semantic analysis when building the vector type.
690 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000691 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000692 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000693 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000694
Douglas Gregor577f75a2009-08-04 16:50:30 +0000695 /// \brief Build a new function type.
696 ///
697 /// By default, performs semantic analysis when building the function type.
698 /// Subclasses may override this routine to provide different behavior.
699 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000700 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000701 unsigned NumParamTypes,
Richard Smitheefb3d52012-02-10 09:58:53 +0000702 bool Variadic, bool HasTrailingReturn,
703 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000704 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000705 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000706
John McCalla2becad2009-10-21 00:40:46 +0000707 /// \brief Build a new unprototyped function type.
708 QualType RebuildFunctionNoProtoType(QualType ResultType);
709
John McCalled976492009-12-04 22:46:56 +0000710 /// \brief Rebuild an unresolved typename type, given the decl that
711 /// the UnresolvedUsingTypenameDecl was transformed to.
712 QualType RebuildUnresolvedUsingType(Decl *D);
713
Douglas Gregor577f75a2009-08-04 16:50:30 +0000714 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000715 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000716 return SemaRef.Context.getTypeDeclType(Typedef);
717 }
718
719 /// \brief Build a new class/struct/union type.
720 QualType RebuildRecordType(RecordDecl *Record) {
721 return SemaRef.Context.getTypeDeclType(Record);
722 }
723
724 /// \brief Build a new Enum type.
725 QualType RebuildEnumType(EnumDecl *Enum) {
726 return SemaRef.Context.getTypeDeclType(Enum);
727 }
John McCall7da24312009-09-05 00:15:47 +0000728
Mike Stump1eb44332009-09-09 15:08:12 +0000729 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000730 ///
731 /// By default, performs semantic analysis when building the typeof type.
732 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000733 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000734
Mike Stump1eb44332009-09-09 15:08:12 +0000735 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000736 ///
737 /// By default, builds a new TypeOfType with the given underlying type.
738 QualType RebuildTypeOfType(QualType Underlying);
739
Sean Huntca63c202011-05-24 22:41:36 +0000740 /// \brief Build a new unary transform type.
741 QualType RebuildUnaryTransformType(QualType BaseType,
742 UnaryTransformType::UTTKind UKind,
743 SourceLocation Loc);
744
Mike Stump1eb44332009-09-09 15:08:12 +0000745 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000746 ///
747 /// By default, performs semantic analysis when building the decltype type.
748 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000749 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000750
Richard Smith34b41d92011-02-20 03:19:35 +0000751 /// \brief Build a new C++0x auto type.
752 ///
753 /// By default, builds a new AutoType with the given deduced type.
754 QualType RebuildAutoType(QualType Deduced) {
755 return SemaRef.Context.getAutoType(Deduced);
756 }
757
Douglas Gregor577f75a2009-08-04 16:50:30 +0000758 /// \brief Build a new template specialization type.
759 ///
760 /// By default, performs semantic analysis when building the template
761 /// specialization type. Subclasses may override this routine to provide
762 /// different behavior.
763 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000764 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000765 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000766
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000767 /// \brief Build a new parenthesized type.
768 ///
769 /// By default, builds a new ParenType type from the inner type.
770 /// Subclasses may override this routine to provide different behavior.
771 QualType RebuildParenType(QualType InnerType) {
772 return SemaRef.Context.getParenType(InnerType);
773 }
774
Douglas Gregor577f75a2009-08-04 16:50:30 +0000775 /// \brief Build a new qualified name type.
776 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000777 /// By default, builds a new ElaboratedType type from the keyword,
778 /// the nested-name-specifier and the named type.
779 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000780 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
781 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000782 NestedNameSpecifierLoc QualifierLoc,
783 QualType Named) {
784 return SemaRef.Context.getElaboratedType(Keyword,
785 QualifierLoc.getNestedNameSpecifier(),
786 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000787 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000788
789 /// \brief Build a new typename type that refers to a template-id.
790 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000791 /// By default, builds a new DependentNameType type from the
792 /// nested-name-specifier and the given type. Subclasses may override
793 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000794 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000795 ElaboratedTypeKeyword Keyword,
796 NestedNameSpecifierLoc QualifierLoc,
797 const IdentifierInfo *Name,
798 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000799 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000800 // Rebuild the template name.
801 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000802 CXXScopeSpec SS;
803 SS.Adopt(QualifierLoc);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000804 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000805 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000806
807 if (InstName.isNull())
808 return QualType();
809
810 // If it's still dependent, make a dependent specialization.
811 if (InstName.getAsDependentTemplateName())
812 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
813 QualifierLoc.getNestedNameSpecifier(),
814 Name,
815 Args);
816
817 // Otherwise, make an elaborated type wrapping a non-dependent
818 // specialization.
819 QualType T =
820 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
821 if (T.isNull()) return QualType();
822
823 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
824 return T;
825
826 return SemaRef.Context.getElaboratedType(Keyword,
827 QualifierLoc.getNestedNameSpecifier(),
828 T);
829 }
830
Douglas Gregor577f75a2009-08-04 16:50:30 +0000831 /// \brief Build a new typename type that refers to an identifier.
832 ///
833 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000834 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000835 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000836 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000837 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000838 NestedNameSpecifierLoc QualifierLoc,
839 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000840 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000841 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000842 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000843
Douglas Gregor2494dd02011-03-01 01:34:45 +0000844 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000845 // If the name is still dependent, just build a new dependent name type.
846 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor2494dd02011-03-01 01:34:45 +0000847 return SemaRef.Context.getDependentNameType(Keyword,
848 QualifierLoc.getNestedNameSpecifier(),
849 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000850 }
851
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000852 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000853 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000854 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000855
856 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
857
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000858 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000859 // into a non-dependent elaborated-type-specifier. Find the tag we're
860 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000861 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000862 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
863 if (!DC)
864 return QualType();
865
John McCall56138762010-05-27 06:40:31 +0000866 if (SemaRef.RequireCompleteDeclContext(SS, DC))
867 return QualType();
868
Douglas Gregor40336422010-03-31 22:19:08 +0000869 TagDecl *Tag = 0;
870 SemaRef.LookupQualifiedName(Result, DC);
871 switch (Result.getResultKind()) {
872 case LookupResult::NotFound:
873 case LookupResult::NotFoundInCurrentInstantiation:
874 break;
Sean Huntc3021132010-05-05 15:23:54 +0000875
Douglas Gregor40336422010-03-31 22:19:08 +0000876 case LookupResult::Found:
877 Tag = Result.getAsSingle<TagDecl>();
878 break;
Sean Huntc3021132010-05-05 15:23:54 +0000879
Douglas Gregor40336422010-03-31 22:19:08 +0000880 case LookupResult::FoundOverloaded:
881 case LookupResult::FoundUnresolvedValue:
882 llvm_unreachable("Tag lookup cannot find non-tags");
Sean Huntc3021132010-05-05 15:23:54 +0000883
Douglas Gregor40336422010-03-31 22:19:08 +0000884 case LookupResult::Ambiguous:
885 // Let the LookupResult structure handle ambiguities.
886 return QualType();
887 }
888
889 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000890 // Check where the name exists but isn't a tag type and use that to emit
891 // better diagnostics.
892 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
893 SemaRef.LookupQualifiedName(Result, DC);
894 switch (Result.getResultKind()) {
895 case LookupResult::Found:
896 case LookupResult::FoundOverloaded:
897 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000898 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000899 unsigned Kind = 0;
900 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000901 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
902 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000903 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
904 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
905 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000906 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000907 default:
908 // FIXME: Would be nice to highlight just the source range.
909 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
910 << Kind << Id << DC;
911 break;
912 }
Douglas Gregor40336422010-03-31 22:19:08 +0000913 return QualType();
914 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000915
Richard Trieubbf34c02011-06-10 03:11:26 +0000916 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
917 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000918 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000919 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
920 return QualType();
921 }
922
923 // Build the elaborated-type-specifier type.
924 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor2494dd02011-03-01 01:34:45 +0000925 return SemaRef.Context.getElaboratedType(Keyword,
926 QualifierLoc.getNestedNameSpecifier(),
927 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000928 }
Mike Stump1eb44332009-09-09 15:08:12 +0000929
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000930 /// \brief Build a new pack expansion type.
931 ///
932 /// By default, builds a new PackExpansionType type from the given pattern.
933 /// Subclasses may override this routine to provide different behavior.
934 QualType RebuildPackExpansionType(QualType Pattern,
935 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000936 SourceLocation EllipsisLoc,
937 llvm::Optional<unsigned> NumExpansions) {
938 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
939 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000940 }
941
Eli Friedmanb001de72011-10-06 23:00:33 +0000942 /// \brief Build a new atomic type given its value type.
943 ///
944 /// By default, performs semantic analysis when building the atomic type.
945 /// Subclasses may override this routine to provide different behavior.
946 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
947
Douglas Gregord1067e52009-08-06 06:41:21 +0000948 /// \brief Build a new template name given a nested name specifier, a flag
949 /// indicating whether the "template" keyword was provided, and the template
950 /// that the template name refers to.
951 ///
952 /// By default, builds the new template name directly. Subclasses may override
953 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000954 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000955 bool TemplateKW,
956 TemplateDecl *Template);
957
Douglas Gregord1067e52009-08-06 06:41:21 +0000958 /// \brief Build a new template name given a nested name specifier and the
959 /// name that is referred to as a template.
960 ///
961 /// By default, performs semantic analysis to determine whether the name can
962 /// be resolved to a specific template, then builds the appropriate kind of
963 /// template name. Subclasses may override this routine to provide different
964 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000965 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
966 const IdentifierInfo &Name,
967 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000968 QualType ObjectType,
969 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000970
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000971 /// \brief Build a new template name given a nested name specifier and the
972 /// overloaded operator name that is referred to as a template.
973 ///
974 /// By default, performs semantic analysis to determine whether the name can
975 /// be resolved to a specific template, then builds the appropriate kind of
976 /// template name. Subclasses may override this routine to provide different
977 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000978 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000979 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000980 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000981 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000982
983 /// \brief Build a new template name given a template template parameter pack
984 /// and the
985 ///
986 /// By default, performs semantic analysis to determine whether the name can
987 /// be resolved to a specific template, then builds the appropriate kind of
988 /// template name. Subclasses may override this routine to provide different
989 /// behavior.
990 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
991 const TemplateArgument &ArgPack) {
992 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
993 }
994
Douglas Gregor43959a92009-08-20 07:17:43 +0000995 /// \brief Build a new compound statement.
996 ///
997 /// By default, performs semantic analysis to build the new statement.
998 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000999 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001000 MultiStmtArg Statements,
1001 SourceLocation RBraceLoc,
1002 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001003 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001004 IsStmtExpr);
1005 }
1006
1007 /// \brief Build a new case statement.
1008 ///
1009 /// By default, performs semantic analysis to build the new statement.
1010 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001011 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001012 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001013 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001014 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001015 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001016 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001017 ColonLoc);
1018 }
Mike Stump1eb44332009-09-09 15:08:12 +00001019
Douglas Gregor43959a92009-08-20 07:17:43 +00001020 /// \brief Attach the body to a new case statement.
1021 ///
1022 /// By default, performs semantic analysis to build the new statement.
1023 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001024 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001025 getSema().ActOnCaseStmtBody(S, Body);
1026 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001027 }
Mike Stump1eb44332009-09-09 15:08:12 +00001028
Douglas Gregor43959a92009-08-20 07:17:43 +00001029 /// \brief Build a new default statement.
1030 ///
1031 /// By default, performs semantic analysis to build the new statement.
1032 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001033 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001034 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001035 Stmt *SubStmt) {
1036 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001037 /*CurScope=*/0);
1038 }
Mike Stump1eb44332009-09-09 15:08:12 +00001039
Douglas Gregor43959a92009-08-20 07:17:43 +00001040 /// \brief Build a new label statement.
1041 ///
1042 /// By default, performs semantic analysis to build the new statement.
1043 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001044 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1045 SourceLocation ColonLoc, Stmt *SubStmt) {
1046 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001047 }
Mike Stump1eb44332009-09-09 15:08:12 +00001048
Richard Smith534986f2012-04-14 00:33:13 +00001049 /// \brief Build a new label statement.
1050 ///
1051 /// By default, performs semantic analysis to build the new statement.
1052 /// Subclasses may override this routine to provide different behavior.
1053 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, const AttrVec &Attrs,
1054 Stmt *SubStmt) {
1055 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1056 }
1057
Douglas Gregor43959a92009-08-20 07:17:43 +00001058 /// \brief Build a new "if" statement.
1059 ///
1060 /// By default, performs semantic analysis to build the new statement.
1061 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001062 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001063 VarDecl *CondVar, Stmt *Then,
1064 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001065 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001066 }
Mike Stump1eb44332009-09-09 15:08:12 +00001067
Douglas Gregor43959a92009-08-20 07:17:43 +00001068 /// \brief Start building a new switch statement.
1069 ///
1070 /// By default, performs semantic analysis to build the new statement.
1071 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001072 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001073 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001074 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001075 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001076 }
Mike Stump1eb44332009-09-09 15:08:12 +00001077
Douglas Gregor43959a92009-08-20 07:17:43 +00001078 /// \brief Attach the body to the switch statement.
1079 ///
1080 /// By default, performs semantic analysis to build the new statement.
1081 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001082 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001083 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001084 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001085 }
1086
1087 /// \brief Build a new while statement.
1088 ///
1089 /// By default, performs semantic analysis to build the new statement.
1090 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001091 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1092 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001093 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001094 }
Mike Stump1eb44332009-09-09 15:08:12 +00001095
Douglas Gregor43959a92009-08-20 07:17:43 +00001096 /// \brief Build a new do-while statement.
1097 ///
1098 /// By default, performs semantic analysis to build the new statement.
1099 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001100 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001101 SourceLocation WhileLoc, SourceLocation LParenLoc,
1102 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001103 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1104 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001105 }
1106
1107 /// \brief Build a new for statement.
1108 ///
1109 /// By default, performs semantic analysis to build the new statement.
1110 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001111 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1112 Stmt *Init, Sema::FullExprArg Cond,
1113 VarDecl *CondVar, Sema::FullExprArg Inc,
1114 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001115 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001116 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001117 }
Mike Stump1eb44332009-09-09 15:08:12 +00001118
Douglas Gregor43959a92009-08-20 07:17:43 +00001119 /// \brief Build a new goto statement.
1120 ///
1121 /// By default, performs semantic analysis to build the new statement.
1122 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001123 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1124 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001125 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001126 }
1127
1128 /// \brief Build a new indirect goto statement.
1129 ///
1130 /// By default, performs semantic analysis to build the new statement.
1131 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001132 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001133 SourceLocation StarLoc,
1134 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001135 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001136 }
Mike Stump1eb44332009-09-09 15:08:12 +00001137
Douglas Gregor43959a92009-08-20 07:17:43 +00001138 /// \brief Build a new return statement.
1139 ///
1140 /// By default, performs semantic analysis to build the new statement.
1141 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001142 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001143 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001144 }
Mike Stump1eb44332009-09-09 15:08:12 +00001145
Douglas Gregor43959a92009-08-20 07:17:43 +00001146 /// \brief Build a new declaration statement.
1147 ///
1148 /// By default, performs semantic analysis to build the new statement.
1149 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001150 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001151 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001152 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001153 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1154 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001155 }
Mike Stump1eb44332009-09-09 15:08:12 +00001156
Anders Carlsson703e3942010-01-24 05:50:09 +00001157 /// \brief Build a new inline asm statement.
1158 ///
1159 /// By default, performs semantic analysis to build the new statement.
1160 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001161 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001162 bool IsSimple,
1163 bool IsVolatile,
1164 unsigned NumOutputs,
1165 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001166 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001167 MultiExprArg Constraints,
1168 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001169 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001170 MultiExprArg Clobbers,
1171 SourceLocation RParenLoc,
1172 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001173 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001174 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001175 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001176 RParenLoc, MSAsm);
1177 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001178
Chad Rosier8cd64b42012-06-11 20:47:18 +00001179 /// \brief Build a new MS style inline asm statement.
1180 ///
1181 /// By default, performs semantic analysis to build the new statement.
1182 /// Subclasses may override this routine to provide different behavior.
1183 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc,
1184 std::string &AsmString,
1185 SourceLocation EndLoc) {
1186 return getSema().ActOnMSAsmStmt(AsmLoc, AsmString, EndLoc);
1187 }
1188
James Dennett699c9042012-06-15 07:13:21 +00001189 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001190 ///
1191 /// By default, performs semantic analysis to build the new statement.
1192 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001193 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001194 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001195 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001196 Stmt *Finally) {
1197 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1198 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001199 }
1200
Douglas Gregorbe270a02010-04-26 17:57:08 +00001201 /// \brief Rebuild an Objective-C exception declaration.
1202 ///
1203 /// By default, performs semantic analysis to build the new declaration.
1204 /// Subclasses may override this routine to provide different behavior.
1205 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1206 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001207 return getSema().BuildObjCExceptionDecl(TInfo, T,
1208 ExceptionDecl->getInnerLocStart(),
1209 ExceptionDecl->getLocation(),
1210 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001211 }
Sean Huntc3021132010-05-05 15:23:54 +00001212
James Dennett699c9042012-06-15 07:13:21 +00001213 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001214 ///
1215 /// By default, performs semantic analysis to build the new statement.
1216 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001217 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001218 SourceLocation RParenLoc,
1219 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001220 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001221 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001222 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001223 }
Sean Huntc3021132010-05-05 15:23:54 +00001224
James Dennett699c9042012-06-15 07:13:21 +00001225 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001226 ///
1227 /// By default, performs semantic analysis to build the new statement.
1228 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001229 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001230 Stmt *Body) {
1231 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001232 }
Sean Huntc3021132010-05-05 15:23:54 +00001233
James Dennett699c9042012-06-15 07:13:21 +00001234 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001235 ///
1236 /// By default, performs semantic analysis to build the new statement.
1237 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001238 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001239 Expr *Operand) {
1240 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001241 }
Sean Huntc3021132010-05-05 15:23:54 +00001242
James Dennett699c9042012-06-15 07:13:21 +00001243 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001244 ///
1245 /// By default, performs semantic analysis to build the new statement.
1246 /// Subclasses may override this routine to provide different behavior.
1247 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1248 Expr *object) {
1249 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1250 }
1251
James Dennett699c9042012-06-15 07:13:21 +00001252 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001253 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001254 /// By default, performs semantic analysis to build the new statement.
1255 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001256 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001257 Expr *Object, Stmt *Body) {
1258 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001259 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001260
James Dennett699c9042012-06-15 07:13:21 +00001261 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001262 ///
1263 /// By default, performs semantic analysis to build the new statement.
1264 /// Subclasses may override this routine to provide different behavior.
1265 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1266 Stmt *Body) {
1267 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1268 }
John McCall990567c2011-07-27 01:07:15 +00001269
1270 /// \brief Build the collection operand to a new Objective-C fast
1271 /// enumeration statement.
1272 ///
1273 /// By default, performs semantic analysis to build the new statement.
1274 /// Subclasses may override this routine to provide different behavior.
1275 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1276 Expr *collection) {
1277 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1278 }
John McCallf85e1932011-06-15 23:02:42 +00001279
Douglas Gregorc3203e72010-04-22 23:10:45 +00001280 /// \brief Build a new Objective-C fast enumeration statement.
1281 ///
1282 /// By default, performs semantic analysis to build the new statement.
1283 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001284 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001285 SourceLocation LParenLoc,
1286 Stmt *Element,
1287 Expr *Collection,
1288 SourceLocation RParenLoc,
1289 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001290 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001291 Element,
1292 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001293 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001294 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001295 }
Sean Huntc3021132010-05-05 15:23:54 +00001296
Douglas Gregor43959a92009-08-20 07:17:43 +00001297 /// \brief Build a new C++ exception declaration.
1298 ///
1299 /// By default, performs semantic analysis to build the new decaration.
1300 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001301 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001302 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001303 SourceLocation StartLoc,
1304 SourceLocation IdLoc,
1305 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001306 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1307 StartLoc, IdLoc, Id);
1308 if (Var)
1309 getSema().CurContext->addDecl(Var);
1310 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001311 }
1312
1313 /// \brief Build a new C++ catch statement.
1314 ///
1315 /// By default, performs semantic analysis to build the new statement.
1316 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001317 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001318 VarDecl *ExceptionDecl,
1319 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001320 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1321 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001322 }
Mike Stump1eb44332009-09-09 15:08:12 +00001323
Douglas Gregor43959a92009-08-20 07:17:43 +00001324 /// \brief Build a new C++ try statement.
1325 ///
1326 /// By default, performs semantic analysis to build the new statement.
1327 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001328 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001329 Stmt *TryBlock,
1330 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001331 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001332 }
Mike Stump1eb44332009-09-09 15:08:12 +00001333
Richard Smithad762fc2011-04-14 22:09:26 +00001334 /// \brief Build a new C++0x range-based for statement.
1335 ///
1336 /// By default, performs semantic analysis to build the new statement.
1337 /// Subclasses may override this routine to provide different behavior.
1338 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1339 SourceLocation ColonLoc,
1340 Stmt *Range, Stmt *BeginEnd,
1341 Expr *Cond, Expr *Inc,
1342 Stmt *LoopVar,
1343 SourceLocation RParenLoc) {
1344 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1345 Cond, Inc, LoopVar, RParenLoc);
1346 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001347
1348 /// \brief Build a new C++0x range-based for statement.
1349 ///
1350 /// By default, performs semantic analysis to build the new statement.
1351 /// Subclasses may override this routine to provide different behavior.
1352 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1353 bool IsIfExists,
1354 NestedNameSpecifierLoc QualifierLoc,
1355 DeclarationNameInfo NameInfo,
1356 Stmt *Nested) {
1357 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1358 QualifierLoc, NameInfo, Nested);
1359 }
1360
Richard Smithad762fc2011-04-14 22:09:26 +00001361 /// \brief Attach body to a C++0x range-based for statement.
1362 ///
1363 /// By default, performs semantic analysis to finish the new statement.
1364 /// Subclasses may override this routine to provide different behavior.
1365 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1366 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1367 }
1368
John Wiegley28bbe4b2011-04-28 01:08:34 +00001369 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1370 SourceLocation TryLoc,
1371 Stmt *TryBlock,
1372 Stmt *Handler) {
1373 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1374 }
1375
1376 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1377 Expr *FilterExpr,
1378 Stmt *Block) {
1379 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1380 }
1381
1382 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1383 Stmt *Block) {
1384 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1385 }
1386
Douglas Gregorb98b1992009-08-11 05:31:07 +00001387 /// \brief Build a new expression that references a declaration.
1388 ///
1389 /// By default, performs semantic analysis to build the new expression.
1390 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001391 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001392 LookupResult &R,
1393 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001394 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1395 }
1396
1397
1398 /// \brief Build a new expression that references a declaration.
1399 ///
1400 /// By default, performs semantic analysis to build the new expression.
1401 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001402 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001403 ValueDecl *VD,
1404 const DeclarationNameInfo &NameInfo,
1405 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001406 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001407 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001408
1409 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001410
1411 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001412 }
Mike Stump1eb44332009-09-09 15:08:12 +00001413
Douglas Gregorb98b1992009-08-11 05:31:07 +00001414 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001415 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001416 /// By default, performs semantic analysis to build the new expression.
1417 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001418 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001419 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001420 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001421 }
1422
Douglas Gregora71d8192009-09-04 17:36:40 +00001423 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001424 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001425 /// By default, performs semantic analysis to build the new expression.
1426 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001427 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001428 SourceLocation OperatorLoc,
1429 bool isArrow,
1430 CXXScopeSpec &SS,
1431 TypeSourceInfo *ScopeType,
1432 SourceLocation CCLoc,
1433 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001434 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001435
Douglas Gregorb98b1992009-08-11 05:31:07 +00001436 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001437 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001438 /// By default, performs semantic analysis to build the new expression.
1439 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001440 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001441 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001442 Expr *SubExpr) {
1443 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001444 }
Mike Stump1eb44332009-09-09 15:08:12 +00001445
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001446 /// \brief Build a new builtin offsetof expression.
1447 ///
1448 /// By default, performs semantic analysis to build the new expression.
1449 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001450 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001451 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001452 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001453 unsigned NumComponents,
1454 SourceLocation RParenLoc) {
1455 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1456 NumComponents, RParenLoc);
1457 }
Sean Huntc3021132010-05-05 15:23:54 +00001458
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001459 /// \brief Build a new sizeof, alignof or vec_step expression with a
1460 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001461 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001462 /// By default, performs semantic analysis to build the new expression.
1463 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001464 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1465 SourceLocation OpLoc,
1466 UnaryExprOrTypeTrait ExprKind,
1467 SourceRange R) {
1468 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001469 }
1470
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001471 /// \brief Build a new sizeof, alignof or vec step expression with an
1472 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001473 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001474 /// By default, performs semantic analysis to build the new expression.
1475 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001476 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1477 UnaryExprOrTypeTrait ExprKind,
1478 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001479 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001480 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001481 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001482 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001483
Douglas Gregorb98b1992009-08-11 05:31:07 +00001484 return move(Result);
1485 }
Mike Stump1eb44332009-09-09 15:08:12 +00001486
Douglas Gregorb98b1992009-08-11 05:31:07 +00001487 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001488 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001489 /// By default, performs semantic analysis to build the new expression.
1490 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001491 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001492 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001493 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001494 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001495 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1496 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001497 RBracketLoc);
1498 }
1499
1500 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001501 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001502 /// By default, performs semantic analysis to build the new expression.
1503 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001504 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001505 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001506 SourceLocation RParenLoc,
1507 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001508 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001509 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001510 }
1511
1512 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001513 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001514 /// By default, performs semantic analysis to build the new expression.
1515 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001516 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001517 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001518 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001519 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001520 const DeclarationNameInfo &MemberNameInfo,
1521 ValueDecl *Member,
1522 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001523 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001524 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001525 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1526 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001527 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001528 // We have a reference to an unnamed field. This is always the
1529 // base of an anonymous struct/union member access, i.e. the
1530 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001531 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001532 assert(Member->getType()->isRecordType() &&
1533 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001534
Richard Smith9138b4e2011-10-26 19:06:56 +00001535 BaseResult =
1536 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001537 QualifierLoc.getNestedNameSpecifier(),
1538 FoundDecl, Member);
1539 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001540 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001541 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001542 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001543 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001544 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001545 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001546 cast<FieldDecl>(Member)->getType(),
1547 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001548 return getSema().Owned(ME);
1549 }
Mike Stump1eb44332009-09-09 15:08:12 +00001550
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001551 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001552 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001553
John Wiegley429bb272011-04-08 18:41:53 +00001554 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001555 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001556
John McCall6bb80172010-03-30 21:47:33 +00001557 // FIXME: this involves duplicating earlier analysis in a lot of
1558 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001559 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001560 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001561 R.resolveKind();
1562
John McCall9ae2f072010-08-23 23:25:46 +00001563 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001564 SS, TemplateKWLoc,
1565 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001566 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 }
Mike Stump1eb44332009-09-09 15:08:12 +00001568
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001570 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001571 /// By default, performs semantic analysis to build the new expression.
1572 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001573 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001574 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001575 Expr *LHS, Expr *RHS) {
1576 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001577 }
1578
1579 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001580 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001581 /// By default, performs semantic analysis to build the new expression.
1582 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001583 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001584 SourceLocation QuestionLoc,
1585 Expr *LHS,
1586 SourceLocation ColonLoc,
1587 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001588 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1589 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 }
1591
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001593 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 /// By default, performs semantic analysis to build the new expression.
1595 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001596 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001597 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001598 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001599 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001600 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001601 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 }
Mike Stump1eb44332009-09-09 15:08:12 +00001603
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001605 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001606 /// By default, performs semantic analysis to build the new expression.
1607 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001608 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001609 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001610 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001611 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001612 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001613 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 }
Mike Stump1eb44332009-09-09 15:08:12 +00001615
Douglas Gregorb98b1992009-08-11 05:31:07 +00001616 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001617 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001618 /// By default, performs semantic analysis to build the new expression.
1619 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001620 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001621 SourceLocation OpLoc,
1622 SourceLocation AccessorLoc,
1623 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001624
John McCall129e2df2009-11-30 22:42:35 +00001625 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001626 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001627 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001628 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001629 SS, SourceLocation(),
1630 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001631 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001632 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001633 }
Mike Stump1eb44332009-09-09 15:08:12 +00001634
Douglas Gregorb98b1992009-08-11 05:31:07 +00001635 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001636 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001637 /// By default, performs semantic analysis to build the new expression.
1638 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001639 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001640 MultiExprArg Inits,
1641 SourceLocation RBraceLoc,
1642 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001643 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001644 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1645 if (Result.isInvalid() || ResultTy->isDependentType())
1646 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001647
Douglas Gregore48319a2009-11-09 17:16:50 +00001648 // Patch in the result type we were given, which may have been computed
1649 // when the initial InitListExpr was built.
1650 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1651 ILE->setType(ResultTy);
1652 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 }
Mike Stump1eb44332009-09-09 15:08:12 +00001654
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001656 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001657 /// By default, performs semantic analysis to build the new expression.
1658 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001659 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001660 MultiExprArg ArrayExprs,
1661 SourceLocation EqualOrColonLoc,
1662 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001663 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001664 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001665 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001666 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001668 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001669
Douglas Gregorb98b1992009-08-11 05:31:07 +00001670 ArrayExprs.release();
1671 return move(Result);
1672 }
Mike Stump1eb44332009-09-09 15:08:12 +00001673
Douglas Gregorb98b1992009-08-11 05:31:07 +00001674 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001675 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001676 /// By default, builds the implicit value initialization without performing
1677 /// any semantic analysis. Subclasses may override this routine to provide
1678 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001679 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001680 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1681 }
Mike Stump1eb44332009-09-09 15:08:12 +00001682
Douglas Gregorb98b1992009-08-11 05:31:07 +00001683 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001684 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001685 /// By default, performs semantic analysis to build the new expression.
1686 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001687 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001688 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001689 SourceLocation RParenLoc) {
1690 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001691 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001692 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001693 }
1694
1695 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001696 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001697 /// By default, performs semantic analysis to build the new expression.
1698 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001699 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001700 MultiExprArg SubExprs,
1701 SourceLocation RParenLoc) {
1702 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001703 }
Mike Stump1eb44332009-09-09 15:08:12 +00001704
Douglas Gregorb98b1992009-08-11 05:31:07 +00001705 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001706 ///
1707 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 /// rather than attempting to map the label statement itself.
1709 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001710 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001711 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001712 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 }
Mike Stump1eb44332009-09-09 15:08:12 +00001714
Douglas Gregorb98b1992009-08-11 05:31:07 +00001715 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001716 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717 /// By default, performs semantic analysis to build the new expression.
1718 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001719 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001720 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001721 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001722 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001723 }
Mike Stump1eb44332009-09-09 15:08:12 +00001724
Douglas Gregorb98b1992009-08-11 05:31:07 +00001725 /// \brief Build a new __builtin_choose_expr expression.
1726 ///
1727 /// By default, performs semantic analysis to build the new expression.
1728 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001729 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001730 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001731 SourceLocation RParenLoc) {
1732 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001733 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001734 RParenLoc);
1735 }
Mike Stump1eb44332009-09-09 15:08:12 +00001736
Peter Collingbournef111d932011-04-15 00:35:48 +00001737 /// \brief Build a new generic selection expression.
1738 ///
1739 /// By default, performs semantic analysis to build the new expression.
1740 /// Subclasses may override this routine to provide different behavior.
1741 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1742 SourceLocation DefaultLoc,
1743 SourceLocation RParenLoc,
1744 Expr *ControllingExpr,
1745 TypeSourceInfo **Types,
1746 Expr **Exprs,
1747 unsigned NumAssocs) {
1748 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1749 ControllingExpr, Types, Exprs,
1750 NumAssocs);
1751 }
1752
Douglas Gregorb98b1992009-08-11 05:31:07 +00001753 /// \brief Build a new overloaded operator call expression.
1754 ///
1755 /// By default, performs semantic analysis to build the new expression.
1756 /// The semantic analysis provides the behavior of template instantiation,
1757 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001758 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 /// argument-dependent lookup, etc. Subclasses may override this routine to
1760 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001761 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001762 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001763 Expr *Callee,
1764 Expr *First,
1765 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001766
1767 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001768 /// reinterpret_cast.
1769 ///
1770 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001771 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001772 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001773 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001774 Stmt::StmtClass Class,
1775 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001776 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001777 SourceLocation RAngleLoc,
1778 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001779 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001780 SourceLocation RParenLoc) {
1781 switch (Class) {
1782 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001783 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001784 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001785 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001786
1787 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001788 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001789 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001790 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001791
Douglas Gregorb98b1992009-08-11 05:31:07 +00001792 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001793 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001794 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001795 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001796 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001797
Douglas Gregorb98b1992009-08-11 05:31:07 +00001798 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001799 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001800 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001801 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001802
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001804 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001805 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 }
Mike Stump1eb44332009-09-09 15:08:12 +00001807
Douglas Gregorb98b1992009-08-11 05:31:07 +00001808 /// \brief Build a new C++ static_cast expression.
1809 ///
1810 /// By default, performs semantic analysis to build the new expression.
1811 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001812 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001813 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001814 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001815 SourceLocation RAngleLoc,
1816 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001817 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001818 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001819 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001820 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001821 SourceRange(LAngleLoc, RAngleLoc),
1822 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001823 }
1824
1825 /// \brief Build a new C++ dynamic_cast expression.
1826 ///
1827 /// By default, performs semantic analysis to build the new expression.
1828 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001829 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001830 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001831 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001832 SourceLocation RAngleLoc,
1833 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001834 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001835 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001836 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001837 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001838 SourceRange(LAngleLoc, RAngleLoc),
1839 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001840 }
1841
1842 /// \brief Build a new C++ reinterpret_cast expression.
1843 ///
1844 /// By default, performs semantic analysis to build the new expression.
1845 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001846 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001847 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001848 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001849 SourceLocation RAngleLoc,
1850 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001851 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001852 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001853 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001854 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001855 SourceRange(LAngleLoc, RAngleLoc),
1856 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001857 }
1858
1859 /// \brief Build a new C++ const_cast expression.
1860 ///
1861 /// By default, performs semantic analysis to build the new expression.
1862 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001863 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001864 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001865 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001866 SourceLocation RAngleLoc,
1867 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001868 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001869 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001870 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001871 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001872 SourceRange(LAngleLoc, RAngleLoc),
1873 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001874 }
Mike Stump1eb44332009-09-09 15:08:12 +00001875
Douglas Gregorb98b1992009-08-11 05:31:07 +00001876 /// \brief Build a new C++ functional-style cast expression.
1877 ///
1878 /// By default, performs semantic analysis to build the new expression.
1879 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001880 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1881 SourceLocation LParenLoc,
1882 Expr *Sub,
1883 SourceLocation RParenLoc) {
1884 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001885 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001886 RParenLoc);
1887 }
Mike Stump1eb44332009-09-09 15:08:12 +00001888
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 /// \brief Build a new C++ typeid(type) expression.
1890 ///
1891 /// By default, performs semantic analysis to build the new expression.
1892 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001893 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001894 SourceLocation TypeidLoc,
1895 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001896 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001897 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001898 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001899 }
Mike Stump1eb44332009-09-09 15:08:12 +00001900
Francois Pichet01b7c302010-09-08 12:20:18 +00001901
Douglas Gregorb98b1992009-08-11 05:31:07 +00001902 /// \brief Build a new C++ typeid(expr) expression.
1903 ///
1904 /// By default, performs semantic analysis to build the new expression.
1905 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001906 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001907 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001908 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001909 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001910 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001911 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001912 }
1913
Francois Pichet01b7c302010-09-08 12:20:18 +00001914 /// \brief Build a new C++ __uuidof(type) expression.
1915 ///
1916 /// By default, performs semantic analysis to build the new expression.
1917 /// Subclasses may override this routine to provide different behavior.
1918 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1919 SourceLocation TypeidLoc,
1920 TypeSourceInfo *Operand,
1921 SourceLocation RParenLoc) {
1922 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1923 RParenLoc);
1924 }
1925
1926 /// \brief Build a new C++ __uuidof(expr) expression.
1927 ///
1928 /// By default, performs semantic analysis to build the new expression.
1929 /// Subclasses may override this routine to provide different behavior.
1930 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1931 SourceLocation TypeidLoc,
1932 Expr *Operand,
1933 SourceLocation RParenLoc) {
1934 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1935 RParenLoc);
1936 }
1937
Douglas Gregorb98b1992009-08-11 05:31:07 +00001938 /// \brief Build a new C++ "this" expression.
1939 ///
1940 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001941 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001942 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001943 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001944 QualType ThisType,
1945 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001946 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001947 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001948 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1949 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001950 }
1951
1952 /// \brief Build a new C++ throw expression.
1953 ///
1954 /// By default, performs semantic analysis to build the new expression.
1955 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001956 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1957 bool IsThrownVariableInScope) {
1958 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001959 }
1960
1961 /// \brief Build a new C++ default-argument expression.
1962 ///
1963 /// By default, builds a new default-argument expression, which does not
1964 /// require any semantic analysis. Subclasses may override this routine to
1965 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001966 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001967 ParmVarDecl *Param) {
1968 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1969 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001970 }
1971
1972 /// \brief Build a new C++ zero-initialization expression.
1973 ///
1974 /// By default, performs semantic analysis to build the new expression.
1975 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001976 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1977 SourceLocation LParenLoc,
1978 SourceLocation RParenLoc) {
1979 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001980 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001981 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001982 }
Mike Stump1eb44332009-09-09 15:08:12 +00001983
Douglas Gregorb98b1992009-08-11 05:31:07 +00001984 /// \brief Build a new C++ "new" expression.
1985 ///
1986 /// By default, performs semantic analysis to build the new expression.
1987 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001988 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001989 bool UseGlobal,
1990 SourceLocation PlacementLParen,
1991 MultiExprArg PlacementArgs,
1992 SourceLocation PlacementRParen,
1993 SourceRange TypeIdParens,
1994 QualType AllocatedType,
1995 TypeSourceInfo *AllocatedTypeInfo,
1996 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001997 SourceRange DirectInitRange,
1998 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001999 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002000 PlacementLParen,
2001 move(PlacementArgs),
2002 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002003 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002004 AllocatedType,
2005 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002006 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002007 DirectInitRange,
2008 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002009 }
Mike Stump1eb44332009-09-09 15:08:12 +00002010
Douglas Gregorb98b1992009-08-11 05:31:07 +00002011 /// \brief Build a new C++ "delete" expression.
2012 ///
2013 /// By default, performs semantic analysis to build the new expression.
2014 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002015 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002016 bool IsGlobalDelete,
2017 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002018 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002019 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002020 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002021 }
Mike Stump1eb44332009-09-09 15:08:12 +00002022
Douglas Gregorb98b1992009-08-11 05:31:07 +00002023 /// \brief Build a new unary type trait expression.
2024 ///
2025 /// By default, performs semantic analysis to build the new expression.
2026 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002027 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002028 SourceLocation StartLoc,
2029 TypeSourceInfo *T,
2030 SourceLocation RParenLoc) {
2031 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002032 }
2033
Francois Pichet6ad6f282010-12-07 00:08:36 +00002034 /// \brief Build a new binary type trait expression.
2035 ///
2036 /// By default, performs semantic analysis to build the new expression.
2037 /// Subclasses may override this routine to provide different behavior.
2038 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2039 SourceLocation StartLoc,
2040 TypeSourceInfo *LhsT,
2041 TypeSourceInfo *RhsT,
2042 SourceLocation RParenLoc) {
2043 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2044 }
2045
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002046 /// \brief Build a new type trait expression.
2047 ///
2048 /// By default, performs semantic analysis to build the new expression.
2049 /// Subclasses may override this routine to provide different behavior.
2050 ExprResult RebuildTypeTrait(TypeTrait Trait,
2051 SourceLocation StartLoc,
2052 ArrayRef<TypeSourceInfo *> Args,
2053 SourceLocation RParenLoc) {
2054 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2055 }
2056
John Wiegley21ff2e52011-04-28 00:16:57 +00002057 /// \brief Build a new array type trait expression.
2058 ///
2059 /// By default, performs semantic analysis to build the new expression.
2060 /// Subclasses may override this routine to provide different behavior.
2061 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2062 SourceLocation StartLoc,
2063 TypeSourceInfo *TSInfo,
2064 Expr *DimExpr,
2065 SourceLocation RParenLoc) {
2066 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2067 }
2068
John Wiegley55262202011-04-25 06:54:41 +00002069 /// \brief Build a new expression trait expression.
2070 ///
2071 /// By default, performs semantic analysis to build the new expression.
2072 /// Subclasses may override this routine to provide different behavior.
2073 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2074 SourceLocation StartLoc,
2075 Expr *Queried,
2076 SourceLocation RParenLoc) {
2077 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2078 }
2079
Mike Stump1eb44332009-09-09 15:08:12 +00002080 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002081 /// expression.
2082 ///
2083 /// By default, performs semantic analysis to build the new expression.
2084 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002085 ExprResult RebuildDependentScopeDeclRefExpr(
2086 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002087 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002088 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002089 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002090 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002091 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002092
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002093 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002094 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002095 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002096
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002097 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002098 }
2099
2100 /// \brief Build a new template-id expression.
2101 ///
2102 /// By default, performs semantic analysis to build the new expression.
2103 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002104 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002105 SourceLocation TemplateKWLoc,
2106 LookupResult &R,
2107 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002108 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002109 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2110 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002111 }
2112
2113 /// \brief Build a new object-construction expression.
2114 ///
2115 /// By default, performs semantic analysis to build the new expression.
2116 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002117 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002118 SourceLocation Loc,
2119 CXXConstructorDecl *Constructor,
2120 bool IsElidable,
2121 MultiExprArg Args,
2122 bool HadMultipleCandidates,
2123 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002124 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002125 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002126 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002127 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002128 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002129 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002130
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002131 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002132 move_arg(ConvertedArgs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002133 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002134 RequiresZeroInit, ConstructKind,
2135 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002136 }
2137
2138 /// \brief Build a new object-construction expression.
2139 ///
2140 /// By default, performs semantic analysis to build the new expression.
2141 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002142 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2143 SourceLocation LParenLoc,
2144 MultiExprArg Args,
2145 SourceLocation RParenLoc) {
2146 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002147 LParenLoc,
2148 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002149 RParenLoc);
2150 }
2151
2152 /// \brief Build a new object-construction expression.
2153 ///
2154 /// By default, performs semantic analysis to build the new expression.
2155 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002156 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2157 SourceLocation LParenLoc,
2158 MultiExprArg Args,
2159 SourceLocation RParenLoc) {
2160 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002161 LParenLoc,
2162 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002163 RParenLoc);
2164 }
Mike Stump1eb44332009-09-09 15:08:12 +00002165
Douglas Gregorb98b1992009-08-11 05:31:07 +00002166 /// \brief Build a new member reference expression.
2167 ///
2168 /// By default, performs semantic analysis to build the new expression.
2169 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002170 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002171 QualType BaseType,
2172 bool IsArrow,
2173 SourceLocation OperatorLoc,
2174 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002175 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002176 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002177 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002178 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002179 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002180 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002181
John McCall9ae2f072010-08-23 23:25:46 +00002182 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002183 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002184 SS, TemplateKWLoc,
2185 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002186 MemberNameInfo,
2187 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002188 }
2189
John McCall129e2df2009-11-30 22:42:35 +00002190 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002191 ///
2192 /// By default, performs semantic analysis to build the new expression.
2193 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002194 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2195 SourceLocation OperatorLoc,
2196 bool IsArrow,
2197 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002198 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002199 NamedDecl *FirstQualifierInScope,
2200 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002201 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002202 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002203 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002204
John McCall9ae2f072010-08-23 23:25:46 +00002205 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002206 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002207 SS, TemplateKWLoc,
2208 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002209 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002210 }
Mike Stump1eb44332009-09-09 15:08:12 +00002211
Sebastian Redl2e156222010-09-10 20:55:43 +00002212 /// \brief Build a new noexcept expression.
2213 ///
2214 /// By default, performs semantic analysis to build the new expression.
2215 /// Subclasses may override this routine to provide different behavior.
2216 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2217 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2218 }
2219
Douglas Gregoree8aff02011-01-04 17:33:58 +00002220 /// \brief Build a new expression to compute the length of a parameter pack.
2221 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2222 SourceLocation PackLoc,
2223 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002224 llvm::Optional<unsigned> Length) {
2225 if (Length)
2226 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2227 OperatorLoc, Pack, PackLoc,
2228 RParenLoc, *Length);
2229
Douglas Gregoree8aff02011-01-04 17:33:58 +00002230 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2231 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002232 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002233 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002234
Patrick Beardeb382ec2012-04-19 00:25:12 +00002235 /// \brief Build a new Objective-C boxed expression.
2236 ///
2237 /// By default, performs semantic analysis to build the new expression.
2238 /// Subclasses may override this routine to provide different behavior.
2239 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2240 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2241 }
2242
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002243 /// \brief Build a new Objective-C array literal.
2244 ///
2245 /// By default, performs semantic analysis to build the new expression.
2246 /// Subclasses may override this routine to provide different behavior.
2247 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2248 Expr **Elements, unsigned NumElements) {
2249 return getSema().BuildObjCArrayLiteral(Range,
2250 MultiExprArg(Elements, NumElements));
2251 }
2252
2253 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
2254 Expr *Base, Expr *Key,
2255 ObjCMethodDecl *getterMethod,
2256 ObjCMethodDecl *setterMethod) {
2257 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2258 getterMethod, setterMethod);
2259 }
2260
2261 /// \brief Build a new Objective-C dictionary literal.
2262 ///
2263 /// By default, performs semantic analysis to build the new expression.
2264 /// Subclasses may override this routine to provide different behavior.
2265 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2266 ObjCDictionaryElement *Elements,
2267 unsigned NumElements) {
2268 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2269 }
2270
James Dennett699c9042012-06-15 07:13:21 +00002271 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002272 ///
2273 /// By default, performs semantic analysis to build the new expression.
2274 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002275 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002276 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002277 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002278 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002279 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002280 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002281
Douglas Gregor92e986e2010-04-22 16:44:27 +00002282 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002283 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002284 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002285 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002286 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002287 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002288 MultiExprArg Args,
2289 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002290 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2291 ReceiverTypeInfo->getType(),
2292 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002293 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002294 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002295 }
2296
2297 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002298 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002299 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002300 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002301 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002302 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002303 MultiExprArg Args,
2304 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002305 return SemaRef.BuildInstanceMessage(Receiver,
2306 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002307 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002308 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002309 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002310 }
2311
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002312 /// \brief Build a new Objective-C ivar reference expression.
2313 ///
2314 /// By default, performs semantic analysis to build the new expression.
2315 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002316 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002317 SourceLocation IvarLoc,
2318 bool IsArrow, bool IsFreeIvar) {
2319 // FIXME: We lose track of the IsFreeIvar bit.
2320 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002321 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002322 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2323 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002324 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002325 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002326 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002327 false);
John Wiegley429bb272011-04-08 18:41:53 +00002328 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002329 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002330
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002331 if (Result.get())
2332 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002333
John Wiegley429bb272011-04-08 18:41:53 +00002334 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002335 /*FIXME:*/IvarLoc, IsArrow,
2336 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002337 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002338 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002339 /*TemplateArgs=*/0);
2340 }
Douglas Gregore3303542010-04-26 20:47:02 +00002341
2342 /// \brief Build a new Objective-C property reference expression.
2343 ///
2344 /// By default, performs semantic analysis to build the new expression.
2345 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002346 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002347 ObjCPropertyDecl *Property,
2348 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002349 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002350 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002351 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2352 Sema::LookupMemberName);
2353 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002354 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002355 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002356 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002357 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002358 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002359
Douglas Gregore3303542010-04-26 20:47:02 +00002360 if (Result.get())
2361 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002362
John Wiegley429bb272011-04-08 18:41:53 +00002363 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002364 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002365 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002366 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002367 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002368 /*TemplateArgs=*/0);
2369 }
Sean Huntc3021132010-05-05 15:23:54 +00002370
John McCall12f78a62010-12-02 01:19:52 +00002371 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002372 ///
2373 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002374 /// Subclasses may override this routine to provide different behavior.
2375 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2376 ObjCMethodDecl *Getter,
2377 ObjCMethodDecl *Setter,
2378 SourceLocation PropertyLoc) {
2379 // Since these expressions can only be value-dependent, we do not
2380 // need to perform semantic analysis again.
2381 return Owned(
2382 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2383 VK_LValue, OK_ObjCProperty,
2384 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002385 }
2386
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002387 /// \brief Build a new Objective-C "isa" expression.
2388 ///
2389 /// By default, performs semantic analysis to build the new expression.
2390 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002391 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002392 bool IsArrow) {
2393 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002394 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002395 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2396 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002397 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002398 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002399 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002400 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002401 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002402
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002403 if (Result.get())
2404 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002405
John Wiegley429bb272011-04-08 18:41:53 +00002406 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002407 /*FIXME:*/IsaLoc, IsArrow,
2408 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002409 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002410 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002411 /*TemplateArgs=*/0);
2412 }
Sean Huntc3021132010-05-05 15:23:54 +00002413
Douglas Gregorb98b1992009-08-11 05:31:07 +00002414 /// \brief Build a new shuffle vector expression.
2415 ///
2416 /// By default, performs semantic analysis to build the new expression.
2417 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002418 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002419 MultiExprArg SubExprs,
2420 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002421 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002422 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002423 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2424 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2425 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2426 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002427
Douglas Gregorb98b1992009-08-11 05:31:07 +00002428 // Build a reference to the __builtin_shufflevector builtin
2429 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002430 ExprResult Callee
John McCallf4b88a42012-03-10 09:33:50 +00002431 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false,
2432 Builtin->getType(),
John Wiegley429bb272011-04-08 18:41:53 +00002433 VK_LValue, BuiltinLoc));
2434 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2435 if (Callee.isInvalid())
2436 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002437
2438 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002439 unsigned NumSubExprs = SubExprs.size();
2440 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002441 ExprResult TheCall = SemaRef.Owned(
2442 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002443 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002444 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002445 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002446 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002447
Douglas Gregorb98b1992009-08-11 05:31:07 +00002448 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002449 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002450 }
John McCall43fed0d2010-11-12 08:19:04 +00002451
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002452 /// \brief Build a new template argument pack expansion.
2453 ///
2454 /// By default, performs semantic analysis to build a new pack expansion
2455 /// for a template argument. Subclasses may override this routine to provide
2456 /// different behavior.
2457 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002458 SourceLocation EllipsisLoc,
2459 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002460 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002461 case TemplateArgument::Expression: {
2462 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002463 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2464 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002465 if (Result.isInvalid())
2466 return TemplateArgumentLoc();
2467
2468 return TemplateArgumentLoc(Result.get(), Result.get());
2469 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002470
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002471 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002472 return TemplateArgumentLoc(TemplateArgument(
2473 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002474 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002475 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002476 Pattern.getTemplateNameLoc(),
2477 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002478
2479 case TemplateArgument::Null:
2480 case TemplateArgument::Integral:
2481 case TemplateArgument::Declaration:
2482 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002483 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002484 llvm_unreachable("Pack expansion pattern has no parameter packs");
2485
2486 case TemplateArgument::Type:
2487 if (TypeSourceInfo *Expansion
2488 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002489 EllipsisLoc,
2490 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002491 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2492 Expansion);
2493 break;
2494 }
2495
2496 return TemplateArgumentLoc();
2497 }
2498
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002499 /// \brief Build a new expression pack expansion.
2500 ///
2501 /// By default, performs semantic analysis to build a new pack expansion
2502 /// for an expression. Subclasses may override this routine to provide
2503 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002504 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2505 llvm::Optional<unsigned> NumExpansions) {
2506 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002507 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002508
2509 /// \brief Build a new atomic operation expression.
2510 ///
2511 /// By default, performs semantic analysis to build the new expression.
2512 /// Subclasses may override this routine to provide different behavior.
2513 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2514 MultiExprArg SubExprs,
2515 QualType RetTy,
2516 AtomicExpr::AtomicOp Op,
2517 SourceLocation RParenLoc) {
2518 // Just create the expression; there is not any interesting semantic
2519 // analysis here because we can't actually build an AtomicExpr until
2520 // we are sure it is semantically sound.
2521 unsigned NumSubExprs = SubExprs.size();
2522 Expr **Subs = (Expr **)SubExprs.release();
2523 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2524 NumSubExprs, RetTy, Op,
2525 RParenLoc);
2526 }
2527
John McCall43fed0d2010-11-12 08:19:04 +00002528private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002529 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2530 QualType ObjectType,
2531 NamedDecl *FirstQualifierInScope,
2532 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002533
2534 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2535 QualType ObjectType,
2536 NamedDecl *FirstQualifierInScope,
2537 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002538};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002539
Douglas Gregor43959a92009-08-20 07:17:43 +00002540template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002541StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002542 if (!S)
2543 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002544
Douglas Gregor43959a92009-08-20 07:17:43 +00002545 switch (S->getStmtClass()) {
2546 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002547
Douglas Gregor43959a92009-08-20 07:17:43 +00002548 // Transform individual statement nodes
2549#define STMT(Node, Parent) \
2550 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002551#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002552#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002553#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002554
Douglas Gregor43959a92009-08-20 07:17:43 +00002555 // Transform expressions by calling TransformExpr.
2556#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002557#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002558#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002559#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002560 {
John McCall60d7b3a2010-08-24 06:29:42 +00002561 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002562 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002563 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002564
John McCall9ae2f072010-08-23 23:25:46 +00002565 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002566 }
Mike Stump1eb44332009-09-09 15:08:12 +00002567 }
2568
John McCall3fa5cae2010-10-26 07:05:15 +00002569 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002570}
Mike Stump1eb44332009-09-09 15:08:12 +00002571
2572
Douglas Gregor670444e2009-08-04 22:27:00 +00002573template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002574ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002575 if (!E)
2576 return SemaRef.Owned(E);
2577
2578 switch (E->getStmtClass()) {
2579 case Stmt::NoStmtClass: break;
2580#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002581#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002582#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002583 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002584#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002585 }
2586
John McCall3fa5cae2010-10-26 07:05:15 +00002587 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002588}
2589
2590template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002591bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2592 unsigned NumInputs,
2593 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002594 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002595 bool *ArgChanged) {
2596 for (unsigned I = 0; I != NumInputs; ++I) {
2597 // If requested, drop call arguments that need to be dropped.
2598 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2599 if (ArgChanged)
2600 *ArgChanged = true;
2601
2602 break;
2603 }
2604
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002605 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2606 Expr *Pattern = Expansion->getPattern();
2607
Chris Lattner686775d2011-07-20 06:58:45 +00002608 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002609 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2610 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2611
2612 // Determine whether the set of unexpanded parameter packs can and should
2613 // be expanded.
2614 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002615 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002616 llvm::Optional<unsigned> OrigNumExpansions
2617 = Expansion->getNumExpansions();
2618 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002619 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2620 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002621 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002622 Expand, RetainExpansion,
2623 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002624 return true;
2625
2626 if (!Expand) {
2627 // The transform has determined that we should perform a simple
2628 // transformation on the pack expansion, producing another pack
2629 // expansion.
2630 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2631 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2632 if (OutPattern.isInvalid())
2633 return true;
2634
2635 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002636 Expansion->getEllipsisLoc(),
2637 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002638 if (Out.isInvalid())
2639 return true;
2640
2641 if (ArgChanged)
2642 *ArgChanged = true;
2643 Outputs.push_back(Out.get());
2644 continue;
2645 }
John McCallc8fc90a2011-07-06 07:30:07 +00002646
2647 // Record right away that the argument was changed. This needs
2648 // to happen even if the array expands to nothing.
2649 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002650
2651 // The transform has determined that we should perform an elementwise
2652 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002653 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002654 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2655 ExprResult Out = getDerived().TransformExpr(Pattern);
2656 if (Out.isInvalid())
2657 return true;
2658
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002659 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002660 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2661 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002662 if (Out.isInvalid())
2663 return true;
2664 }
2665
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002666 Outputs.push_back(Out.get());
2667 }
2668
2669 continue;
2670 }
2671
Douglas Gregoraa165f82011-01-03 19:04:46 +00002672 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2673 if (Result.isInvalid())
2674 return true;
2675
2676 if (Result.get() != Inputs[I] && ArgChanged)
2677 *ArgChanged = true;
2678
2679 Outputs.push_back(Result.get());
2680 }
2681
2682 return false;
2683}
2684
2685template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002686NestedNameSpecifierLoc
2687TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2688 NestedNameSpecifierLoc NNS,
2689 QualType ObjectType,
2690 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002691 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002692 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2693 Qualifier = Qualifier.getPrefix())
2694 Qualifiers.push_back(Qualifier);
2695
2696 CXXScopeSpec SS;
2697 while (!Qualifiers.empty()) {
2698 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2699 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2700
2701 switch (QNNS->getKind()) {
2702 case NestedNameSpecifier::Identifier:
2703 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2704 *QNNS->getAsIdentifier(),
2705 Q.getLocalBeginLoc(),
2706 Q.getLocalEndLoc(),
2707 ObjectType, false, SS,
2708 FirstQualifierInScope, false))
2709 return NestedNameSpecifierLoc();
2710
2711 break;
2712
2713 case NestedNameSpecifier::Namespace: {
2714 NamespaceDecl *NS
2715 = cast_or_null<NamespaceDecl>(
2716 getDerived().TransformDecl(
2717 Q.getLocalBeginLoc(),
2718 QNNS->getAsNamespace()));
2719 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2720 break;
2721 }
2722
2723 case NestedNameSpecifier::NamespaceAlias: {
2724 NamespaceAliasDecl *Alias
2725 = cast_or_null<NamespaceAliasDecl>(
2726 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2727 QNNS->getAsNamespaceAlias()));
2728 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2729 Q.getLocalEndLoc());
2730 break;
2731 }
2732
2733 case NestedNameSpecifier::Global:
2734 // There is no meaningful transformation that one could perform on the
2735 // global scope.
2736 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2737 break;
2738
2739 case NestedNameSpecifier::TypeSpecWithTemplate:
2740 case NestedNameSpecifier::TypeSpec: {
2741 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2742 FirstQualifierInScope, SS);
2743
2744 if (!TL)
2745 return NestedNameSpecifierLoc();
2746
2747 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
David Blaikie4e4d0842012-03-11 07:00:24 +00002748 (SemaRef.getLangOpts().CPlusPlus0x &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002749 TL.getType()->isEnumeralType())) {
2750 assert(!TL.getType().hasLocalQualifiers() &&
2751 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002752 if (TL.getType()->isEnumeralType())
2753 SemaRef.Diag(TL.getBeginLoc(),
2754 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002755 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2756 Q.getLocalEndLoc());
2757 break;
2758 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002759 // If the nested-name-specifier is an invalid type def, don't emit an
2760 // error because a previous error should have already been emitted.
2761 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2762 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2763 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2764 << TL.getType() << SS.getRange();
2765 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002766 return NestedNameSpecifierLoc();
2767 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002768 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002769
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002770 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002771 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002772 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002773 }
2774
2775 // Don't rebuild the nested-name-specifier if we don't have to.
2776 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2777 !getDerived().AlwaysRebuild())
2778 return NNS;
2779
2780 // If we can re-use the source-location data from the original
2781 // nested-name-specifier, do so.
2782 if (SS.location_size() == NNS.getDataLength() &&
2783 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2784 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2785
2786 // Allocate new nested-name-specifier location information.
2787 return SS.getWithLocInContext(SemaRef.Context);
2788}
2789
2790template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002791DeclarationNameInfo
2792TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002793::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002794 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002795 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002796 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002797
2798 switch (Name.getNameKind()) {
2799 case DeclarationName::Identifier:
2800 case DeclarationName::ObjCZeroArgSelector:
2801 case DeclarationName::ObjCOneArgSelector:
2802 case DeclarationName::ObjCMultiArgSelector:
2803 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002804 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002805 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002806 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002807
Douglas Gregor81499bb2009-09-03 22:13:48 +00002808 case DeclarationName::CXXConstructorName:
2809 case DeclarationName::CXXDestructorName:
2810 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002811 TypeSourceInfo *NewTInfo;
2812 CanQualType NewCanTy;
2813 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002814 NewTInfo = getDerived().TransformType(OldTInfo);
2815 if (!NewTInfo)
2816 return DeclarationNameInfo();
2817 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002818 }
2819 else {
2820 NewTInfo = 0;
2821 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002822 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002823 if (NewT.isNull())
2824 return DeclarationNameInfo();
2825 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2826 }
Mike Stump1eb44332009-09-09 15:08:12 +00002827
Abramo Bagnara25777432010-08-11 22:01:17 +00002828 DeclarationName NewName
2829 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2830 NewCanTy);
2831 DeclarationNameInfo NewNameInfo(NameInfo);
2832 NewNameInfo.setName(NewName);
2833 NewNameInfo.setNamedTypeInfo(NewTInfo);
2834 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002835 }
Mike Stump1eb44332009-09-09 15:08:12 +00002836 }
2837
David Blaikieb219cfc2011-09-23 05:06:16 +00002838 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002839}
2840
2841template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002842TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002843TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2844 TemplateName Name,
2845 SourceLocation NameLoc,
2846 QualType ObjectType,
2847 NamedDecl *FirstQualifierInScope) {
2848 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2849 TemplateDecl *Template = QTN->getTemplateDecl();
2850 assert(Template && "qualified template name must refer to a template");
2851
2852 TemplateDecl *TransTemplate
2853 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2854 Template));
2855 if (!TransTemplate)
2856 return TemplateName();
2857
2858 if (!getDerived().AlwaysRebuild() &&
2859 SS.getScopeRep() == QTN->getQualifier() &&
2860 TransTemplate == Template)
2861 return Name;
2862
2863 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2864 TransTemplate);
2865 }
2866
2867 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2868 if (SS.getScopeRep()) {
2869 // These apply to the scope specifier, not the template.
2870 ObjectType = QualType();
2871 FirstQualifierInScope = 0;
2872 }
2873
2874 if (!getDerived().AlwaysRebuild() &&
2875 SS.getScopeRep() == DTN->getQualifier() &&
2876 ObjectType.isNull())
2877 return Name;
2878
2879 if (DTN->isIdentifier()) {
2880 return getDerived().RebuildTemplateName(SS,
2881 *DTN->getIdentifier(),
2882 NameLoc,
2883 ObjectType,
2884 FirstQualifierInScope);
2885 }
2886
2887 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2888 ObjectType);
2889 }
2890
2891 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2892 TemplateDecl *TransTemplate
2893 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2894 Template));
2895 if (!TransTemplate)
2896 return TemplateName();
2897
2898 if (!getDerived().AlwaysRebuild() &&
2899 TransTemplate == Template)
2900 return Name;
2901
2902 return TemplateName(TransTemplate);
2903 }
2904
2905 if (SubstTemplateTemplateParmPackStorage *SubstPack
2906 = Name.getAsSubstTemplateTemplateParmPack()) {
2907 TemplateTemplateParmDecl *TransParam
2908 = cast_or_null<TemplateTemplateParmDecl>(
2909 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2910 if (!TransParam)
2911 return TemplateName();
2912
2913 if (!getDerived().AlwaysRebuild() &&
2914 TransParam == SubstPack->getParameterPack())
2915 return Name;
2916
2917 return getDerived().RebuildTemplateName(TransParam,
2918 SubstPack->getArgumentPack());
2919 }
2920
2921 // These should be getting filtered out before they reach the AST.
2922 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002923}
2924
2925template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002926void TreeTransform<Derived>::InventTemplateArgumentLoc(
2927 const TemplateArgument &Arg,
2928 TemplateArgumentLoc &Output) {
2929 SourceLocation Loc = getDerived().getBaseLocation();
2930 switch (Arg.getKind()) {
2931 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002932 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002933 break;
2934
2935 case TemplateArgument::Type:
2936 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002937 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002938
John McCall833ca992009-10-29 08:12:44 +00002939 break;
2940
Douglas Gregor788cd062009-11-11 01:00:40 +00002941 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002942 case TemplateArgument::TemplateExpansion: {
2943 NestedNameSpecifierLocBuilder Builder;
2944 TemplateName Template = Arg.getAsTemplate();
2945 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2946 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2947 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2948 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2949
2950 if (Arg.getKind() == TemplateArgument::Template)
2951 Output = TemplateArgumentLoc(Arg,
2952 Builder.getWithLocInContext(SemaRef.Context),
2953 Loc);
2954 else
2955 Output = TemplateArgumentLoc(Arg,
2956 Builder.getWithLocInContext(SemaRef.Context),
2957 Loc, Loc);
2958
Douglas Gregor788cd062009-11-11 01:00:40 +00002959 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002960 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002961
John McCall833ca992009-10-29 08:12:44 +00002962 case TemplateArgument::Expression:
2963 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2964 break;
2965
2966 case TemplateArgument::Declaration:
2967 case TemplateArgument::Integral:
2968 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002969 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002970 break;
2971 }
2972}
2973
2974template<typename Derived>
2975bool TreeTransform<Derived>::TransformTemplateArgument(
2976 const TemplateArgumentLoc &Input,
2977 TemplateArgumentLoc &Output) {
2978 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002979 switch (Arg.getKind()) {
2980 case TemplateArgument::Null:
2981 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002982 Output = Input;
2983 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002984
Douglas Gregor670444e2009-08-04 22:27:00 +00002985 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002986 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002987 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002988 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002989
2990 DI = getDerived().TransformType(DI);
2991 if (!DI) return true;
2992
2993 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2994 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002995 }
Mike Stump1eb44332009-09-09 15:08:12 +00002996
Douglas Gregor670444e2009-08-04 22:27:00 +00002997 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002998 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002999 DeclarationName Name;
3000 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
3001 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00003002 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003003 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00003004 if (!D) return true;
3005
John McCall828bff22009-10-29 18:45:58 +00003006 Expr *SourceExpr = Input.getSourceDeclExpression();
3007 if (SourceExpr) {
3008 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003009 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00003010 ExprResult E = getDerived().TransformExpr(SourceExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003011 E = SemaRef.ActOnConstantExpression(E);
John McCall9ae2f072010-08-23 23:25:46 +00003012 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00003013 }
3014
3015 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00003016 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003017 }
Mike Stump1eb44332009-09-09 15:08:12 +00003018
Douglas Gregor788cd062009-11-11 01:00:40 +00003019 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003020 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3021 if (QualifierLoc) {
3022 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3023 if (!QualifierLoc)
3024 return true;
3025 }
3026
Douglas Gregor1d752d72011-03-02 18:46:51 +00003027 CXXScopeSpec SS;
3028 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003029 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003030 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3031 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003032 if (Template.isNull())
3033 return true;
Sean Huntc3021132010-05-05 15:23:54 +00003034
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003035 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003036 Input.getTemplateNameLoc());
3037 return false;
3038 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003039
3040 case TemplateArgument::TemplateExpansion:
3041 llvm_unreachable("Caller should expand pack expansions");
3042
Douglas Gregor670444e2009-08-04 22:27:00 +00003043 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003044 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003045 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003046 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003047
John McCall833ca992009-10-29 08:12:44 +00003048 Expr *InputExpr = Input.getSourceExpression();
3049 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3050
Chris Lattner223de242011-04-25 20:37:58 +00003051 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003052 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003053 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003054 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003055 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003056 }
Mike Stump1eb44332009-09-09 15:08:12 +00003057
Douglas Gregor670444e2009-08-04 22:27:00 +00003058 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00003059 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00003060 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00003061 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00003062 AEnd = Arg.pack_end();
3063 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00003064
John McCall833ca992009-10-29 08:12:44 +00003065 // FIXME: preserve source information here when we start
3066 // caring about parameter packs.
3067
John McCall828bff22009-10-29 18:45:58 +00003068 TemplateArgumentLoc InputArg;
3069 TemplateArgumentLoc OutputArg;
3070 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3071 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00003072 return true;
3073
John McCall828bff22009-10-29 18:45:58 +00003074 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00003075 }
Douglas Gregor910f8002010-11-07 23:05:16 +00003076
3077 TemplateArgument *TransformedArgsPtr
3078 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3079 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3080 TransformedArgsPtr);
3081 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3082 TransformedArgs.size()),
3083 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003084 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003085 }
3086 }
Mike Stump1eb44332009-09-09 15:08:12 +00003087
Douglas Gregor670444e2009-08-04 22:27:00 +00003088 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003089 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003090}
3091
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003092/// \brief Iterator adaptor that invents template argument location information
3093/// for each of the template arguments in its underlying iterator.
3094template<typename Derived, typename InputIterator>
3095class TemplateArgumentLocInventIterator {
3096 TreeTransform<Derived> &Self;
3097 InputIterator Iter;
3098
3099public:
3100 typedef TemplateArgumentLoc value_type;
3101 typedef TemplateArgumentLoc reference;
3102 typedef typename std::iterator_traits<InputIterator>::difference_type
3103 difference_type;
3104 typedef std::input_iterator_tag iterator_category;
3105
3106 class pointer {
3107 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003108
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003109 public:
3110 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3111
3112 const TemplateArgumentLoc *operator->() const { return &Arg; }
3113 };
3114
3115 TemplateArgumentLocInventIterator() { }
3116
3117 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3118 InputIterator Iter)
3119 : Self(Self), Iter(Iter) { }
3120
3121 TemplateArgumentLocInventIterator &operator++() {
3122 ++Iter;
3123 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003124 }
3125
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003126 TemplateArgumentLocInventIterator operator++(int) {
3127 TemplateArgumentLocInventIterator Old(*this);
3128 ++(*this);
3129 return Old;
3130 }
3131
3132 reference operator*() const {
3133 TemplateArgumentLoc Result;
3134 Self.InventTemplateArgumentLoc(*Iter, Result);
3135 return Result;
3136 }
3137
3138 pointer operator->() const { return pointer(**this); }
3139
3140 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3141 const TemplateArgumentLocInventIterator &Y) {
3142 return X.Iter == Y.Iter;
3143 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003144
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003145 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3146 const TemplateArgumentLocInventIterator &Y) {
3147 return X.Iter != Y.Iter;
3148 }
3149};
3150
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003151template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003152template<typename InputIterator>
3153bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3154 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003155 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003156 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003157 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003158 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003159
3160 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3161 // Unpack argument packs, which we translate them into separate
3162 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003163 // FIXME: We could do much better if we could guarantee that the
3164 // TemplateArgumentLocInfo for the pack expansion would be usable for
3165 // all of the template arguments in the argument pack.
3166 typedef TemplateArgumentLocInventIterator<Derived,
3167 TemplateArgument::pack_iterator>
3168 PackLocIterator;
3169 if (TransformTemplateArguments(PackLocIterator(*this,
3170 In.getArgument().pack_begin()),
3171 PackLocIterator(*this,
3172 In.getArgument().pack_end()),
3173 Outputs))
3174 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003175
3176 continue;
3177 }
3178
3179 if (In.getArgument().isPackExpansion()) {
3180 // We have a pack expansion, for which we will be substituting into
3181 // the pattern.
3182 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003183 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003184 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003185 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3186 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003187
Chris Lattner686775d2011-07-20 06:58:45 +00003188 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003189 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3190 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3191
3192 // Determine whether the set of unexpanded parameter packs can and should
3193 // be expanded.
3194 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003195 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003196 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003197 if (getDerived().TryExpandParameterPacks(Ellipsis,
3198 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003199 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003200 Expand,
3201 RetainExpansion,
3202 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003203 return true;
3204
3205 if (!Expand) {
3206 // The transform has determined that we should perform a simple
3207 // transformation on the pack expansion, producing another pack
3208 // expansion.
3209 TemplateArgumentLoc OutPattern;
3210 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3211 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3212 return true;
3213
Douglas Gregorcded4f62011-01-14 17:04:44 +00003214 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3215 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003216 if (Out.getArgument().isNull())
3217 return true;
3218
3219 Outputs.addArgument(Out);
3220 continue;
3221 }
3222
3223 // The transform has determined that we should perform an elementwise
3224 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003225 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003226 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3227
3228 if (getDerived().TransformTemplateArgument(Pattern, Out))
3229 return true;
3230
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003231 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003232 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3233 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003234 if (Out.getArgument().isNull())
3235 return true;
3236 }
3237
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003238 Outputs.addArgument(Out);
3239 }
3240
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003241 // If we're supposed to retain a pack expansion, do so by temporarily
3242 // forgetting the partially-substituted parameter pack.
3243 if (RetainExpansion) {
3244 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3245
3246 if (getDerived().TransformTemplateArgument(Pattern, Out))
3247 return true;
3248
Douglas Gregorcded4f62011-01-14 17:04:44 +00003249 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3250 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003251 if (Out.getArgument().isNull())
3252 return true;
3253
3254 Outputs.addArgument(Out);
3255 }
Douglas Gregord3731192011-01-10 07:32:04 +00003256
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003257 continue;
3258 }
3259
3260 // The simple case:
3261 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003262 return true;
3263
3264 Outputs.addArgument(Out);
3265 }
3266
3267 return false;
3268
3269}
3270
Douglas Gregor577f75a2009-08-04 16:50:30 +00003271//===----------------------------------------------------------------------===//
3272// Type transformation
3273//===----------------------------------------------------------------------===//
3274
3275template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003276QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003277 if (getDerived().AlreadyTransformed(T))
3278 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003279
John McCalla2becad2009-10-21 00:40:46 +00003280 // Temporary workaround. All of these transformations should
3281 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003282 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3283 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003284
John McCall43fed0d2010-11-12 08:19:04 +00003285 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003286
John McCalla2becad2009-10-21 00:40:46 +00003287 if (!NewDI)
3288 return QualType();
3289
3290 return NewDI->getType();
3291}
3292
3293template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003294TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003295 // Refine the base location to the type's location.
3296 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3297 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003298 if (getDerived().AlreadyTransformed(DI->getType()))
3299 return DI;
3300
3301 TypeLocBuilder TLB;
3302
3303 TypeLoc TL = DI->getTypeLoc();
3304 TLB.reserve(TL.getFullDataSize());
3305
John McCall43fed0d2010-11-12 08:19:04 +00003306 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003307 if (Result.isNull())
3308 return 0;
3309
John McCalla93c9342009-12-07 02:54:59 +00003310 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003311}
3312
3313template<typename Derived>
3314QualType
John McCall43fed0d2010-11-12 08:19:04 +00003315TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003316 switch (T.getTypeLocClass()) {
3317#define ABSTRACT_TYPELOC(CLASS, PARENT)
3318#define TYPELOC(CLASS, PARENT) \
3319 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003320 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003321#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003322 }
Mike Stump1eb44332009-09-09 15:08:12 +00003323
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003324 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003325}
3326
3327/// FIXME: By default, this routine adds type qualifiers only to types
3328/// that can have qualifiers, and silently suppresses those qualifiers
3329/// that are not permitted (e.g., qualifiers on reference or function
3330/// types). This is the right thing for template instantiation, but
3331/// probably not for other clients.
3332template<typename Derived>
3333QualType
3334TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003335 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003336 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003337
John McCall43fed0d2010-11-12 08:19:04 +00003338 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003339 if (Result.isNull())
3340 return QualType();
3341
3342 // Silently suppress qualifiers if the result type can't be qualified.
3343 // FIXME: this is the right thing for template instantiation, but
3344 // probably not for other clients.
3345 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003346 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003347
John McCallf85e1932011-06-15 23:02:42 +00003348 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003349 // resulting type.
3350 if (Quals.hasObjCLifetime()) {
3351 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3352 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003353 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003354 // Objective-C ARC:
3355 // A lifetime qualifier applied to a substituted template parameter
3356 // overrides the lifetime qualifier from the template argument.
3357 if (const SubstTemplateTypeParmType *SubstTypeParam
3358 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3359 QualType Replacement = SubstTypeParam->getReplacementType();
3360 Qualifiers Qs = Replacement.getQualifiers();
3361 Qs.removeObjCLifetime();
3362 Replacement
3363 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3364 Qs);
3365 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3366 SubstTypeParam->getReplacedParameter(),
3367 Replacement);
3368 TLB.TypeWasModifiedSafely(Result);
3369 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003370 // Otherwise, complain about the addition of a qualifier to an
3371 // already-qualified type.
3372 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003373 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003374 << Result << R;
3375
Douglas Gregore559ca12011-06-17 22:11:49 +00003376 Quals.removeObjCLifetime();
3377 }
3378 }
3379 }
John McCall28654742010-06-05 06:41:15 +00003380 if (!Quals.empty()) {
3381 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3382 TLB.push<QualifiedTypeLoc>(Result);
3383 // No location information to preserve.
3384 }
John McCalla2becad2009-10-21 00:40:46 +00003385
3386 return Result;
3387}
3388
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003389template<typename Derived>
3390TypeLoc
3391TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3392 QualType ObjectType,
3393 NamedDecl *UnqualLookup,
3394 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003395 QualType T = TL.getType();
3396 if (getDerived().AlreadyTransformed(T))
3397 return TL;
3398
3399 TypeLocBuilder TLB;
3400 QualType Result;
3401
3402 if (isa<TemplateSpecializationType>(T)) {
3403 TemplateSpecializationTypeLoc SpecTL
3404 = cast<TemplateSpecializationTypeLoc>(TL);
3405
3406 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003407 getDerived().TransformTemplateName(SS,
3408 SpecTL.getTypePtr()->getTemplateName(),
3409 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003410 ObjectType, UnqualLookup);
3411 if (Template.isNull())
3412 return TypeLoc();
3413
3414 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3415 Template);
3416 } else if (isa<DependentTemplateSpecializationType>(T)) {
3417 DependentTemplateSpecializationTypeLoc SpecTL
3418 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3419
Douglas Gregora88f09f2011-02-28 17:23:35 +00003420 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003421 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003422 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003423 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003424 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003425 if (Template.isNull())
3426 return TypeLoc();
3427
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003428 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003429 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003430 Template,
3431 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003432 } else {
3433 // Nothing special needs to be done for these.
3434 Result = getDerived().TransformType(TLB, TL);
3435 }
3436
3437 if (Result.isNull())
3438 return TypeLoc();
3439
3440 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3441}
3442
Douglas Gregorb71d8212011-03-02 18:32:08 +00003443template<typename Derived>
3444TypeSourceInfo *
3445TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3446 QualType ObjectType,
3447 NamedDecl *UnqualLookup,
3448 CXXScopeSpec &SS) {
3449 // FIXME: Painfully copy-paste from the above!
3450
3451 QualType T = TSInfo->getType();
3452 if (getDerived().AlreadyTransformed(T))
3453 return TSInfo;
3454
3455 TypeLocBuilder TLB;
3456 QualType Result;
3457
3458 TypeLoc TL = TSInfo->getTypeLoc();
3459 if (isa<TemplateSpecializationType>(T)) {
3460 TemplateSpecializationTypeLoc SpecTL
3461 = cast<TemplateSpecializationTypeLoc>(TL);
3462
3463 TemplateName Template
3464 = getDerived().TransformTemplateName(SS,
3465 SpecTL.getTypePtr()->getTemplateName(),
3466 SpecTL.getTemplateNameLoc(),
3467 ObjectType, UnqualLookup);
3468 if (Template.isNull())
3469 return 0;
3470
3471 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3472 Template);
3473 } else if (isa<DependentTemplateSpecializationType>(T)) {
3474 DependentTemplateSpecializationTypeLoc SpecTL
3475 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3476
3477 TemplateName Template
3478 = getDerived().RebuildTemplateName(SS,
3479 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003480 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003481 ObjectType, UnqualLookup);
3482 if (Template.isNull())
3483 return 0;
3484
3485 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3486 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003487 Template,
3488 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003489 } else {
3490 // Nothing special needs to be done for these.
3491 Result = getDerived().TransformType(TLB, TL);
3492 }
3493
3494 if (Result.isNull())
3495 return 0;
3496
3497 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3498}
3499
John McCalla2becad2009-10-21 00:40:46 +00003500template <class TyLoc> static inline
3501QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3502 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3503 NewT.setNameLoc(T.getNameLoc());
3504 return T.getType();
3505}
3506
John McCalla2becad2009-10-21 00:40:46 +00003507template<typename Derived>
3508QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003509 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003510 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3511 NewT.setBuiltinLoc(T.getBuiltinLoc());
3512 if (T.needsExtraLocalData())
3513 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3514 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003515}
Mike Stump1eb44332009-09-09 15:08:12 +00003516
Douglas Gregor577f75a2009-08-04 16:50:30 +00003517template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003518QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003519 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003520 // FIXME: recurse?
3521 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003522}
Mike Stump1eb44332009-09-09 15:08:12 +00003523
Douglas Gregor577f75a2009-08-04 16:50:30 +00003524template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003525QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003526 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003527 QualType PointeeType
3528 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003529 if (PointeeType.isNull())
3530 return QualType();
3531
3532 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003533 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003534 // A dependent pointer type 'T *' has is being transformed such
3535 // that an Objective-C class type is being replaced for 'T'. The
3536 // resulting pointer type is an ObjCObjectPointerType, not a
3537 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003538 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003539
John McCallc12c5bb2010-05-15 11:32:37 +00003540 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3541 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003542 return Result;
3543 }
John McCall43fed0d2010-11-12 08:19:04 +00003544
Douglas Gregor92e986e2010-04-22 16:44:27 +00003545 if (getDerived().AlwaysRebuild() ||
3546 PointeeType != TL.getPointeeLoc().getType()) {
3547 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3548 if (Result.isNull())
3549 return QualType();
3550 }
John McCallf85e1932011-06-15 23:02:42 +00003551
3552 // Objective-C ARC can add lifetime qualifiers to the type that we're
3553 // pointing to.
3554 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3555
Douglas Gregor92e986e2010-04-22 16:44:27 +00003556 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3557 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003558 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003559}
Mike Stump1eb44332009-09-09 15:08:12 +00003560
3561template<typename Derived>
3562QualType
John McCalla2becad2009-10-21 00:40:46 +00003563TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003564 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003565 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003566 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3567 if (PointeeType.isNull())
3568 return QualType();
3569
3570 QualType Result = TL.getType();
3571 if (getDerived().AlwaysRebuild() ||
3572 PointeeType != TL.getPointeeLoc().getType()) {
3573 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003574 TL.getSigilLoc());
3575 if (Result.isNull())
3576 return QualType();
3577 }
3578
Douglas Gregor39968ad2010-04-22 16:50:51 +00003579 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003580 NewT.setSigilLoc(TL.getSigilLoc());
3581 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003582}
3583
John McCall85737a72009-10-30 00:06:24 +00003584/// Transforms a reference type. Note that somewhat paradoxically we
3585/// don't care whether the type itself is an l-value type or an r-value
3586/// type; we only care if the type was *written* as an l-value type
3587/// or an r-value type.
3588template<typename Derived>
3589QualType
3590TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003591 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003592 const ReferenceType *T = TL.getTypePtr();
3593
3594 // Note that this works with the pointee-as-written.
3595 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3596 if (PointeeType.isNull())
3597 return QualType();
3598
3599 QualType Result = TL.getType();
3600 if (getDerived().AlwaysRebuild() ||
3601 PointeeType != T->getPointeeTypeAsWritten()) {
3602 Result = getDerived().RebuildReferenceType(PointeeType,
3603 T->isSpelledAsLValue(),
3604 TL.getSigilLoc());
3605 if (Result.isNull())
3606 return QualType();
3607 }
3608
John McCallf85e1932011-06-15 23:02:42 +00003609 // Objective-C ARC can add lifetime qualifiers to the type that we're
3610 // referring to.
3611 TLB.TypeWasModifiedSafely(
3612 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3613
John McCall85737a72009-10-30 00:06:24 +00003614 // r-value references can be rebuilt as l-value references.
3615 ReferenceTypeLoc NewTL;
3616 if (isa<LValueReferenceType>(Result))
3617 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3618 else
3619 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3620 NewTL.setSigilLoc(TL.getSigilLoc());
3621
3622 return Result;
3623}
3624
Mike Stump1eb44332009-09-09 15:08:12 +00003625template<typename Derived>
3626QualType
John McCalla2becad2009-10-21 00:40:46 +00003627TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003628 LValueReferenceTypeLoc TL) {
3629 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003630}
3631
Mike Stump1eb44332009-09-09 15:08:12 +00003632template<typename Derived>
3633QualType
John McCalla2becad2009-10-21 00:40:46 +00003634TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003635 RValueReferenceTypeLoc TL) {
3636 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003637}
Mike Stump1eb44332009-09-09 15:08:12 +00003638
Douglas Gregor577f75a2009-08-04 16:50:30 +00003639template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003640QualType
John McCalla2becad2009-10-21 00:40:46 +00003641TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003642 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003643 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003644 if (PointeeType.isNull())
3645 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003646
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003647 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3648 TypeSourceInfo* NewClsTInfo = 0;
3649 if (OldClsTInfo) {
3650 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3651 if (!NewClsTInfo)
3652 return QualType();
3653 }
3654
3655 const MemberPointerType *T = TL.getTypePtr();
3656 QualType OldClsType = QualType(T->getClass(), 0);
3657 QualType NewClsType;
3658 if (NewClsTInfo)
3659 NewClsType = NewClsTInfo->getType();
3660 else {
3661 NewClsType = getDerived().TransformType(OldClsType);
3662 if (NewClsType.isNull())
3663 return QualType();
3664 }
Mike Stump1eb44332009-09-09 15:08:12 +00003665
John McCalla2becad2009-10-21 00:40:46 +00003666 QualType Result = TL.getType();
3667 if (getDerived().AlwaysRebuild() ||
3668 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003669 NewClsType != OldClsType) {
3670 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003671 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003672 if (Result.isNull())
3673 return QualType();
3674 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003675
John McCalla2becad2009-10-21 00:40:46 +00003676 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3677 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003678 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003679
3680 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003681}
3682
Mike Stump1eb44332009-09-09 15:08:12 +00003683template<typename Derived>
3684QualType
John McCalla2becad2009-10-21 00:40:46 +00003685TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003686 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003687 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003688 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003689 if (ElementType.isNull())
3690 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003691
John McCalla2becad2009-10-21 00:40:46 +00003692 QualType Result = TL.getType();
3693 if (getDerived().AlwaysRebuild() ||
3694 ElementType != T->getElementType()) {
3695 Result = getDerived().RebuildConstantArrayType(ElementType,
3696 T->getSizeModifier(),
3697 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003698 T->getIndexTypeCVRQualifiers(),
3699 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003700 if (Result.isNull())
3701 return QualType();
3702 }
Eli Friedman457a3772012-01-25 22:19:07 +00003703
3704 // We might have either a ConstantArrayType or a VariableArrayType now:
3705 // a ConstantArrayType is allowed to have an element type which is a
3706 // VariableArrayType if the type is dependent. Fortunately, all array
3707 // types have the same location layout.
3708 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003709 NewTL.setLBracketLoc(TL.getLBracketLoc());
3710 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003711
John McCalla2becad2009-10-21 00:40:46 +00003712 Expr *Size = TL.getSizeExpr();
3713 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003714 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3715 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003716 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003717 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003718 }
3719 NewTL.setSizeExpr(Size);
3720
3721 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003722}
Mike Stump1eb44332009-09-09 15:08:12 +00003723
Douglas Gregor577f75a2009-08-04 16:50:30 +00003724template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003725QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003726 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003727 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003728 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003729 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003730 if (ElementType.isNull())
3731 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003732
John McCalla2becad2009-10-21 00:40:46 +00003733 QualType Result = TL.getType();
3734 if (getDerived().AlwaysRebuild() ||
3735 ElementType != T->getElementType()) {
3736 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003737 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003738 T->getIndexTypeCVRQualifiers(),
3739 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003740 if (Result.isNull())
3741 return QualType();
3742 }
Sean Huntc3021132010-05-05 15:23:54 +00003743
John McCalla2becad2009-10-21 00:40:46 +00003744 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3745 NewTL.setLBracketLoc(TL.getLBracketLoc());
3746 NewTL.setRBracketLoc(TL.getRBracketLoc());
3747 NewTL.setSizeExpr(0);
3748
3749 return Result;
3750}
3751
3752template<typename Derived>
3753QualType
3754TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003755 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003756 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003757 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3758 if (ElementType.isNull())
3759 return QualType();
3760
John McCall60d7b3a2010-08-24 06:29:42 +00003761 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003762 = getDerived().TransformExpr(T->getSizeExpr());
3763 if (SizeResult.isInvalid())
3764 return QualType();
3765
John McCall9ae2f072010-08-23 23:25:46 +00003766 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003767
3768 QualType Result = TL.getType();
3769 if (getDerived().AlwaysRebuild() ||
3770 ElementType != T->getElementType() ||
3771 Size != T->getSizeExpr()) {
3772 Result = getDerived().RebuildVariableArrayType(ElementType,
3773 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003774 Size,
John McCalla2becad2009-10-21 00:40:46 +00003775 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003776 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003777 if (Result.isNull())
3778 return QualType();
3779 }
Sean Huntc3021132010-05-05 15:23:54 +00003780
John McCalla2becad2009-10-21 00:40:46 +00003781 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3782 NewTL.setLBracketLoc(TL.getLBracketLoc());
3783 NewTL.setRBracketLoc(TL.getRBracketLoc());
3784 NewTL.setSizeExpr(Size);
3785
3786 return Result;
3787}
3788
3789template<typename Derived>
3790QualType
3791TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003792 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003793 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003794 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3795 if (ElementType.isNull())
3796 return QualType();
3797
Richard Smithf6702a32011-12-20 02:08:33 +00003798 // Array bounds are constant expressions.
3799 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3800 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003801
John McCall3b657512011-01-19 10:06:00 +00003802 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3803 Expr *origSize = TL.getSizeExpr();
3804 if (!origSize) origSize = T->getSizeExpr();
3805
3806 ExprResult sizeResult
3807 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003808 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003809 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003810 return QualType();
3811
John McCall3b657512011-01-19 10:06:00 +00003812 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003813
3814 QualType Result = TL.getType();
3815 if (getDerived().AlwaysRebuild() ||
3816 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003817 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003818 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3819 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003820 size,
John McCalla2becad2009-10-21 00:40:46 +00003821 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003822 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003823 if (Result.isNull())
3824 return QualType();
3825 }
John McCalla2becad2009-10-21 00:40:46 +00003826
3827 // We might have any sort of array type now, but fortunately they
3828 // all have the same location layout.
3829 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3830 NewTL.setLBracketLoc(TL.getLBracketLoc());
3831 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003832 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003833
3834 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003835}
Mike Stump1eb44332009-09-09 15:08:12 +00003836
3837template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003838QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003839 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003840 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003841 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003842
3843 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003844 QualType ElementType = getDerived().TransformType(T->getElementType());
3845 if (ElementType.isNull())
3846 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003847
Richard Smithf6702a32011-12-20 02:08:33 +00003848 // Vector sizes are constant expressions.
3849 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3850 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003851
John McCall60d7b3a2010-08-24 06:29:42 +00003852 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003853 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003854 if (Size.isInvalid())
3855 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003856
John McCalla2becad2009-10-21 00:40:46 +00003857 QualType Result = TL.getType();
3858 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003859 ElementType != T->getElementType() ||
3860 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003861 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003862 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003863 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003864 if (Result.isNull())
3865 return QualType();
3866 }
John McCalla2becad2009-10-21 00:40:46 +00003867
3868 // Result might be dependent or not.
3869 if (isa<DependentSizedExtVectorType>(Result)) {
3870 DependentSizedExtVectorTypeLoc NewTL
3871 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3872 NewTL.setNameLoc(TL.getNameLoc());
3873 } else {
3874 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3875 NewTL.setNameLoc(TL.getNameLoc());
3876 }
3877
3878 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003879}
Mike Stump1eb44332009-09-09 15:08:12 +00003880
3881template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003882QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003883 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003884 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003885 QualType ElementType = getDerived().TransformType(T->getElementType());
3886 if (ElementType.isNull())
3887 return QualType();
3888
John McCalla2becad2009-10-21 00:40:46 +00003889 QualType Result = TL.getType();
3890 if (getDerived().AlwaysRebuild() ||
3891 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003892 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003893 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003894 if (Result.isNull())
3895 return QualType();
3896 }
Sean Huntc3021132010-05-05 15:23:54 +00003897
John McCalla2becad2009-10-21 00:40:46 +00003898 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3899 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003900
John McCalla2becad2009-10-21 00:40:46 +00003901 return Result;
3902}
3903
3904template<typename Derived>
3905QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003906 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003907 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003908 QualType ElementType = getDerived().TransformType(T->getElementType());
3909 if (ElementType.isNull())
3910 return QualType();
3911
3912 QualType Result = TL.getType();
3913 if (getDerived().AlwaysRebuild() ||
3914 ElementType != T->getElementType()) {
3915 Result = getDerived().RebuildExtVectorType(ElementType,
3916 T->getNumElements(),
3917 /*FIXME*/ SourceLocation());
3918 if (Result.isNull())
3919 return QualType();
3920 }
Sean Huntc3021132010-05-05 15:23:54 +00003921
John McCalla2becad2009-10-21 00:40:46 +00003922 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3923 NewTL.setNameLoc(TL.getNameLoc());
3924
3925 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003926}
Mike Stump1eb44332009-09-09 15:08:12 +00003927
3928template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003929ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003930TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003931 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003932 llvm::Optional<unsigned> NumExpansions,
3933 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003934 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003935 TypeSourceInfo *NewDI = 0;
3936
3937 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3938 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003939 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003940 TypeLoc OldTL = OldDI->getTypeLoc();
3941 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3942
3943 TypeLocBuilder TLB;
3944 TypeLoc NewTL = OldDI->getTypeLoc();
3945 TLB.reserve(NewTL.getFullDataSize());
3946
3947 QualType Result = getDerived().TransformType(TLB,
3948 OldExpansionTL.getPatternLoc());
3949 if (Result.isNull())
3950 return 0;
3951
3952 Result = RebuildPackExpansionType(Result,
3953 OldExpansionTL.getPatternLoc().getSourceRange(),
3954 OldExpansionTL.getEllipsisLoc(),
3955 NumExpansions);
3956 if (Result.isNull())
3957 return 0;
3958
3959 PackExpansionTypeLoc NewExpansionTL
3960 = TLB.push<PackExpansionTypeLoc>(Result);
3961 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3962 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3963 } else
3964 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003965 if (!NewDI)
3966 return 0;
3967
John McCallfb44de92011-05-01 22:35:37 +00003968 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003969 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003970
3971 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3972 OldParm->getDeclContext(),
3973 OldParm->getInnerLocStart(),
3974 OldParm->getLocation(),
3975 OldParm->getIdentifier(),
3976 NewDI->getType(),
3977 NewDI,
3978 OldParm->getStorageClass(),
3979 OldParm->getStorageClassAsWritten(),
3980 /* DefArg */ NULL);
3981 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3982 OldParm->getFunctionScopeIndex() + indexAdjustment);
3983 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003984}
3985
3986template<typename Derived>
3987bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003988 TransformFunctionTypeParams(SourceLocation Loc,
3989 ParmVarDecl **Params, unsigned NumParams,
3990 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003991 SmallVectorImpl<QualType> &OutParamTypes,
3992 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003993 int indexAdjustment = 0;
3994
Douglas Gregora009b592011-01-07 00:20:55 +00003995 for (unsigned i = 0; i != NumParams; ++i) {
3996 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003997 assert(OldParm->getFunctionScopeIndex() == i);
3998
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003999 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004000 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004001 if (OldParm->isParameterPack()) {
4002 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004003 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004004
Douglas Gregor603cfb42011-01-05 23:12:31 +00004005 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004006 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4007 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
4008 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4009 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004010 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4011
Douglas Gregor603cfb42011-01-05 23:12:31 +00004012 // Determine whether we should expand the parameter packs.
4013 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004014 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004015 llvm::Optional<unsigned> OrigNumExpansions
4016 = ExpansionTL.getTypePtr()->getNumExpansions();
4017 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004018 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4019 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004020 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004021 ShouldExpand,
4022 RetainExpansion,
4023 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004024 return true;
4025 }
4026
4027 if (ShouldExpand) {
4028 // Expand the function parameter pack into multiple, separate
4029 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004030 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004031 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004032 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4033 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004034 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004035 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004036 OrigNumExpansions,
4037 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004038 if (!NewParm)
4039 return true;
4040
Douglas Gregora009b592011-01-07 00:20:55 +00004041 OutParamTypes.push_back(NewParm->getType());
4042 if (PVars)
4043 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004044 }
Douglas Gregord3731192011-01-10 07:32:04 +00004045
4046 // If we're supposed to retain a pack expansion, do so by temporarily
4047 // forgetting the partially-substituted parameter pack.
4048 if (RetainExpansion) {
4049 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4050 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004051 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004052 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004053 OrigNumExpansions,
4054 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004055 if (!NewParm)
4056 return true;
4057
4058 OutParamTypes.push_back(NewParm->getType());
4059 if (PVars)
4060 PVars->push_back(NewParm);
4061 }
4062
John McCallfb44de92011-05-01 22:35:37 +00004063 // The next parameter should have the same adjustment as the
4064 // last thing we pushed, but we post-incremented indexAdjustment
4065 // on every push. Also, if we push nothing, the adjustment should
4066 // go down by one.
4067 indexAdjustment--;
4068
Douglas Gregor603cfb42011-01-05 23:12:31 +00004069 // We're done with the pack expansion.
4070 continue;
4071 }
4072
4073 // We'll substitute the parameter now without expanding the pack
4074 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004075 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4076 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004077 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004078 NumExpansions,
4079 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004080 } else {
4081 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004082 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004083 llvm::Optional<unsigned>(),
4084 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004085 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004086
John McCall21ef0fa2010-03-11 09:03:00 +00004087 if (!NewParm)
4088 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004089
Douglas Gregora009b592011-01-07 00:20:55 +00004090 OutParamTypes.push_back(NewParm->getType());
4091 if (PVars)
4092 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004093 continue;
4094 }
John McCall21ef0fa2010-03-11 09:03:00 +00004095
4096 // Deal with the possibility that we don't have a parameter
4097 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004098 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004099 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004100 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004101 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004102 if (const PackExpansionType *Expansion
4103 = dyn_cast<PackExpansionType>(OldType)) {
4104 // We have a function parameter pack that may need to be expanded.
4105 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004106 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004107 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4108
4109 // Determine whether we should expand the parameter packs.
4110 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004111 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004112 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004113 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004114 ShouldExpand,
4115 RetainExpansion,
4116 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004117 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004118 }
4119
4120 if (ShouldExpand) {
4121 // Expand the function parameter pack into multiple, separate
4122 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004123 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004124 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4125 QualType NewType = getDerived().TransformType(Pattern);
4126 if (NewType.isNull())
4127 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004128
Douglas Gregora009b592011-01-07 00:20:55 +00004129 OutParamTypes.push_back(NewType);
4130 if (PVars)
4131 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004132 }
4133
4134 // We're done with the pack expansion.
4135 continue;
4136 }
4137
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004138 // If we're supposed to retain a pack expansion, do so by temporarily
4139 // forgetting the partially-substituted parameter pack.
4140 if (RetainExpansion) {
4141 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4142 QualType NewType = getDerived().TransformType(Pattern);
4143 if (NewType.isNull())
4144 return true;
4145
4146 OutParamTypes.push_back(NewType);
4147 if (PVars)
4148 PVars->push_back(0);
4149 }
Douglas Gregord3731192011-01-10 07:32:04 +00004150
Douglas Gregor603cfb42011-01-05 23:12:31 +00004151 // We'll substitute the parameter now without expanding the pack
4152 // expansion.
4153 OldType = Expansion->getPattern();
4154 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004155 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4156 NewType = getDerived().TransformType(OldType);
4157 } else {
4158 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004159 }
4160
Douglas Gregor603cfb42011-01-05 23:12:31 +00004161 if (NewType.isNull())
4162 return true;
4163
4164 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004165 NewType = getSema().Context.getPackExpansionType(NewType,
4166 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004167
Douglas Gregora009b592011-01-07 00:20:55 +00004168 OutParamTypes.push_back(NewType);
4169 if (PVars)
4170 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004171 }
4172
John McCallfb44de92011-05-01 22:35:37 +00004173#ifndef NDEBUG
4174 if (PVars) {
4175 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4176 if (ParmVarDecl *parm = (*PVars)[i])
4177 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004178 }
John McCallfb44de92011-05-01 22:35:37 +00004179#endif
4180
4181 return false;
4182}
John McCall21ef0fa2010-03-11 09:03:00 +00004183
4184template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004185QualType
John McCalla2becad2009-10-21 00:40:46 +00004186TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004187 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004188 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4189}
4190
4191template<typename Derived>
4192QualType
4193TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4194 FunctionProtoTypeLoc TL,
4195 CXXRecordDecl *ThisContext,
4196 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004197 // Transform the parameters and return type.
4198 //
Richard Smithe6975e92012-04-17 00:58:00 +00004199 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004200 // When the function has a trailing return type, we instantiate the
4201 // parameters before the return type, since the return type can then refer
4202 // to the parameters themselves (via decltype, sizeof, etc.).
4203 //
Chris Lattner686775d2011-07-20 06:58:45 +00004204 SmallVector<QualType, 4> ParamTypes;
4205 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004206 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004207
Douglas Gregordab60ad2010-10-01 18:44:50 +00004208 QualType ResultType;
4209
4210 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004211 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4212 TL.getParmArray(),
4213 TL.getNumArgs(),
4214 TL.getTypePtr()->arg_type_begin(),
4215 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004216 return QualType();
4217
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004218 {
4219 // C++11 [expr.prim.general]p3:
4220 // If a declaration declares a member function or member function
4221 // template of a class X, the expression this is a prvalue of type
4222 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
4223 // and the end of the function-definition, member-declarator, or
4224 // declarator.
4225 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
4226
4227 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4228 if (ResultType.isNull())
4229 return QualType();
4230 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004231 }
4232 else {
4233 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4234 if (ResultType.isNull())
4235 return QualType();
4236
Douglas Gregora009b592011-01-07 00:20:55 +00004237 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4238 TL.getParmArray(),
4239 TL.getNumArgs(),
4240 TL.getTypePtr()->arg_type_begin(),
4241 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004242 return QualType();
4243 }
4244
Richard Smithe6975e92012-04-17 00:58:00 +00004245 // FIXME: Need to transform the exception-specification too.
4246
John McCalla2becad2009-10-21 00:40:46 +00004247 QualType Result = TL.getType();
4248 if (getDerived().AlwaysRebuild() ||
4249 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004250 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004251 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4252 Result = getDerived().RebuildFunctionProtoType(ResultType,
4253 ParamTypes.data(),
4254 ParamTypes.size(),
4255 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004256 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004257 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004258 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004259 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004260 if (Result.isNull())
4261 return QualType();
4262 }
Mike Stump1eb44332009-09-09 15:08:12 +00004263
John McCalla2becad2009-10-21 00:40:46 +00004264 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004265 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4266 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004267 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004268 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4269 NewTL.setArg(i, ParamDecls[i]);
4270
4271 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004272}
Mike Stump1eb44332009-09-09 15:08:12 +00004273
Douglas Gregor577f75a2009-08-04 16:50:30 +00004274template<typename Derived>
4275QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004276 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004277 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004278 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004279 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4280 if (ResultType.isNull())
4281 return QualType();
4282
4283 QualType Result = TL.getType();
4284 if (getDerived().AlwaysRebuild() ||
4285 ResultType != T->getResultType())
4286 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4287
4288 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004289 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4290 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004291 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004292
4293 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004294}
Mike Stump1eb44332009-09-09 15:08:12 +00004295
John McCalled976492009-12-04 22:46:56 +00004296template<typename Derived> QualType
4297TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004298 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004299 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004300 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004301 if (!D)
4302 return QualType();
4303
4304 QualType Result = TL.getType();
4305 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4306 Result = getDerived().RebuildUnresolvedUsingType(D);
4307 if (Result.isNull())
4308 return QualType();
4309 }
4310
4311 // We might get an arbitrary type spec type back. We should at
4312 // least always get a type spec type, though.
4313 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4314 NewTL.setNameLoc(TL.getNameLoc());
4315
4316 return Result;
4317}
4318
Douglas Gregor577f75a2009-08-04 16:50:30 +00004319template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004320QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004321 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004322 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004323 TypedefNameDecl *Typedef
4324 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4325 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004326 if (!Typedef)
4327 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004328
John McCalla2becad2009-10-21 00:40:46 +00004329 QualType Result = TL.getType();
4330 if (getDerived().AlwaysRebuild() ||
4331 Typedef != T->getDecl()) {
4332 Result = getDerived().RebuildTypedefType(Typedef);
4333 if (Result.isNull())
4334 return QualType();
4335 }
Mike Stump1eb44332009-09-09 15:08:12 +00004336
John McCalla2becad2009-10-21 00:40:46 +00004337 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4338 NewTL.setNameLoc(TL.getNameLoc());
4339
4340 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004341}
Mike Stump1eb44332009-09-09 15:08:12 +00004342
Douglas Gregor577f75a2009-08-04 16:50:30 +00004343template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004344QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004345 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004346 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004347 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004348
John McCall60d7b3a2010-08-24 06:29:42 +00004349 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004350 if (E.isInvalid())
4351 return QualType();
4352
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004353 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4354 if (E.isInvalid())
4355 return QualType();
4356
John McCalla2becad2009-10-21 00:40:46 +00004357 QualType Result = TL.getType();
4358 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004359 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004360 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004361 if (Result.isNull())
4362 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004363 }
John McCalla2becad2009-10-21 00:40:46 +00004364 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004365
John McCalla2becad2009-10-21 00:40:46 +00004366 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004367 NewTL.setTypeofLoc(TL.getTypeofLoc());
4368 NewTL.setLParenLoc(TL.getLParenLoc());
4369 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004370
4371 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004372}
Mike Stump1eb44332009-09-09 15:08:12 +00004373
4374template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004375QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004376 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004377 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4378 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4379 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004380 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004381
John McCalla2becad2009-10-21 00:40:46 +00004382 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004383 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4384 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004385 if (Result.isNull())
4386 return QualType();
4387 }
Mike Stump1eb44332009-09-09 15:08:12 +00004388
John McCalla2becad2009-10-21 00:40:46 +00004389 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004390 NewTL.setTypeofLoc(TL.getTypeofLoc());
4391 NewTL.setLParenLoc(TL.getLParenLoc());
4392 NewTL.setRParenLoc(TL.getRParenLoc());
4393 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004394
4395 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004396}
Mike Stump1eb44332009-09-09 15:08:12 +00004397
4398template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004399QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004400 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004401 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004402
Douglas Gregor670444e2009-08-04 22:27:00 +00004403 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004404 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4405 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004406
John McCall60d7b3a2010-08-24 06:29:42 +00004407 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004408 if (E.isInvalid())
4409 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004410
Richard Smith76f3f692012-02-22 02:04:18 +00004411 E = getSema().ActOnDecltypeExpression(E.take());
4412 if (E.isInvalid())
4413 return QualType();
4414
John McCalla2becad2009-10-21 00:40:46 +00004415 QualType Result = TL.getType();
4416 if (getDerived().AlwaysRebuild() ||
4417 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004418 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004419 if (Result.isNull())
4420 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004421 }
John McCalla2becad2009-10-21 00:40:46 +00004422 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004423
John McCalla2becad2009-10-21 00:40:46 +00004424 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4425 NewTL.setNameLoc(TL.getNameLoc());
4426
4427 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004428}
4429
4430template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004431QualType TreeTransform<Derived>::TransformUnaryTransformType(
4432 TypeLocBuilder &TLB,
4433 UnaryTransformTypeLoc TL) {
4434 QualType Result = TL.getType();
4435 if (Result->isDependentType()) {
4436 const UnaryTransformType *T = TL.getTypePtr();
4437 QualType NewBase =
4438 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4439 Result = getDerived().RebuildUnaryTransformType(NewBase,
4440 T->getUTTKind(),
4441 TL.getKWLoc());
4442 if (Result.isNull())
4443 return QualType();
4444 }
4445
4446 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4447 NewTL.setKWLoc(TL.getKWLoc());
4448 NewTL.setParensRange(TL.getParensRange());
4449 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4450 return Result;
4451}
4452
4453template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004454QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4455 AutoTypeLoc TL) {
4456 const AutoType *T = TL.getTypePtr();
4457 QualType OldDeduced = T->getDeducedType();
4458 QualType NewDeduced;
4459 if (!OldDeduced.isNull()) {
4460 NewDeduced = getDerived().TransformType(OldDeduced);
4461 if (NewDeduced.isNull())
4462 return QualType();
4463 }
4464
4465 QualType Result = TL.getType();
4466 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4467 Result = getDerived().RebuildAutoType(NewDeduced);
4468 if (Result.isNull())
4469 return QualType();
4470 }
4471
4472 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4473 NewTL.setNameLoc(TL.getNameLoc());
4474
4475 return Result;
4476}
4477
4478template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004479QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004480 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004481 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004482 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004483 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4484 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004485 if (!Record)
4486 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004487
John McCalla2becad2009-10-21 00:40:46 +00004488 QualType Result = TL.getType();
4489 if (getDerived().AlwaysRebuild() ||
4490 Record != T->getDecl()) {
4491 Result = getDerived().RebuildRecordType(Record);
4492 if (Result.isNull())
4493 return QualType();
4494 }
Mike Stump1eb44332009-09-09 15:08:12 +00004495
John McCalla2becad2009-10-21 00:40:46 +00004496 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4497 NewTL.setNameLoc(TL.getNameLoc());
4498
4499 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004500}
Mike Stump1eb44332009-09-09 15:08:12 +00004501
4502template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004503QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004504 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004505 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004506 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004507 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4508 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004509 if (!Enum)
4510 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004511
John McCalla2becad2009-10-21 00:40:46 +00004512 QualType Result = TL.getType();
4513 if (getDerived().AlwaysRebuild() ||
4514 Enum != T->getDecl()) {
4515 Result = getDerived().RebuildEnumType(Enum);
4516 if (Result.isNull())
4517 return QualType();
4518 }
Mike Stump1eb44332009-09-09 15:08:12 +00004519
John McCalla2becad2009-10-21 00:40:46 +00004520 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4521 NewTL.setNameLoc(TL.getNameLoc());
4522
4523 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004524}
John McCall7da24312009-09-05 00:15:47 +00004525
John McCall3cb0ebd2010-03-10 03:28:59 +00004526template<typename Derived>
4527QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4528 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004529 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004530 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4531 TL.getTypePtr()->getDecl());
4532 if (!D) return QualType();
4533
4534 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4535 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4536 return T;
4537}
4538
Douglas Gregor577f75a2009-08-04 16:50:30 +00004539template<typename Derived>
4540QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004541 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004542 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004543 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004544}
4545
Mike Stump1eb44332009-09-09 15:08:12 +00004546template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004547QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004548 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004549 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004550 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4551
4552 // Substitute into the replacement type, which itself might involve something
4553 // that needs to be transformed. This only tends to occur with default
4554 // template arguments of template template parameters.
4555 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4556 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4557 if (Replacement.isNull())
4558 return QualType();
4559
4560 // Always canonicalize the replacement type.
4561 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4562 QualType Result
4563 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4564 Replacement);
4565
4566 // Propagate type-source information.
4567 SubstTemplateTypeParmTypeLoc NewTL
4568 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4569 NewTL.setNameLoc(TL.getNameLoc());
4570 return Result;
4571
John McCall49a832b2009-10-18 09:09:24 +00004572}
4573
4574template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004575QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4576 TypeLocBuilder &TLB,
4577 SubstTemplateTypeParmPackTypeLoc TL) {
4578 return TransformTypeSpecType(TLB, TL);
4579}
4580
4581template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004582QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004583 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004584 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004585 const TemplateSpecializationType *T = TL.getTypePtr();
4586
Douglas Gregor1d752d72011-03-02 18:46:51 +00004587 // The nested-name-specifier never matters in a TemplateSpecializationType,
4588 // because we can't have a dependent nested-name-specifier anyway.
4589 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004590 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004591 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4592 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004593 if (Template.isNull())
4594 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004595
John McCall43fed0d2010-11-12 08:19:04 +00004596 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4597}
4598
Eli Friedmanb001de72011-10-06 23:00:33 +00004599template<typename Derived>
4600QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4601 AtomicTypeLoc TL) {
4602 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4603 if (ValueType.isNull())
4604 return QualType();
4605
4606 QualType Result = TL.getType();
4607 if (getDerived().AlwaysRebuild() ||
4608 ValueType != TL.getValueLoc().getType()) {
4609 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4610 if (Result.isNull())
4611 return QualType();
4612 }
4613
4614 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4615 NewTL.setKWLoc(TL.getKWLoc());
4616 NewTL.setLParenLoc(TL.getLParenLoc());
4617 NewTL.setRParenLoc(TL.getRParenLoc());
4618
4619 return Result;
4620}
4621
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004622namespace {
4623 /// \brief Simple iterator that traverses the template arguments in a
4624 /// container that provides a \c getArgLoc() member function.
4625 ///
4626 /// This iterator is intended to be used with the iterator form of
4627 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4628 template<typename ArgLocContainer>
4629 class TemplateArgumentLocContainerIterator {
4630 ArgLocContainer *Container;
4631 unsigned Index;
4632
4633 public:
4634 typedef TemplateArgumentLoc value_type;
4635 typedef TemplateArgumentLoc reference;
4636 typedef int difference_type;
4637 typedef std::input_iterator_tag iterator_category;
4638
4639 class pointer {
4640 TemplateArgumentLoc Arg;
4641
4642 public:
4643 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4644
4645 const TemplateArgumentLoc *operator->() const {
4646 return &Arg;
4647 }
4648 };
4649
4650
4651 TemplateArgumentLocContainerIterator() {}
4652
4653 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4654 unsigned Index)
4655 : Container(&Container), Index(Index) { }
4656
4657 TemplateArgumentLocContainerIterator &operator++() {
4658 ++Index;
4659 return *this;
4660 }
4661
4662 TemplateArgumentLocContainerIterator operator++(int) {
4663 TemplateArgumentLocContainerIterator Old(*this);
4664 ++(*this);
4665 return Old;
4666 }
4667
4668 TemplateArgumentLoc operator*() const {
4669 return Container->getArgLoc(Index);
4670 }
4671
4672 pointer operator->() const {
4673 return pointer(Container->getArgLoc(Index));
4674 }
4675
4676 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004677 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004678 return X.Container == Y.Container && X.Index == Y.Index;
4679 }
4680
4681 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004682 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004683 return !(X == Y);
4684 }
4685 };
4686}
4687
4688
John McCall43fed0d2010-11-12 08:19:04 +00004689template <typename Derived>
4690QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4691 TypeLocBuilder &TLB,
4692 TemplateSpecializationTypeLoc TL,
4693 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004694 TemplateArgumentListInfo NewTemplateArgs;
4695 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4696 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004697 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4698 ArgIterator;
4699 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4700 ArgIterator(TL, TL.getNumArgs()),
4701 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004702 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004703
John McCall833ca992009-10-29 08:12:44 +00004704 // FIXME: maybe don't rebuild if all the template arguments are the same.
4705
4706 QualType Result =
4707 getDerived().RebuildTemplateSpecializationType(Template,
4708 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004709 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004710
4711 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004712 // Specializations of template template parameters are represented as
4713 // TemplateSpecializationTypes, and substitution of type alias templates
4714 // within a dependent context can transform them into
4715 // DependentTemplateSpecializationTypes.
4716 if (isa<DependentTemplateSpecializationType>(Result)) {
4717 DependentTemplateSpecializationTypeLoc NewTL
4718 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004719 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004720 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004721 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004722 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004723 NewTL.setLAngleLoc(TL.getLAngleLoc());
4724 NewTL.setRAngleLoc(TL.getRAngleLoc());
4725 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4726 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4727 return Result;
4728 }
4729
John McCall833ca992009-10-29 08:12:44 +00004730 TemplateSpecializationTypeLoc NewTL
4731 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004732 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004733 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4734 NewTL.setLAngleLoc(TL.getLAngleLoc());
4735 NewTL.setRAngleLoc(TL.getRAngleLoc());
4736 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4737 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004738 }
Mike Stump1eb44332009-09-09 15:08:12 +00004739
John McCall833ca992009-10-29 08:12:44 +00004740 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004741}
Mike Stump1eb44332009-09-09 15:08:12 +00004742
Douglas Gregora88f09f2011-02-28 17:23:35 +00004743template <typename Derived>
4744QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4745 TypeLocBuilder &TLB,
4746 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004747 TemplateName Template,
4748 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004749 TemplateArgumentListInfo NewTemplateArgs;
4750 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4751 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4752 typedef TemplateArgumentLocContainerIterator<
4753 DependentTemplateSpecializationTypeLoc> ArgIterator;
4754 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4755 ArgIterator(TL, TL.getNumArgs()),
4756 NewTemplateArgs))
4757 return QualType();
4758
4759 // FIXME: maybe don't rebuild if all the template arguments are the same.
4760
4761 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4762 QualType Result
4763 = getSema().Context.getDependentTemplateSpecializationType(
4764 TL.getTypePtr()->getKeyword(),
4765 DTN->getQualifier(),
4766 DTN->getIdentifier(),
4767 NewTemplateArgs);
4768
4769 DependentTemplateSpecializationTypeLoc NewTL
4770 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004771 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004772 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004773 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004774 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004775 NewTL.setLAngleLoc(TL.getLAngleLoc());
4776 NewTL.setRAngleLoc(TL.getRAngleLoc());
4777 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4778 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4779 return Result;
4780 }
4781
4782 QualType Result
4783 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004784 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004785 NewTemplateArgs);
4786
4787 if (!Result.isNull()) {
4788 /// FIXME: Wrap this in an elaborated-type-specifier?
4789 TemplateSpecializationTypeLoc NewTL
4790 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004791 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004792 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004793 NewTL.setLAngleLoc(TL.getLAngleLoc());
4794 NewTL.setRAngleLoc(TL.getRAngleLoc());
4795 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4796 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4797 }
4798
4799 return Result;
4800}
4801
Mike Stump1eb44332009-09-09 15:08:12 +00004802template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004803QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004804TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004805 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004806 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004807
Douglas Gregor9e876872011-03-01 18:12:44 +00004808 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004809 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004810 if (TL.getQualifierLoc()) {
4811 QualifierLoc
4812 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4813 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004814 return QualType();
4815 }
Mike Stump1eb44332009-09-09 15:08:12 +00004816
John McCall43fed0d2010-11-12 08:19:04 +00004817 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4818 if (NamedT.isNull())
4819 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004820
Richard Smith3e4c6c42011-05-05 21:57:07 +00004821 // C++0x [dcl.type.elab]p2:
4822 // If the identifier resolves to a typedef-name or the simple-template-id
4823 // resolves to an alias template specialization, the
4824 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004825 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4826 if (const TemplateSpecializationType *TST =
4827 NamedT->getAs<TemplateSpecializationType>()) {
4828 TemplateName Template = TST->getTemplateName();
4829 if (TypeAliasTemplateDecl *TAT =
4830 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4831 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4832 diag::err_tag_reference_non_tag) << 4;
4833 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4834 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004835 }
4836 }
4837
John McCalla2becad2009-10-21 00:40:46 +00004838 QualType Result = TL.getType();
4839 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004840 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004841 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004842 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004843 T->getKeyword(),
4844 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004845 if (Result.isNull())
4846 return QualType();
4847 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004848
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004849 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004850 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004851 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004852 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004853}
Mike Stump1eb44332009-09-09 15:08:12 +00004854
4855template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004856QualType TreeTransform<Derived>::TransformAttributedType(
4857 TypeLocBuilder &TLB,
4858 AttributedTypeLoc TL) {
4859 const AttributedType *oldType = TL.getTypePtr();
4860 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4861 if (modifiedType.isNull())
4862 return QualType();
4863
4864 QualType result = TL.getType();
4865
4866 // FIXME: dependent operand expressions?
4867 if (getDerived().AlwaysRebuild() ||
4868 modifiedType != oldType->getModifiedType()) {
4869 // TODO: this is really lame; we should really be rebuilding the
4870 // equivalent type from first principles.
4871 QualType equivalentType
4872 = getDerived().TransformType(oldType->getEquivalentType());
4873 if (equivalentType.isNull())
4874 return QualType();
4875 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4876 modifiedType,
4877 equivalentType);
4878 }
4879
4880 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4881 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4882 if (TL.hasAttrOperand())
4883 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4884 if (TL.hasAttrExprOperand())
4885 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4886 else if (TL.hasAttrEnumOperand())
4887 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4888
4889 return result;
4890}
4891
4892template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004893QualType
4894TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4895 ParenTypeLoc TL) {
4896 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4897 if (Inner.isNull())
4898 return QualType();
4899
4900 QualType Result = TL.getType();
4901 if (getDerived().AlwaysRebuild() ||
4902 Inner != TL.getInnerLoc().getType()) {
4903 Result = getDerived().RebuildParenType(Inner);
4904 if (Result.isNull())
4905 return QualType();
4906 }
4907
4908 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4909 NewTL.setLParenLoc(TL.getLParenLoc());
4910 NewTL.setRParenLoc(TL.getRParenLoc());
4911 return Result;
4912}
4913
4914template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004915QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004916 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004917 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004918
Douglas Gregor2494dd02011-03-01 01:34:45 +00004919 NestedNameSpecifierLoc QualifierLoc
4920 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4921 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004922 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004923
John McCall33500952010-06-11 00:33:02 +00004924 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004925 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004926 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004927 QualifierLoc,
4928 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004929 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004930 if (Result.isNull())
4931 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004932
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004933 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4934 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004935 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4936
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004937 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004938 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004939 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004940 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004941 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004942 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004943 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004944 NewTL.setNameLoc(TL.getNameLoc());
4945 }
John McCalla2becad2009-10-21 00:40:46 +00004946 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004947}
Mike Stump1eb44332009-09-09 15:08:12 +00004948
Douglas Gregor577f75a2009-08-04 16:50:30 +00004949template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004950QualType TreeTransform<Derived>::
4951 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004952 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004953 NestedNameSpecifierLoc QualifierLoc;
4954 if (TL.getQualifierLoc()) {
4955 QualifierLoc
4956 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4957 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004958 return QualType();
4959 }
4960
John McCall43fed0d2010-11-12 08:19:04 +00004961 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004962 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004963}
4964
4965template<typename Derived>
4966QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004967TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4968 DependentTemplateSpecializationTypeLoc TL,
4969 NestedNameSpecifierLoc QualifierLoc) {
4970 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4971
4972 TemplateArgumentListInfo NewTemplateArgs;
4973 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4974 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4975
4976 typedef TemplateArgumentLocContainerIterator<
4977 DependentTemplateSpecializationTypeLoc> ArgIterator;
4978 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4979 ArgIterator(TL, TL.getNumArgs()),
4980 NewTemplateArgs))
4981 return QualType();
4982
4983 QualType Result
4984 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4985 QualifierLoc,
4986 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004987 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004988 NewTemplateArgs);
4989 if (Result.isNull())
4990 return QualType();
4991
4992 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4993 QualType NamedT = ElabT->getNamedType();
4994
4995 // Copy information relevant to the template specialization.
4996 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004997 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004998 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004999 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005000 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5001 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005002 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005003 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005004
5005 // Copy information relevant to the elaborated type.
5006 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005007 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005008 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005009 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5010 DependentTemplateSpecializationTypeLoc SpecTL
5011 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005012 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005013 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005014 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005015 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005016 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5017 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005018 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005019 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005020 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005021 TemplateSpecializationTypeLoc SpecTL
5022 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005023 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005024 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005025 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5026 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005027 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005028 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005029 }
5030 return Result;
5031}
5032
5033template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005034QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5035 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005036 QualType Pattern
5037 = getDerived().TransformType(TLB, TL.getPatternLoc());
5038 if (Pattern.isNull())
5039 return QualType();
5040
5041 QualType Result = TL.getType();
5042 if (getDerived().AlwaysRebuild() ||
5043 Pattern != TL.getPatternLoc().getType()) {
5044 Result = getDerived().RebuildPackExpansionType(Pattern,
5045 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005046 TL.getEllipsisLoc(),
5047 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005048 if (Result.isNull())
5049 return QualType();
5050 }
5051
5052 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5053 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5054 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005055}
5056
5057template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005058QualType
5059TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005060 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005061 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005062 TLB.pushFullCopy(TL);
5063 return TL.getType();
5064}
5065
5066template<typename Derived>
5067QualType
5068TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005069 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005070 // ObjCObjectType is never dependent.
5071 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005072 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005073}
Mike Stump1eb44332009-09-09 15:08:12 +00005074
5075template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005076QualType
5077TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005078 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005079 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005080 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005081 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005082}
5083
Douglas Gregor577f75a2009-08-04 16:50:30 +00005084//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005085// Statement transformation
5086//===----------------------------------------------------------------------===//
5087template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005088StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005089TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005090 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005091}
5092
5093template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005094StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005095TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5096 return getDerived().TransformCompoundStmt(S, false);
5097}
5098
5099template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005100StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005101TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005102 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005103 Sema::CompoundScopeRAII CompoundScope(getSema());
5104
John McCall7114cba2010-08-27 19:56:05 +00005105 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005106 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005107 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00005108 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5109 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005110 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005111 if (Result.isInvalid()) {
5112 // Immediately fail if this was a DeclStmt, since it's very
5113 // likely that this will cause problems for future statements.
5114 if (isa<DeclStmt>(*B))
5115 return StmtError();
5116
5117 // Otherwise, just keep processing substatements and fail later.
5118 SubStmtInvalid = true;
5119 continue;
5120 }
Mike Stump1eb44332009-09-09 15:08:12 +00005121
Douglas Gregor43959a92009-08-20 07:17:43 +00005122 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5123 Statements.push_back(Result.takeAs<Stmt>());
5124 }
Mike Stump1eb44332009-09-09 15:08:12 +00005125
John McCall7114cba2010-08-27 19:56:05 +00005126 if (SubStmtInvalid)
5127 return StmtError();
5128
Douglas Gregor43959a92009-08-20 07:17:43 +00005129 if (!getDerived().AlwaysRebuild() &&
5130 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005131 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005132
5133 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5134 move_arg(Statements),
5135 S->getRBracLoc(),
5136 IsStmtExpr);
5137}
Mike Stump1eb44332009-09-09 15:08:12 +00005138
Douglas Gregor43959a92009-08-20 07:17:43 +00005139template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005140StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005141TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005142 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005143 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005144 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5145 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005146
Eli Friedman264c1f82009-11-19 03:14:00 +00005147 // Transform the left-hand case value.
5148 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005149 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005150 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005151 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005152
Eli Friedman264c1f82009-11-19 03:14:00 +00005153 // Transform the right-hand case value (for the GNU case-range extension).
5154 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005155 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005156 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005157 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005158 }
Mike Stump1eb44332009-09-09 15:08:12 +00005159
Douglas Gregor43959a92009-08-20 07:17:43 +00005160 // Build the case statement.
5161 // Case statements are always rebuilt so that they will attached to their
5162 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005163 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005164 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005165 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005166 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005167 S->getColonLoc());
5168 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005169 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005170
Douglas Gregor43959a92009-08-20 07:17:43 +00005171 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005172 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005173 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005174 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005175
Douglas Gregor43959a92009-08-20 07:17:43 +00005176 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005177 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005178}
5179
5180template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005181StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005182TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005183 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005184 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005185 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005186 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005187
Douglas Gregor43959a92009-08-20 07:17:43 +00005188 // Default statements are always rebuilt
5189 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005190 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005191}
Mike Stump1eb44332009-09-09 15:08:12 +00005192
Douglas Gregor43959a92009-08-20 07:17:43 +00005193template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005194StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005195TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005196 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005197 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005198 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005199
Chris Lattner57ad3782011-02-17 20:34:02 +00005200 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5201 S->getDecl());
5202 if (!LD)
5203 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005204
5205
Douglas Gregor43959a92009-08-20 07:17:43 +00005206 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005207 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005208 cast<LabelDecl>(LD), SourceLocation(),
5209 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005210}
Mike Stump1eb44332009-09-09 15:08:12 +00005211
Douglas Gregor43959a92009-08-20 07:17:43 +00005212template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005213StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005214TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5215 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5216 if (SubStmt.isInvalid())
5217 return StmtError();
5218
5219 // TODO: transform attributes
5220 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5221 return S;
5222
5223 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5224 S->getAttrs(),
5225 SubStmt.get());
5226}
5227
5228template<typename Derived>
5229StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005230TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005231 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005232 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005233 VarDecl *ConditionVar = 0;
5234 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005235 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005236 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005237 getDerived().TransformDefinition(
5238 S->getConditionVariable()->getLocation(),
5239 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005240 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005241 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005242 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005243 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005244
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005245 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005246 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005247
5248 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005249 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005250 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5251 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005252 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005253 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005254
John McCall9ae2f072010-08-23 23:25:46 +00005255 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005256 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005257 }
Sean Huntc3021132010-05-05 15:23:54 +00005258
John McCall9ae2f072010-08-23 23:25:46 +00005259 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5260 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005261 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005262
Douglas Gregor43959a92009-08-20 07:17:43 +00005263 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005264 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005265 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005266 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005267
Douglas Gregor43959a92009-08-20 07:17:43 +00005268 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005269 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005270 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005271 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005272
Douglas Gregor43959a92009-08-20 07:17:43 +00005273 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005274 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005275 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005276 Then.get() == S->getThen() &&
5277 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005278 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005279
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005280 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005281 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005282 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005283}
5284
5285template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005286StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005287TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005288 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005289 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005290 VarDecl *ConditionVar = 0;
5291 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005292 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005293 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005294 getDerived().TransformDefinition(
5295 S->getConditionVariable()->getLocation(),
5296 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005297 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005298 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005299 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005300 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005301
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005302 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005303 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005304 }
Mike Stump1eb44332009-09-09 15:08:12 +00005305
Douglas Gregor43959a92009-08-20 07:17:43 +00005306 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005307 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005308 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005309 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005310 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005311 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005312
Douglas Gregor43959a92009-08-20 07:17:43 +00005313 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005314 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005315 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005316 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005317
Douglas Gregor43959a92009-08-20 07:17:43 +00005318 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005319 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5320 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005321}
Mike Stump1eb44332009-09-09 15:08:12 +00005322
Douglas Gregor43959a92009-08-20 07:17:43 +00005323template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005324StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005325TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005326 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005327 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005328 VarDecl *ConditionVar = 0;
5329 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005330 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005331 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005332 getDerived().TransformDefinition(
5333 S->getConditionVariable()->getLocation(),
5334 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005335 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005336 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005337 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005338 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005339
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005340 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005341 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005342
5343 if (S->getCond()) {
5344 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005345 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5346 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005347 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005348 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005349 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005350 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005351 }
Mike Stump1eb44332009-09-09 15:08:12 +00005352
John McCall9ae2f072010-08-23 23:25:46 +00005353 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5354 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005355 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005356
Douglas Gregor43959a92009-08-20 07:17:43 +00005357 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005358 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005359 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005360 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005361
Douglas Gregor43959a92009-08-20 07:17:43 +00005362 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005363 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005364 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005365 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005366 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005367
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005368 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005369 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005370}
Mike Stump1eb44332009-09-09 15:08:12 +00005371
Douglas Gregor43959a92009-08-20 07:17:43 +00005372template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005373StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005374TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005375 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005376 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005377 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005378 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005379
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005380 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005381 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005382 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005383 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005384
Douglas Gregor43959a92009-08-20 07:17:43 +00005385 if (!getDerived().AlwaysRebuild() &&
5386 Cond.get() == S->getCond() &&
5387 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005388 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005389
John McCall9ae2f072010-08-23 23:25:46 +00005390 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5391 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005392 S->getRParenLoc());
5393}
Mike Stump1eb44332009-09-09 15:08:12 +00005394
Douglas Gregor43959a92009-08-20 07:17:43 +00005395template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005396StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005397TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005398 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005399 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005400 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005401 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005402
Douglas Gregor43959a92009-08-20 07:17:43 +00005403 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005404 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005405 VarDecl *ConditionVar = 0;
5406 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005407 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005408 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005409 getDerived().TransformDefinition(
5410 S->getConditionVariable()->getLocation(),
5411 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005412 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005413 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005414 } else {
5415 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005416
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005417 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005418 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005419
5420 if (S->getCond()) {
5421 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005422 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5423 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005424 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005425 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005426
John McCall9ae2f072010-08-23 23:25:46 +00005427 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005428 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005429 }
Mike Stump1eb44332009-09-09 15:08:12 +00005430
John McCall9ae2f072010-08-23 23:25:46 +00005431 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5432 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005433 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005434
Douglas Gregor43959a92009-08-20 07:17:43 +00005435 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005436 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005437 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005438 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005439
John McCall9ae2f072010-08-23 23:25:46 +00005440 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5441 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005442 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005443
Douglas Gregor43959a92009-08-20 07:17:43 +00005444 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005445 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005446 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005447 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005448
Douglas Gregor43959a92009-08-20 07:17:43 +00005449 if (!getDerived().AlwaysRebuild() &&
5450 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005451 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005452 Inc.get() == S->getInc() &&
5453 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005454 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005455
Douglas Gregor43959a92009-08-20 07:17:43 +00005456 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005457 Init.get(), FullCond, ConditionVar,
5458 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005459}
5460
5461template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005462StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005463TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005464 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5465 S->getLabel());
5466 if (!LD)
5467 return StmtError();
5468
Douglas Gregor43959a92009-08-20 07:17:43 +00005469 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005470 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005471 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005472}
5473
5474template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005475StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005476TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005477 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005478 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005479 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005480 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005481
Douglas Gregor43959a92009-08-20 07:17:43 +00005482 if (!getDerived().AlwaysRebuild() &&
5483 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005484 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005485
5486 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005487 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005488}
5489
5490template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005491StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005492TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005493 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005494}
Mike Stump1eb44332009-09-09 15:08:12 +00005495
Douglas Gregor43959a92009-08-20 07:17:43 +00005496template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005497StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005498TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005499 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005500}
Mike Stump1eb44332009-09-09 15:08:12 +00005501
Douglas Gregor43959a92009-08-20 07:17:43 +00005502template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005503StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005504TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005505 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005506 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005507 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005508
Mike Stump1eb44332009-09-09 15:08:12 +00005509 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005510 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005511 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005512}
Mike Stump1eb44332009-09-09 15:08:12 +00005513
Douglas Gregor43959a92009-08-20 07:17:43 +00005514template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005515StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005516TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005517 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005518 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005519 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5520 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005521 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5522 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005523 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005524 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005525
Douglas Gregor43959a92009-08-20 07:17:43 +00005526 if (Transformed != *D)
5527 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005528
Douglas Gregor43959a92009-08-20 07:17:43 +00005529 Decls.push_back(Transformed);
5530 }
Mike Stump1eb44332009-09-09 15:08:12 +00005531
Douglas Gregor43959a92009-08-20 07:17:43 +00005532 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005533 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005534
5535 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005536 S->getStartLoc(), S->getEndLoc());
5537}
Mike Stump1eb44332009-09-09 15:08:12 +00005538
Douglas Gregor43959a92009-08-20 07:17:43 +00005539template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005540StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005541TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005542
John McCallca0408f2010-08-23 06:44:23 +00005543 ASTOwningVector<Expr*> Constraints(getSema());
5544 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005545 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005546
John McCall60d7b3a2010-08-24 06:29:42 +00005547 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005548 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005549
5550 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005551
Anders Carlsson703e3942010-01-24 05:50:09 +00005552 // Go through the outputs.
5553 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005554 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005555
Anders Carlsson703e3942010-01-24 05:50:09 +00005556 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005557 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005558
Anders Carlsson703e3942010-01-24 05:50:09 +00005559 // Transform the output expr.
5560 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005561 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005562 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005563 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005564
Anders Carlsson703e3942010-01-24 05:50:09 +00005565 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005566
John McCall9ae2f072010-08-23 23:25:46 +00005567 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005568 }
Sean Huntc3021132010-05-05 15:23:54 +00005569
Anders Carlsson703e3942010-01-24 05:50:09 +00005570 // Go through the inputs.
5571 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005572 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005573
Anders Carlsson703e3942010-01-24 05:50:09 +00005574 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005575 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005576
Anders Carlsson703e3942010-01-24 05:50:09 +00005577 // Transform the input expr.
5578 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005579 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005580 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005581 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005582
Anders Carlsson703e3942010-01-24 05:50:09 +00005583 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005584
John McCall9ae2f072010-08-23 23:25:46 +00005585 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005586 }
Sean Huntc3021132010-05-05 15:23:54 +00005587
Anders Carlsson703e3942010-01-24 05:50:09 +00005588 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005589 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005590
5591 // Go through the clobbers.
5592 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005593 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005594
5595 // No need to transform the asm string literal.
5596 AsmString = SemaRef.Owned(S->getAsmString());
5597
5598 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5599 S->isSimple(),
5600 S->isVolatile(),
5601 S->getNumOutputs(),
5602 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005603 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005604 move_arg(Constraints),
5605 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005606 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005607 move_arg(Clobbers),
5608 S->getRParenLoc(),
5609 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005610}
5611
Chad Rosier8cd64b42012-06-11 20:47:18 +00005612template<typename Derived>
5613StmtResult
5614TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
5615 // No need to transform the asm string literal.
5616 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(),
5617 *S->getAsmString(),
5618 S->getEndLoc());
5619}
Douglas Gregor43959a92009-08-20 07:17:43 +00005620
5621template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005622StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005623TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005624 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005625 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005626 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005627 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005628
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005629 // Transform the @catch statements (if present).
5630 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005631 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005632 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005633 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005634 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005635 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005636 if (Catch.get() != S->getCatchStmt(I))
5637 AnyCatchChanged = true;
5638 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005639 }
Sean Huntc3021132010-05-05 15:23:54 +00005640
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005641 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005642 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005643 if (S->getFinallyStmt()) {
5644 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5645 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005646 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005647 }
5648
5649 // If nothing changed, just retain this statement.
5650 if (!getDerived().AlwaysRebuild() &&
5651 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005652 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005653 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005654 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005655
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005656 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005657 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5658 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005659}
Mike Stump1eb44332009-09-09 15:08:12 +00005660
Douglas Gregor43959a92009-08-20 07:17:43 +00005661template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005662StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005663TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005664 // Transform the @catch parameter, if there is one.
5665 VarDecl *Var = 0;
5666 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5667 TypeSourceInfo *TSInfo = 0;
5668 if (FromVar->getTypeSourceInfo()) {
5669 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5670 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005671 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005672 }
Sean Huntc3021132010-05-05 15:23:54 +00005673
Douglas Gregorbe270a02010-04-26 17:57:08 +00005674 QualType T;
5675 if (TSInfo)
5676 T = TSInfo->getType();
5677 else {
5678 T = getDerived().TransformType(FromVar->getType());
5679 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005680 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005681 }
Sean Huntc3021132010-05-05 15:23:54 +00005682
Douglas Gregorbe270a02010-04-26 17:57:08 +00005683 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5684 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005685 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005686 }
Sean Huntc3021132010-05-05 15:23:54 +00005687
John McCall60d7b3a2010-08-24 06:29:42 +00005688 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005689 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005690 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005691
5692 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005693 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005694 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005695}
Mike Stump1eb44332009-09-09 15:08:12 +00005696
Douglas Gregor43959a92009-08-20 07:17:43 +00005697template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005698StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005699TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005700 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005701 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005702 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005703 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005704
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005705 // If nothing changed, just retain this statement.
5706 if (!getDerived().AlwaysRebuild() &&
5707 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005708 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005709
5710 // Build a new statement.
5711 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005712 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005713}
Mike Stump1eb44332009-09-09 15:08:12 +00005714
Douglas Gregor43959a92009-08-20 07:17:43 +00005715template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005716StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005717TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005718 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005719 if (S->getThrowExpr()) {
5720 Operand = getDerived().TransformExpr(S->getThrowExpr());
5721 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005722 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005723 }
Sean Huntc3021132010-05-05 15:23:54 +00005724
Douglas Gregord1377b22010-04-22 21:44:01 +00005725 if (!getDerived().AlwaysRebuild() &&
5726 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005727 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005728
John McCall9ae2f072010-08-23 23:25:46 +00005729 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005730}
Mike Stump1eb44332009-09-09 15:08:12 +00005731
Douglas Gregor43959a92009-08-20 07:17:43 +00005732template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005733StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005734TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005735 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005736 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005737 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005738 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005739 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005740 Object =
5741 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5742 Object.get());
5743 if (Object.isInvalid())
5744 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005745
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005746 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005747 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005748 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005749 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005750
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005751 // If nothing change, just retain the current statement.
5752 if (!getDerived().AlwaysRebuild() &&
5753 Object.get() == S->getSynchExpr() &&
5754 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005755 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005756
5757 // Build a new statement.
5758 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005759 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005760}
5761
5762template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005763StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005764TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5765 ObjCAutoreleasePoolStmt *S) {
5766 // Transform the body.
5767 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5768 if (Body.isInvalid())
5769 return StmtError();
5770
5771 // If nothing changed, just retain this statement.
5772 if (!getDerived().AlwaysRebuild() &&
5773 Body.get() == S->getSubStmt())
5774 return SemaRef.Owned(S);
5775
5776 // Build a new statement.
5777 return getDerived().RebuildObjCAutoreleasePoolStmt(
5778 S->getAtLoc(), Body.get());
5779}
5780
5781template<typename Derived>
5782StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005783TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005784 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005785 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005786 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005787 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005788 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005789
Douglas Gregorc3203e72010-04-22 23:10:45 +00005790 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005791 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005792 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005793 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005794 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5795 Collection.take());
5796 if (Collection.isInvalid())
5797 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005798
Douglas Gregorc3203e72010-04-22 23:10:45 +00005799 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005800 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005801 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005802 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005803
Douglas Gregorc3203e72010-04-22 23:10:45 +00005804 // If nothing changed, just retain this statement.
5805 if (!getDerived().AlwaysRebuild() &&
5806 Element.get() == S->getElement() &&
5807 Collection.get() == S->getCollection() &&
5808 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005809 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005810
Douglas Gregorc3203e72010-04-22 23:10:45 +00005811 // Build a new statement.
5812 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5813 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005814 Element.get(),
5815 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005816 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005817 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005818}
5819
5820
5821template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005822StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005823TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5824 // Transform the exception declaration, if any.
5825 VarDecl *Var = 0;
5826 if (S->getExceptionDecl()) {
5827 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005828 TypeSourceInfo *T = getDerived().TransformType(
5829 ExceptionDecl->getTypeSourceInfo());
5830 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005831 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005832
Douglas Gregor83cb9422010-09-09 17:09:21 +00005833 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005834 ExceptionDecl->getInnerLocStart(),
5835 ExceptionDecl->getLocation(),
5836 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005837 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005838 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005839 }
Mike Stump1eb44332009-09-09 15:08:12 +00005840
Douglas Gregor43959a92009-08-20 07:17:43 +00005841 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005842 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005843 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005844 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005845
Douglas Gregor43959a92009-08-20 07:17:43 +00005846 if (!getDerived().AlwaysRebuild() &&
5847 !Var &&
5848 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005849 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005850
5851 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5852 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005853 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005854}
Mike Stump1eb44332009-09-09 15:08:12 +00005855
Douglas Gregor43959a92009-08-20 07:17:43 +00005856template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005857StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005858TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5859 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005860 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005861 = getDerived().TransformCompoundStmt(S->getTryBlock());
5862 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005863 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005864
Douglas Gregor43959a92009-08-20 07:17:43 +00005865 // Transform the handlers.
5866 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005867 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005868 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005869 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005870 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5871 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005872 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005873
Douglas Gregor43959a92009-08-20 07:17:43 +00005874 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5875 Handlers.push_back(Handler.takeAs<Stmt>());
5876 }
Mike Stump1eb44332009-09-09 15:08:12 +00005877
Douglas Gregor43959a92009-08-20 07:17:43 +00005878 if (!getDerived().AlwaysRebuild() &&
5879 TryBlock.get() == S->getTryBlock() &&
5880 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005881 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005882
John McCall9ae2f072010-08-23 23:25:46 +00005883 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005884 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005885}
Mike Stump1eb44332009-09-09 15:08:12 +00005886
Richard Smithad762fc2011-04-14 22:09:26 +00005887template<typename Derived>
5888StmtResult
5889TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5890 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5891 if (Range.isInvalid())
5892 return StmtError();
5893
5894 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5895 if (BeginEnd.isInvalid())
5896 return StmtError();
5897
5898 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5899 if (Cond.isInvalid())
5900 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005901 if (Cond.get())
5902 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5903 if (Cond.isInvalid())
5904 return StmtError();
5905 if (Cond.get())
5906 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005907
5908 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5909 if (Inc.isInvalid())
5910 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005911 if (Inc.get())
5912 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005913
5914 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5915 if (LoopVar.isInvalid())
5916 return StmtError();
5917
5918 StmtResult NewStmt = S;
5919 if (getDerived().AlwaysRebuild() ||
5920 Range.get() != S->getRangeStmt() ||
5921 BeginEnd.get() != S->getBeginEndStmt() ||
5922 Cond.get() != S->getCond() ||
5923 Inc.get() != S->getInc() ||
5924 LoopVar.get() != S->getLoopVarStmt())
5925 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5926 S->getColonLoc(), Range.get(),
5927 BeginEnd.get(), Cond.get(),
5928 Inc.get(), LoopVar.get(),
5929 S->getRParenLoc());
5930
5931 StmtResult Body = getDerived().TransformStmt(S->getBody());
5932 if (Body.isInvalid())
5933 return StmtError();
5934
5935 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5936 // it now so we have a new statement to attach the body to.
5937 if (Body.get() != S->getBody() && NewStmt.get() == S)
5938 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5939 S->getColonLoc(), Range.get(),
5940 BeginEnd.get(), Cond.get(),
5941 Inc.get(), LoopVar.get(),
5942 S->getRParenLoc());
5943
5944 if (NewStmt.get() == S)
5945 return SemaRef.Owned(S);
5946
5947 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5948}
5949
John Wiegley28bbe4b2011-04-28 01:08:34 +00005950template<typename Derived>
5951StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005952TreeTransform<Derived>::TransformMSDependentExistsStmt(
5953 MSDependentExistsStmt *S) {
5954 // Transform the nested-name-specifier, if any.
5955 NestedNameSpecifierLoc QualifierLoc;
5956 if (S->getQualifierLoc()) {
5957 QualifierLoc
5958 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5959 if (!QualifierLoc)
5960 return StmtError();
5961 }
5962
5963 // Transform the declaration name.
5964 DeclarationNameInfo NameInfo = S->getNameInfo();
5965 if (NameInfo.getName()) {
5966 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5967 if (!NameInfo.getName())
5968 return StmtError();
5969 }
5970
5971 // Check whether anything changed.
5972 if (!getDerived().AlwaysRebuild() &&
5973 QualifierLoc == S->getQualifierLoc() &&
5974 NameInfo.getName() == S->getNameInfo().getName())
5975 return S;
5976
5977 // Determine whether this name exists, if we can.
5978 CXXScopeSpec SS;
5979 SS.Adopt(QualifierLoc);
5980 bool Dependent = false;
5981 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5982 case Sema::IER_Exists:
5983 if (S->isIfExists())
5984 break;
5985
5986 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5987
5988 case Sema::IER_DoesNotExist:
5989 if (S->isIfNotExists())
5990 break;
5991
5992 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5993
5994 case Sema::IER_Dependent:
5995 Dependent = true;
5996 break;
Douglas Gregor65019ac2011-10-25 03:44:56 +00005997
5998 case Sema::IER_Error:
5999 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006000 }
6001
6002 // We need to continue with the instantiation, so do so now.
6003 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6004 if (SubStmt.isInvalid())
6005 return StmtError();
6006
6007 // If we have resolved the name, just transform to the substatement.
6008 if (!Dependent)
6009 return SubStmt;
6010
6011 // The name is still dependent, so build a dependent expression again.
6012 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6013 S->isIfExists(),
6014 QualifierLoc,
6015 NameInfo,
6016 SubStmt.get());
6017}
6018
6019template<typename Derived>
6020StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006021TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6022 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6023 if(TryBlock.isInvalid()) return StmtError();
6024
6025 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6026 if(!getDerived().AlwaysRebuild() &&
6027 TryBlock.get() == S->getTryBlock() &&
6028 Handler.get() == S->getHandler())
6029 return SemaRef.Owned(S);
6030
6031 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6032 S->getTryLoc(),
6033 TryBlock.take(),
6034 Handler.take());
6035}
6036
6037template<typename Derived>
6038StmtResult
6039TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6040 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6041 if(Block.isInvalid()) return StmtError();
6042
6043 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6044 Block.take());
6045}
6046
6047template<typename Derived>
6048StmtResult
6049TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6050 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6051 if(FilterExpr.isInvalid()) return StmtError();
6052
6053 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6054 if(Block.isInvalid()) return StmtError();
6055
6056 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6057 FilterExpr.take(),
6058 Block.take());
6059}
6060
6061template<typename Derived>
6062StmtResult
6063TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6064 if(isa<SEHFinallyStmt>(Handler))
6065 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6066 else
6067 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6068}
6069
Douglas Gregor43959a92009-08-20 07:17:43 +00006070//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006071// Expression transformation
6072//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006073template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006074ExprResult
John McCall454feb92009-12-08 09:21:05 +00006075TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006076 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006077}
Mike Stump1eb44332009-09-09 15:08:12 +00006078
6079template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006080ExprResult
John McCall454feb92009-12-08 09:21:05 +00006081TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006082 NestedNameSpecifierLoc QualifierLoc;
6083 if (E->getQualifierLoc()) {
6084 QualifierLoc
6085 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6086 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006087 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006088 }
John McCalldbd872f2009-12-08 09:08:17 +00006089
6090 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006091 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6092 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006093 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006094 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006095
John McCallec8045d2010-08-17 21:27:17 +00006096 DeclarationNameInfo NameInfo = E->getNameInfo();
6097 if (NameInfo.getName()) {
6098 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6099 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006100 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006101 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006102
6103 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006104 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006105 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006106 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006107 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006108
6109 // Mark it referenced in the new context regardless.
6110 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006111 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006112
John McCall3fa5cae2010-10-26 07:05:15 +00006113 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006114 }
John McCalldbd872f2009-12-08 09:08:17 +00006115
6116 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006117 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006118 TemplateArgs = &TransArgs;
6119 TransArgs.setLAngleLoc(E->getLAngleLoc());
6120 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006121 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6122 E->getNumTemplateArgs(),
6123 TransArgs))
6124 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006125 }
6126
Douglas Gregor40d96a62011-02-28 21:54:11 +00006127 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
6128 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006129}
Mike Stump1eb44332009-09-09 15:08:12 +00006130
Douglas Gregorb98b1992009-08-11 05:31:07 +00006131template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006132ExprResult
John McCall454feb92009-12-08 09:21:05 +00006133TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006134 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006135}
Mike Stump1eb44332009-09-09 15:08:12 +00006136
Douglas Gregorb98b1992009-08-11 05:31:07 +00006137template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006138ExprResult
John McCall454feb92009-12-08 09:21:05 +00006139TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006140 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006141}
Mike Stump1eb44332009-09-09 15:08:12 +00006142
Douglas Gregorb98b1992009-08-11 05:31:07 +00006143template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006144ExprResult
John McCall454feb92009-12-08 09:21:05 +00006145TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006146 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006147}
Mike Stump1eb44332009-09-09 15:08:12 +00006148
Douglas Gregorb98b1992009-08-11 05:31:07 +00006149template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006150ExprResult
John McCall454feb92009-12-08 09:21:05 +00006151TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006152 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006153}
Mike Stump1eb44332009-09-09 15:08:12 +00006154
Douglas Gregorb98b1992009-08-11 05:31:07 +00006155template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006156ExprResult
John McCall454feb92009-12-08 09:21:05 +00006157TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006158 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006159}
6160
6161template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006162ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006163TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6164 return SemaRef.MaybeBindToTemporary(E);
6165}
6166
6167template<typename Derived>
6168ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006169TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6170 ExprResult ControllingExpr =
6171 getDerived().TransformExpr(E->getControllingExpr());
6172 if (ControllingExpr.isInvalid())
6173 return ExprError();
6174
Chris Lattner686775d2011-07-20 06:58:45 +00006175 SmallVector<Expr *, 4> AssocExprs;
6176 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006177 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6178 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6179 if (TS) {
6180 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6181 if (!AssocType)
6182 return ExprError();
6183 AssocTypes.push_back(AssocType);
6184 } else {
6185 AssocTypes.push_back(0);
6186 }
6187
6188 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6189 if (AssocExpr.isInvalid())
6190 return ExprError();
6191 AssocExprs.push_back(AssocExpr.release());
6192 }
6193
6194 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6195 E->getDefaultLoc(),
6196 E->getRParenLoc(),
6197 ControllingExpr.release(),
6198 AssocTypes.data(),
6199 AssocExprs.data(),
6200 E->getNumAssocs());
6201}
6202
6203template<typename Derived>
6204ExprResult
John McCall454feb92009-12-08 09:21:05 +00006205TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006206 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006207 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006208 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006209
Douglas Gregorb98b1992009-08-11 05:31:07 +00006210 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006211 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006212
John McCall9ae2f072010-08-23 23:25:46 +00006213 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006214 E->getRParen());
6215}
6216
Mike Stump1eb44332009-09-09 15:08:12 +00006217template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006218ExprResult
John McCall454feb92009-12-08 09:21:05 +00006219TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006220 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006221 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006222 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006223
Douglas Gregorb98b1992009-08-11 05:31:07 +00006224 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006225 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006226
Douglas Gregorb98b1992009-08-11 05:31:07 +00006227 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6228 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006229 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006230}
Mike Stump1eb44332009-09-09 15:08:12 +00006231
Douglas Gregorb98b1992009-08-11 05:31:07 +00006232template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006233ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006234TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6235 // Transform the type.
6236 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6237 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006238 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006239
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006240 // Transform all of the components into components similar to what the
6241 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00006242 // FIXME: It would be slightly more efficient in the non-dependent case to
6243 // just map FieldDecls, rather than requiring the rebuilder to look for
6244 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006245 // template code that we don't care.
6246 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006247 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006248 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006249 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006250 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6251 const Node &ON = E->getComponent(I);
6252 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006253 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006254 Comp.LocStart = ON.getSourceRange().getBegin();
6255 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006256 switch (ON.getKind()) {
6257 case Node::Array: {
6258 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006259 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006260 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006261 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006262
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006263 ExprChanged = ExprChanged || Index.get() != FromIndex;
6264 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006265 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006266 break;
6267 }
Sean Huntc3021132010-05-05 15:23:54 +00006268
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006269 case Node::Field:
6270 case Node::Identifier:
6271 Comp.isBrackets = false;
6272 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006273 if (!Comp.U.IdentInfo)
6274 continue;
Sean Huntc3021132010-05-05 15:23:54 +00006275
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006276 break;
Sean Huntc3021132010-05-05 15:23:54 +00006277
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006278 case Node::Base:
6279 // Will be recomputed during the rebuild.
6280 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006281 }
Sean Huntc3021132010-05-05 15:23:54 +00006282
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006283 Components.push_back(Comp);
6284 }
Sean Huntc3021132010-05-05 15:23:54 +00006285
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006286 // If nothing changed, retain the existing expression.
6287 if (!getDerived().AlwaysRebuild() &&
6288 Type == E->getTypeSourceInfo() &&
6289 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006290 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006291
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006292 // Build a new offsetof expression.
6293 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6294 Components.data(), Components.size(),
6295 E->getRParenLoc());
6296}
6297
6298template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006299ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006300TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6301 assert(getDerived().AlreadyTransformed(E->getType()) &&
6302 "opaque value expression requires transformation");
6303 return SemaRef.Owned(E);
6304}
6305
6306template<typename Derived>
6307ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006308TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006309 // Rebuild the syntactic form. The original syntactic form has
6310 // opaque-value expressions in it, so strip those away and rebuild
6311 // the result. This is a really awful way of doing this, but the
6312 // better solution (rebuilding the semantic expressions and
6313 // rebinding OVEs as necessary) doesn't work; we'd need
6314 // TreeTransform to not strip away implicit conversions.
6315 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6316 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006317 if (result.isInvalid()) return ExprError();
6318
6319 // If that gives us a pseudo-object result back, the pseudo-object
6320 // expression must have been an lvalue-to-rvalue conversion which we
6321 // should reapply.
6322 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6323 result = SemaRef.checkPseudoObjectRValue(result.take());
6324
6325 return result;
6326}
6327
6328template<typename Derived>
6329ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006330TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6331 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006332 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006333 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006334
John McCalla93c9342009-12-07 02:54:59 +00006335 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006336 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006337 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006338
John McCall5ab75172009-11-04 07:28:41 +00006339 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006340 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006341
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006342 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6343 E->getKind(),
6344 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006345 }
Mike Stump1eb44332009-09-09 15:08:12 +00006346
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006347 // C++0x [expr.sizeof]p1:
6348 // The operand is either an expression, which is an unevaluated operand
6349 // [...]
6350 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006351
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006352 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6353 if (SubExpr.isInvalid())
6354 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006355
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006356 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6357 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006358
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006359 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6360 E->getOperatorLoc(),
6361 E->getKind(),
6362 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006363}
Mike Stump1eb44332009-09-09 15:08:12 +00006364
Douglas Gregorb98b1992009-08-11 05:31:07 +00006365template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006366ExprResult
John McCall454feb92009-12-08 09:21:05 +00006367TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006368 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006369 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006370 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006371
John McCall60d7b3a2010-08-24 06:29:42 +00006372 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006373 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006374 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006375
6376
Douglas Gregorb98b1992009-08-11 05:31:07 +00006377 if (!getDerived().AlwaysRebuild() &&
6378 LHS.get() == E->getLHS() &&
6379 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006380 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006381
John McCall9ae2f072010-08-23 23:25:46 +00006382 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006383 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006384 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006385 E->getRBracketLoc());
6386}
Mike Stump1eb44332009-09-09 15:08:12 +00006387
6388template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006389ExprResult
John McCall454feb92009-12-08 09:21:05 +00006390TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006391 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006392 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006393 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006394 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006395
6396 // Transform arguments.
6397 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006398 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006399 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6400 &ArgChanged))
6401 return ExprError();
6402
Douglas Gregorb98b1992009-08-11 05:31:07 +00006403 if (!getDerived().AlwaysRebuild() &&
6404 Callee.get() == E->getCallee() &&
6405 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006406 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006407
Douglas Gregorb98b1992009-08-11 05:31:07 +00006408 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006409 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006410 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006411 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006412 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006413 E->getRParenLoc());
6414}
Mike Stump1eb44332009-09-09 15:08:12 +00006415
6416template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006417ExprResult
John McCall454feb92009-12-08 09:21:05 +00006418TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006419 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006420 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006421 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006422
Douglas Gregor40d96a62011-02-28 21:54:11 +00006423 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006424 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006425 QualifierLoc
6426 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6427
6428 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006429 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006430 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006431 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006432
Eli Friedmanf595cc42009-12-04 06:40:45 +00006433 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006434 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6435 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006436 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006437 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006438
John McCall6bb80172010-03-30 21:47:33 +00006439 NamedDecl *FoundDecl = E->getFoundDecl();
6440 if (FoundDecl == E->getMemberDecl()) {
6441 FoundDecl = Member;
6442 } else {
6443 FoundDecl = cast_or_null<NamedDecl>(
6444 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6445 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006446 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006447 }
6448
Douglas Gregorb98b1992009-08-11 05:31:07 +00006449 if (!getDerived().AlwaysRebuild() &&
6450 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006451 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006452 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006453 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006454 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006455
Anders Carlsson1f240322009-12-22 05:24:09 +00006456 // Mark it referenced in the new context regardless.
6457 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006458 SemaRef.MarkMemberReferenced(E);
6459
John McCall3fa5cae2010-10-26 07:05:15 +00006460 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006461 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006462
John McCalld5532b62009-11-23 01:53:49 +00006463 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006464 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006465 TransArgs.setLAngleLoc(E->getLAngleLoc());
6466 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006467 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6468 E->getNumTemplateArgs(),
6469 TransArgs))
6470 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006471 }
Sean Huntc3021132010-05-05 15:23:54 +00006472
Douglas Gregorb98b1992009-08-11 05:31:07 +00006473 // FIXME: Bogus source location for the operator
6474 SourceLocation FakeOperatorLoc
6475 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6476
John McCallc2233c52010-01-15 08:34:02 +00006477 // FIXME: to do this check properly, we will need to preserve the
6478 // first-qualifier-in-scope here, just in case we had a dependent
6479 // base (and therefore couldn't do the check) and a
6480 // nested-name-qualifier (and therefore could do the lookup).
6481 NamedDecl *FirstQualifierInScope = 0;
6482
John McCall9ae2f072010-08-23 23:25:46 +00006483 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006485 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006486 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006487 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006488 Member,
John McCall6bb80172010-03-30 21:47:33 +00006489 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006490 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006491 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006492 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006493}
Mike Stump1eb44332009-09-09 15:08:12 +00006494
Douglas Gregorb98b1992009-08-11 05:31:07 +00006495template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006496ExprResult
John McCall454feb92009-12-08 09:21:05 +00006497TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006498 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006499 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006500 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006501
John McCall60d7b3a2010-08-24 06:29:42 +00006502 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006503 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006504 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006505
Douglas Gregorb98b1992009-08-11 05:31:07 +00006506 if (!getDerived().AlwaysRebuild() &&
6507 LHS.get() == E->getLHS() &&
6508 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006509 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006510
Douglas Gregorb98b1992009-08-11 05:31:07 +00006511 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006512 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006513}
6514
Mike Stump1eb44332009-09-09 15:08:12 +00006515template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006516ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006517TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006518 CompoundAssignOperator *E) {
6519 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006520}
Mike Stump1eb44332009-09-09 15:08:12 +00006521
Douglas Gregorb98b1992009-08-11 05:31:07 +00006522template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006523ExprResult TreeTransform<Derived>::
6524TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6525 // Just rebuild the common and RHS expressions and see whether we
6526 // get any changes.
6527
6528 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6529 if (commonExpr.isInvalid())
6530 return ExprError();
6531
6532 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6533 if (rhs.isInvalid())
6534 return ExprError();
6535
6536 if (!getDerived().AlwaysRebuild() &&
6537 commonExpr.get() == e->getCommon() &&
6538 rhs.get() == e->getFalseExpr())
6539 return SemaRef.Owned(e);
6540
6541 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6542 e->getQuestionLoc(),
6543 0,
6544 e->getColonLoc(),
6545 rhs.get());
6546}
6547
6548template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006549ExprResult
John McCall454feb92009-12-08 09:21:05 +00006550TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006551 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006552 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006553 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006554
John McCall60d7b3a2010-08-24 06:29:42 +00006555 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006556 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006557 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006558
John McCall60d7b3a2010-08-24 06:29:42 +00006559 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006560 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006561 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006562
Douglas Gregorb98b1992009-08-11 05:31:07 +00006563 if (!getDerived().AlwaysRebuild() &&
6564 Cond.get() == E->getCond() &&
6565 LHS.get() == E->getLHS() &&
6566 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006567 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006568
John McCall9ae2f072010-08-23 23:25:46 +00006569 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006570 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006571 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006572 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006573 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006574}
Mike Stump1eb44332009-09-09 15:08:12 +00006575
6576template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006577ExprResult
John McCall454feb92009-12-08 09:21:05 +00006578TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006579 // Implicit casts are eliminated during transformation, since they
6580 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006581 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006582}
Mike Stump1eb44332009-09-09 15:08:12 +00006583
Douglas Gregorb98b1992009-08-11 05:31:07 +00006584template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006585ExprResult
John McCall454feb92009-12-08 09:21:05 +00006586TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006587 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6588 if (!Type)
6589 return ExprError();
6590
John McCall60d7b3a2010-08-24 06:29:42 +00006591 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006592 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006593 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006594 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006595
Douglas Gregorb98b1992009-08-11 05:31:07 +00006596 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006597 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006598 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006599 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006600
John McCall9d125032010-01-15 18:39:57 +00006601 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006602 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006603 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006604 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006605}
Mike Stump1eb44332009-09-09 15:08:12 +00006606
Douglas Gregorb98b1992009-08-11 05:31:07 +00006607template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006608ExprResult
John McCall454feb92009-12-08 09:21:05 +00006609TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006610 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6611 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6612 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006613 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006614
John McCall60d7b3a2010-08-24 06:29:42 +00006615 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006616 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006617 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006618
Douglas Gregorb98b1992009-08-11 05:31:07 +00006619 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006620 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006622 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623
John McCall1d7d8d62010-01-19 22:33:45 +00006624 // Note: the expression type doesn't necessarily match the
6625 // type-as-written, but that's okay, because it should always be
6626 // derivable from the initializer.
6627
John McCall42f56b52010-01-18 19:35:47 +00006628 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006629 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006630 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631}
Mike Stump1eb44332009-09-09 15:08:12 +00006632
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006634ExprResult
John McCall454feb92009-12-08 09:21:05 +00006635TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006636 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006637 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006638 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006639
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640 if (!getDerived().AlwaysRebuild() &&
6641 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006642 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006643
Douglas Gregorb98b1992009-08-11 05:31:07 +00006644 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006645 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006647 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006648 E->getAccessorLoc(),
6649 E->getAccessor());
6650}
Mike Stump1eb44332009-09-09 15:08:12 +00006651
Douglas Gregorb98b1992009-08-11 05:31:07 +00006652template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006653ExprResult
John McCall454feb92009-12-08 09:21:05 +00006654TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006655 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006656
John McCallca0408f2010-08-23 06:44:23 +00006657 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006658 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6659 Inits, &InitChanged))
6660 return ExprError();
6661
Douglas Gregorb98b1992009-08-11 05:31:07 +00006662 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006663 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006664
Douglas Gregorb98b1992009-08-11 05:31:07 +00006665 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006666 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667}
Mike Stump1eb44332009-09-09 15:08:12 +00006668
Douglas Gregorb98b1992009-08-11 05:31:07 +00006669template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006670ExprResult
John McCall454feb92009-12-08 09:21:05 +00006671TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006672 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006673
Douglas Gregor43959a92009-08-20 07:17:43 +00006674 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006675 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006676 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006677 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006678
Douglas Gregor43959a92009-08-20 07:17:43 +00006679 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006680 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006681 bool ExprChanged = false;
6682 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6683 DEnd = E->designators_end();
6684 D != DEnd; ++D) {
6685 if (D->isFieldDesignator()) {
6686 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6687 D->getDotLoc(),
6688 D->getFieldLoc()));
6689 continue;
6690 }
Mike Stump1eb44332009-09-09 15:08:12 +00006691
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006693 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006694 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006695 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006696
6697 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006698 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006699
Douglas Gregorb98b1992009-08-11 05:31:07 +00006700 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6701 ArrayExprs.push_back(Index.release());
6702 continue;
6703 }
Mike Stump1eb44332009-09-09 15:08:12 +00006704
Douglas Gregorb98b1992009-08-11 05:31:07 +00006705 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006706 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006707 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6708 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006709 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006710
John McCall60d7b3a2010-08-24 06:29:42 +00006711 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006713 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006714
6715 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006716 End.get(),
6717 D->getLBracketLoc(),
6718 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006719
Douglas Gregorb98b1992009-08-11 05:31:07 +00006720 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6721 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006722
Douglas Gregorb98b1992009-08-11 05:31:07 +00006723 ArrayExprs.push_back(Start.release());
6724 ArrayExprs.push_back(End.release());
6725 }
Mike Stump1eb44332009-09-09 15:08:12 +00006726
Douglas Gregorb98b1992009-08-11 05:31:07 +00006727 if (!getDerived().AlwaysRebuild() &&
6728 Init.get() == E->getInit() &&
6729 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006730 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006731
Douglas Gregorb98b1992009-08-11 05:31:07 +00006732 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6733 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006734 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006735}
Mike Stump1eb44332009-09-09 15:08:12 +00006736
Douglas Gregorb98b1992009-08-11 05:31:07 +00006737template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006738ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006740 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006741 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006742
Douglas Gregor5557b252009-10-28 00:29:27 +00006743 // FIXME: Will we ever have proper type location here? Will we actually
6744 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006745 QualType T = getDerived().TransformType(E->getType());
6746 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006747 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006748
Douglas Gregorb98b1992009-08-11 05:31:07 +00006749 if (!getDerived().AlwaysRebuild() &&
6750 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006751 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006752
Douglas Gregorb98b1992009-08-11 05:31:07 +00006753 return getDerived().RebuildImplicitValueInitExpr(T);
6754}
Mike Stump1eb44332009-09-09 15:08:12 +00006755
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006757ExprResult
John McCall454feb92009-12-08 09:21:05 +00006758TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006759 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6760 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006761 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006762
John McCall60d7b3a2010-08-24 06:29:42 +00006763 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006764 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006765 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006766
Douglas Gregorb98b1992009-08-11 05:31:07 +00006767 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006768 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006769 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006770 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006771
John McCall9ae2f072010-08-23 23:25:46 +00006772 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006773 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006774}
6775
6776template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006777ExprResult
John McCall454feb92009-12-08 09:21:05 +00006778TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006779 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006780 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006781 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6782 &ArgumentChanged))
6783 return ExprError();
6784
Douglas Gregorb98b1992009-08-11 05:31:07 +00006785 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6786 move_arg(Inits),
6787 E->getRParenLoc());
6788}
Mike Stump1eb44332009-09-09 15:08:12 +00006789
Douglas Gregorb98b1992009-08-11 05:31:07 +00006790/// \brief Transform an address-of-label expression.
6791///
6792/// By default, the transformation of an address-of-label expression always
6793/// rebuilds the expression, so that the label identifier can be resolved to
6794/// the corresponding label statement by semantic analysis.
6795template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006796ExprResult
John McCall454feb92009-12-08 09:21:05 +00006797TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006798 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6799 E->getLabel());
6800 if (!LD)
6801 return ExprError();
6802
Douglas Gregorb98b1992009-08-11 05:31:07 +00006803 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006804 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006805}
Mike Stump1eb44332009-09-09 15:08:12 +00006806
6807template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006808ExprResult
John McCall454feb92009-12-08 09:21:05 +00006809TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006810 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006811 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006812 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006813 if (SubStmt.isInvalid()) {
6814 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006815 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006816 }
Mike Stump1eb44332009-09-09 15:08:12 +00006817
Douglas Gregorb98b1992009-08-11 05:31:07 +00006818 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006819 SubStmt.get() == E->getSubStmt()) {
6820 // Calling this an 'error' is unintuitive, but it does the right thing.
6821 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006822 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006823 }
Mike Stump1eb44332009-09-09 15:08:12 +00006824
6825 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006826 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006827 E->getRParenLoc());
6828}
Mike Stump1eb44332009-09-09 15:08:12 +00006829
Douglas Gregorb98b1992009-08-11 05:31:07 +00006830template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006831ExprResult
John McCall454feb92009-12-08 09:21:05 +00006832TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006833 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006834 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006835 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006836
John McCall60d7b3a2010-08-24 06:29:42 +00006837 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006838 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006839 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006840
John McCall60d7b3a2010-08-24 06:29:42 +00006841 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006842 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006843 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006844
Douglas Gregorb98b1992009-08-11 05:31:07 +00006845 if (!getDerived().AlwaysRebuild() &&
6846 Cond.get() == E->getCond() &&
6847 LHS.get() == E->getLHS() &&
6848 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006849 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006850
Douglas Gregorb98b1992009-08-11 05:31:07 +00006851 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006852 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006853 E->getRParenLoc());
6854}
Mike Stump1eb44332009-09-09 15:08:12 +00006855
Douglas Gregorb98b1992009-08-11 05:31:07 +00006856template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006857ExprResult
John McCall454feb92009-12-08 09:21:05 +00006858TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006859 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006860}
6861
6862template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006863ExprResult
John McCall454feb92009-12-08 09:21:05 +00006864TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006865 switch (E->getOperator()) {
6866 case OO_New:
6867 case OO_Delete:
6868 case OO_Array_New:
6869 case OO_Array_Delete:
6870 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Sean Huntc3021132010-05-05 15:23:54 +00006871
Douglas Gregor668d6d92009-12-13 20:44:55 +00006872 case OO_Call: {
6873 // This is a call to an object's operator().
6874 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6875
6876 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006877 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006878 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006879 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006880
6881 // FIXME: Poor location information
6882 SourceLocation FakeLParenLoc
6883 = SemaRef.PP.getLocForEndOfToken(
6884 static_cast<Expr *>(Object.get())->getLocEnd());
6885
6886 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006887 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006888 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6889 Args))
6890 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006891
John McCall9ae2f072010-08-23 23:25:46 +00006892 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006893 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006894 E->getLocEnd());
6895 }
6896
6897#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6898 case OO_##Name:
6899#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6900#include "clang/Basic/OperatorKinds.def"
6901 case OO_Subscript:
6902 // Handled below.
6903 break;
6904
6905 case OO_Conditional:
6906 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006907
6908 case OO_None:
6909 case NUM_OVERLOADED_OPERATORS:
6910 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006911 }
6912
John McCall60d7b3a2010-08-24 06:29:42 +00006913 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006914 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006915 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006916
John McCall60d7b3a2010-08-24 06:29:42 +00006917 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006918 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006919 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006920
John McCall60d7b3a2010-08-24 06:29:42 +00006921 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006922 if (E->getNumArgs() == 2) {
6923 Second = getDerived().TransformExpr(E->getArg(1));
6924 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006925 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006926 }
Mike Stump1eb44332009-09-09 15:08:12 +00006927
Douglas Gregorb98b1992009-08-11 05:31:07 +00006928 if (!getDerived().AlwaysRebuild() &&
6929 Callee.get() == E->getCallee() &&
6930 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006931 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006932 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006933
Douglas Gregorb98b1992009-08-11 05:31:07 +00006934 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6935 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006936 Callee.get(),
6937 First.get(),
6938 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006939}
Mike Stump1eb44332009-09-09 15:08:12 +00006940
Douglas Gregorb98b1992009-08-11 05:31:07 +00006941template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006942ExprResult
John McCall454feb92009-12-08 09:21:05 +00006943TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6944 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006945}
Mike Stump1eb44332009-09-09 15:08:12 +00006946
Douglas Gregorb98b1992009-08-11 05:31:07 +00006947template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006948ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006949TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6950 // Transform the callee.
6951 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6952 if (Callee.isInvalid())
6953 return ExprError();
6954
6955 // Transform exec config.
6956 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6957 if (EC.isInvalid())
6958 return ExprError();
6959
6960 // Transform arguments.
6961 bool ArgChanged = false;
6962 ASTOwningVector<Expr*> Args(SemaRef);
6963 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6964 &ArgChanged))
6965 return ExprError();
6966
6967 if (!getDerived().AlwaysRebuild() &&
6968 Callee.get() == E->getCallee() &&
6969 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006970 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006971
6972 // FIXME: Wrong source location information for the '('.
6973 SourceLocation FakeLParenLoc
6974 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6975 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6976 move_arg(Args),
6977 E->getRParenLoc(), EC.get());
6978}
6979
6980template<typename Derived>
6981ExprResult
John McCall454feb92009-12-08 09:21:05 +00006982TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006983 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6984 if (!Type)
6985 return ExprError();
6986
John McCall60d7b3a2010-08-24 06:29:42 +00006987 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006988 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006989 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006990 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006991
Douglas Gregorb98b1992009-08-11 05:31:07 +00006992 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006993 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006994 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006995 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006996
Douglas Gregorb98b1992009-08-11 05:31:07 +00006997 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006998 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006999 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
7000 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
7001 SourceLocation FakeRParenLoc
7002 = SemaRef.PP.getLocForEndOfToken(
7003 E->getSubExpr()->getSourceRange().getEnd());
7004 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007005 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007006 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007007 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007008 FakeRAngleLoc,
7009 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007010 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007011 FakeRParenLoc);
7012}
Mike Stump1eb44332009-09-09 15:08:12 +00007013
Douglas Gregorb98b1992009-08-11 05:31:07 +00007014template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007015ExprResult
John McCall454feb92009-12-08 09:21:05 +00007016TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7017 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007018}
Mike Stump1eb44332009-09-09 15:08:12 +00007019
7020template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007021ExprResult
John McCall454feb92009-12-08 09:21:05 +00007022TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7023 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007024}
7025
Douglas Gregorb98b1992009-08-11 05:31:07 +00007026template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007027ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007028TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007029 CXXReinterpretCastExpr *E) {
7030 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031}
Mike Stump1eb44332009-09-09 15:08:12 +00007032
Douglas Gregorb98b1992009-08-11 05:31:07 +00007033template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007034ExprResult
John McCall454feb92009-12-08 09:21:05 +00007035TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7036 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007037}
Mike Stump1eb44332009-09-09 15:08:12 +00007038
Douglas Gregorb98b1992009-08-11 05:31:07 +00007039template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007040ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007041TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007042 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007043 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7044 if (!Type)
7045 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007046
John McCall60d7b3a2010-08-24 06:29:42 +00007047 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007048 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007049 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007050 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007051
Douglas Gregorb98b1992009-08-11 05:31:07 +00007052 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007053 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007054 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007055 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007056
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007057 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007058 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007059 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007060 E->getRParenLoc());
7061}
Mike Stump1eb44332009-09-09 15:08:12 +00007062
Douglas Gregorb98b1992009-08-11 05:31:07 +00007063template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007064ExprResult
John McCall454feb92009-12-08 09:21:05 +00007065TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007066 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007067 TypeSourceInfo *TInfo
7068 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7069 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007070 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007071
Douglas Gregorb98b1992009-08-11 05:31:07 +00007072 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007073 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007074 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007075
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007076 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7077 E->getLocStart(),
7078 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007079 E->getLocEnd());
7080 }
Mike Stump1eb44332009-09-09 15:08:12 +00007081
Eli Friedmanef331b72012-01-20 01:26:23 +00007082 // We don't know whether the subexpression is potentially evaluated until
7083 // after we perform semantic analysis. We speculatively assume it is
7084 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007085 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00007086 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00007087
John McCall60d7b3a2010-08-24 06:29:42 +00007088 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007089 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007090 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007091
Douglas Gregorb98b1992009-08-11 05:31:07 +00007092 if (!getDerived().AlwaysRebuild() &&
7093 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007094 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007095
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007096 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7097 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007098 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007099 E->getLocEnd());
7100}
7101
7102template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007103ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007104TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7105 if (E->isTypeOperand()) {
7106 TypeSourceInfo *TInfo
7107 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7108 if (!TInfo)
7109 return ExprError();
7110
7111 if (!getDerived().AlwaysRebuild() &&
7112 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007113 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007114
Douglas Gregor3c52a212011-03-06 17:40:41 +00007115 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007116 E->getLocStart(),
7117 TInfo,
7118 E->getLocEnd());
7119 }
7120
Francois Pichet01b7c302010-09-08 12:20:18 +00007121 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7122
7123 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7124 if (SubExpr.isInvalid())
7125 return ExprError();
7126
7127 if (!getDerived().AlwaysRebuild() &&
7128 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007129 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007130
7131 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7132 E->getLocStart(),
7133 SubExpr.get(),
7134 E->getLocEnd());
7135}
7136
7137template<typename Derived>
7138ExprResult
John McCall454feb92009-12-08 09:21:05 +00007139TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007140 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007141}
Mike Stump1eb44332009-09-09 15:08:12 +00007142
Douglas Gregorb98b1992009-08-11 05:31:07 +00007143template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007144ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007145TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007146 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007147 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007148}
Mike Stump1eb44332009-09-09 15:08:12 +00007149
Douglas Gregorb98b1992009-08-11 05:31:07 +00007150template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007151ExprResult
John McCall454feb92009-12-08 09:21:05 +00007152TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007153 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007154 QualType T;
7155 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7156 T = MD->getThisType(getSema().Context);
7157 else
7158 T = getSema().Context.getPointerType(
7159 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007160
Douglas Gregorec79d872012-02-24 17:41:38 +00007161 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7162 // Make sure that we capture 'this'.
7163 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007164 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007165 }
7166
Douglas Gregor828a1972010-01-07 23:12:05 +00007167 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007168}
Mike Stump1eb44332009-09-09 15:08:12 +00007169
Douglas Gregorb98b1992009-08-11 05:31:07 +00007170template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007171ExprResult
John McCall454feb92009-12-08 09:21:05 +00007172TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007173 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007174 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007175 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007176
Douglas Gregorb98b1992009-08-11 05:31:07 +00007177 if (!getDerived().AlwaysRebuild() &&
7178 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007179 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007180
Douglas Gregorbca01b42011-07-06 22:04:06 +00007181 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7182 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007183}
Mike Stump1eb44332009-09-09 15:08:12 +00007184
Douglas Gregorb98b1992009-08-11 05:31:07 +00007185template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007186ExprResult
John McCall454feb92009-12-08 09:21:05 +00007187TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007188 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007189 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7190 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007191 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007192 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007193
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007194 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007195 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007196 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007197
Douglas Gregor036aed12009-12-23 23:03:06 +00007198 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007199}
Mike Stump1eb44332009-09-09 15:08:12 +00007200
Douglas Gregorb98b1992009-08-11 05:31:07 +00007201template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007202ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007203TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7204 CXXScalarValueInitExpr *E) {
7205 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7206 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007207 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00007208
Douglas Gregorb98b1992009-08-11 05:31:07 +00007209 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007210 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007211 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007212
Douglas Gregorab6677e2010-09-08 00:15:04 +00007213 return getDerived().RebuildCXXScalarValueInitExpr(T,
7214 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007215 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007216}
Mike Stump1eb44332009-09-09 15:08:12 +00007217
Douglas Gregorb98b1992009-08-11 05:31:07 +00007218template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007219ExprResult
John McCall454feb92009-12-08 09:21:05 +00007220TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007221 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007222 TypeSourceInfo *AllocTypeInfo
7223 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7224 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007225 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007226
Douglas Gregorb98b1992009-08-11 05:31:07 +00007227 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007228 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007229 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007230 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007231
Douglas Gregorb98b1992009-08-11 05:31:07 +00007232 // Transform the placement arguments (if any).
7233 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007234 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007235 if (getDerived().TransformExprs(E->getPlacementArgs(),
7236 E->getNumPlacementArgs(), true,
7237 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007238 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007239
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007240 // Transform the initializer (if any).
7241 Expr *OldInit = E->getInitializer();
7242 ExprResult NewInit;
7243 if (OldInit)
7244 NewInit = getDerived().TransformExpr(OldInit);
7245 if (NewInit.isInvalid())
7246 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007247
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007248 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007249 FunctionDecl *OperatorNew = 0;
7250 if (E->getOperatorNew()) {
7251 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007252 getDerived().TransformDecl(E->getLocStart(),
7253 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007254 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007255 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007256 }
7257
7258 FunctionDecl *OperatorDelete = 0;
7259 if (E->getOperatorDelete()) {
7260 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007261 getDerived().TransformDecl(E->getLocStart(),
7262 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007263 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007264 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007265 }
Sean Huntc3021132010-05-05 15:23:54 +00007266
Douglas Gregorb98b1992009-08-11 05:31:07 +00007267 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007268 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007269 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007270 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007271 OperatorNew == E->getOperatorNew() &&
7272 OperatorDelete == E->getOperatorDelete() &&
7273 !ArgumentChanged) {
7274 // Mark any declarations we need as referenced.
7275 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007276 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007277 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007278 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007279 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007280
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007281 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007282 QualType ElementType
7283 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7284 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7285 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7286 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007287 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007288 }
7289 }
7290 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007291
John McCall3fa5cae2010-10-26 07:05:15 +00007292 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007293 }
Mike Stump1eb44332009-09-09 15:08:12 +00007294
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007295 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007296 if (!ArraySize.get()) {
7297 // If no array size was specified, but the new expression was
7298 // instantiated with an array type (e.g., "new T" where T is
7299 // instantiated with "int[4]"), extract the outer bound from the
7300 // array type as our array size. We do this with constant and
7301 // dependently-sized array types.
7302 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7303 if (!ArrayT) {
7304 // Do nothing
7305 } else if (const ConstantArrayType *ConsArrayT
7306 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007307 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007308 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7309 ConsArrayT->getSize(),
7310 SemaRef.Context.getSizeType(),
7311 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007312 AllocType = ConsArrayT->getElementType();
7313 } else if (const DependentSizedArrayType *DepArrayT
7314 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7315 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007316 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007317 AllocType = DepArrayT->getElementType();
7318 }
7319 }
7320 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007321
Douglas Gregorb98b1992009-08-11 05:31:07 +00007322 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7323 E->isGlobalNew(),
7324 /*FIXME:*/E->getLocStart(),
7325 move_arg(PlacementArgs),
7326 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007327 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007328 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007329 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007330 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007331 E->getDirectInitRange(),
7332 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007333}
Mike Stump1eb44332009-09-09 15:08:12 +00007334
Douglas Gregorb98b1992009-08-11 05:31:07 +00007335template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007336ExprResult
John McCall454feb92009-12-08 09:21:05 +00007337TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007338 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007339 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007340 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007341
Douglas Gregor1af74512010-02-26 00:38:10 +00007342 // Transform the delete operator, if known.
7343 FunctionDecl *OperatorDelete = 0;
7344 if (E->getOperatorDelete()) {
7345 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007346 getDerived().TransformDecl(E->getLocStart(),
7347 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007348 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007349 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007350 }
Sean Huntc3021132010-05-05 15:23:54 +00007351
Douglas Gregorb98b1992009-08-11 05:31:07 +00007352 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007353 Operand.get() == E->getArgument() &&
7354 OperatorDelete == E->getOperatorDelete()) {
7355 // Mark any declarations we need as referenced.
7356 // FIXME: instantiation-specific.
7357 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007358 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007359
7360 if (!E->getArgument()->isTypeDependent()) {
7361 QualType Destroyed = SemaRef.Context.getBaseElementType(
7362 E->getDestroyedType());
7363 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7364 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Eli Friedman5f2987c2012-02-02 03:46:19 +00007365 SemaRef.MarkFunctionReferenced(E->getLocStart(),
7366 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007367 }
7368 }
7369
John McCall3fa5cae2010-10-26 07:05:15 +00007370 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007371 }
Mike Stump1eb44332009-09-09 15:08:12 +00007372
Douglas Gregorb98b1992009-08-11 05:31:07 +00007373 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7374 E->isGlobalDelete(),
7375 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007376 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007377}
Mike Stump1eb44332009-09-09 15:08:12 +00007378
Douglas Gregorb98b1992009-08-11 05:31:07 +00007379template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007380ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007381TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007382 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007383 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007384 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007385 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007386
John McCallb3d87482010-08-24 05:47:05 +00007387 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007388 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007389 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007390 E->getOperatorLoc(),
7391 E->isArrow()? tok::arrow : tok::period,
7392 ObjectTypePtr,
7393 MayBePseudoDestructor);
7394 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007395 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007396
John McCallb3d87482010-08-24 05:47:05 +00007397 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007398 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7399 if (QualifierLoc) {
7400 QualifierLoc
7401 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7402 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007403 return ExprError();
7404 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007405 CXXScopeSpec SS;
7406 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007407
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007408 PseudoDestructorTypeStorage Destroyed;
7409 if (E->getDestroyedTypeInfo()) {
7410 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007411 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007412 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007413 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007414 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007415 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007416 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007417 // We aren't likely to be able to resolve the identifier down to a type
7418 // now anyway, so just retain the identifier.
7419 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7420 E->getDestroyedTypeLoc());
7421 } else {
7422 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007423 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007424 *E->getDestroyedTypeIdentifier(),
7425 E->getDestroyedTypeLoc(),
7426 /*Scope=*/0,
7427 SS, ObjectTypePtr,
7428 false);
7429 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007430 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007431
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007432 Destroyed
7433 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7434 E->getDestroyedTypeLoc());
7435 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007436
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007437 TypeSourceInfo *ScopeTypeInfo = 0;
7438 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007439 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007440 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007441 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007442 }
Sean Huntc3021132010-05-05 15:23:54 +00007443
John McCall9ae2f072010-08-23 23:25:46 +00007444 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007445 E->getOperatorLoc(),
7446 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007447 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007448 ScopeTypeInfo,
7449 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007450 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007451 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007452}
Mike Stump1eb44332009-09-09 15:08:12 +00007453
Douglas Gregora71d8192009-09-04 17:36:40 +00007454template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007455ExprResult
John McCallba135432009-11-21 08:51:07 +00007456TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007457 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007458 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7459 Sema::LookupOrdinaryName);
7460
7461 // Transform all the decls.
7462 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7463 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007464 NamedDecl *InstD = static_cast<NamedDecl*>(
7465 getDerived().TransformDecl(Old->getNameLoc(),
7466 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007467 if (!InstD) {
7468 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7469 // This can happen because of dependent hiding.
7470 if (isa<UsingShadowDecl>(*I))
7471 continue;
7472 else
John McCallf312b1e2010-08-26 23:41:50 +00007473 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007474 }
John McCallf7a1a742009-11-24 19:00:30 +00007475
7476 // Expand using declarations.
7477 if (isa<UsingDecl>(InstD)) {
7478 UsingDecl *UD = cast<UsingDecl>(InstD);
7479 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7480 E = UD->shadow_end(); I != E; ++I)
7481 R.addDecl(*I);
7482 continue;
7483 }
7484
7485 R.addDecl(InstD);
7486 }
7487
7488 // Resolve a kind, but don't do any further analysis. If it's
7489 // ambiguous, the callee needs to deal with it.
7490 R.resolveKind();
7491
7492 // Rebuild the nested-name qualifier, if present.
7493 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007494 if (Old->getQualifierLoc()) {
7495 NestedNameSpecifierLoc QualifierLoc
7496 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7497 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007498 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007499
Douglas Gregor4c9be892011-02-28 20:01:57 +00007500 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007501 }
7502
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007503 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007504 CXXRecordDecl *NamingClass
7505 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7506 Old->getNameLoc(),
7507 Old->getNamingClass()));
7508 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007509 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007510
Douglas Gregor66c45152010-04-27 16:10:10 +00007511 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007512 }
7513
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007514 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7515
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007516 // If we have neither explicit template arguments, nor the template keyword,
7517 // it's a normal declaration name.
7518 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007519 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7520
7521 // If we have template arguments, rebuild them, then rebuild the
7522 // templateid expression.
7523 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007524 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7525 Old->getNumTemplateArgs(),
7526 TransArgs))
7527 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007528
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007529 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007530 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007531}
Mike Stump1eb44332009-09-09 15:08:12 +00007532
Douglas Gregorb98b1992009-08-11 05:31:07 +00007533template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007534ExprResult
John McCall454feb92009-12-08 09:21:05 +00007535TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007536 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7537 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007538 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007539
Douglas Gregorb98b1992009-08-11 05:31:07 +00007540 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007541 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007542 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007543
Mike Stump1eb44332009-09-09 15:08:12 +00007544 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007545 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007546 T,
7547 E->getLocEnd());
7548}
Mike Stump1eb44332009-09-09 15:08:12 +00007549
Douglas Gregorb98b1992009-08-11 05:31:07 +00007550template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007551ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007552TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7553 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7554 if (!LhsT)
7555 return ExprError();
7556
7557 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7558 if (!RhsT)
7559 return ExprError();
7560
7561 if (!getDerived().AlwaysRebuild() &&
7562 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7563 return SemaRef.Owned(E);
7564
7565 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7566 E->getLocStart(),
7567 LhsT, RhsT,
7568 E->getLocEnd());
7569}
7570
7571template<typename Derived>
7572ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007573TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7574 bool ArgChanged = false;
7575 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7576 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7577 TypeSourceInfo *From = E->getArg(I);
7578 TypeLoc FromTL = From->getTypeLoc();
7579 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7580 TypeLocBuilder TLB;
7581 TLB.reserve(FromTL.getFullDataSize());
7582 QualType To = getDerived().TransformType(TLB, FromTL);
7583 if (To.isNull())
7584 return ExprError();
7585
7586 if (To == From->getType())
7587 Args.push_back(From);
7588 else {
7589 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7590 ArgChanged = true;
7591 }
7592 continue;
7593 }
7594
7595 ArgChanged = true;
7596
7597 // We have a pack expansion. Instantiate it.
7598 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
7599 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7600 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7601 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
7602
7603 // Determine whether the set of unexpanded parameter packs can and should
7604 // be expanded.
7605 bool Expand = true;
7606 bool RetainExpansion = false;
7607 llvm::Optional<unsigned> OrigNumExpansions
7608 = ExpansionTL.getTypePtr()->getNumExpansions();
7609 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7610 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7611 PatternTL.getSourceRange(),
7612 Unexpanded,
7613 Expand, RetainExpansion,
7614 NumExpansions))
7615 return ExprError();
7616
7617 if (!Expand) {
7618 // The transform has determined that we should perform a simple
7619 // transformation on the pack expansion, producing another pack
7620 // expansion.
7621 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7622
7623 TypeLocBuilder TLB;
7624 TLB.reserve(From->getTypeLoc().getFullDataSize());
7625
7626 QualType To = getDerived().TransformType(TLB, PatternTL);
7627 if (To.isNull())
7628 return ExprError();
7629
7630 To = getDerived().RebuildPackExpansionType(To,
7631 PatternTL.getSourceRange(),
7632 ExpansionTL.getEllipsisLoc(),
7633 NumExpansions);
7634 if (To.isNull())
7635 return ExprError();
7636
7637 PackExpansionTypeLoc ToExpansionTL
7638 = TLB.push<PackExpansionTypeLoc>(To);
7639 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7640 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7641 continue;
7642 }
7643
7644 // Expand the pack expansion by substituting for each argument in the
7645 // pack(s).
7646 for (unsigned I = 0; I != *NumExpansions; ++I) {
7647 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7648 TypeLocBuilder TLB;
7649 TLB.reserve(PatternTL.getFullDataSize());
7650 QualType To = getDerived().TransformType(TLB, PatternTL);
7651 if (To.isNull())
7652 return ExprError();
7653
7654 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7655 }
7656
7657 if (!RetainExpansion)
7658 continue;
7659
7660 // If we're supposed to retain a pack expansion, do so by temporarily
7661 // forgetting the partially-substituted parameter pack.
7662 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7663
7664 TypeLocBuilder TLB;
7665 TLB.reserve(From->getTypeLoc().getFullDataSize());
7666
7667 QualType To = getDerived().TransformType(TLB, PatternTL);
7668 if (To.isNull())
7669 return ExprError();
7670
7671 To = getDerived().RebuildPackExpansionType(To,
7672 PatternTL.getSourceRange(),
7673 ExpansionTL.getEllipsisLoc(),
7674 NumExpansions);
7675 if (To.isNull())
7676 return ExprError();
7677
7678 PackExpansionTypeLoc ToExpansionTL
7679 = TLB.push<PackExpansionTypeLoc>(To);
7680 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7681 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7682 }
7683
7684 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7685 return SemaRef.Owned(E);
7686
7687 return getDerived().RebuildTypeTrait(E->getTrait(),
7688 E->getLocStart(),
7689 Args,
7690 E->getLocEnd());
7691}
7692
7693template<typename Derived>
7694ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007695TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7696 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7697 if (!T)
7698 return ExprError();
7699
7700 if (!getDerived().AlwaysRebuild() &&
7701 T == E->getQueriedTypeSourceInfo())
7702 return SemaRef.Owned(E);
7703
7704 ExprResult SubExpr;
7705 {
7706 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7707 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7708 if (SubExpr.isInvalid())
7709 return ExprError();
7710
7711 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7712 return SemaRef.Owned(E);
7713 }
7714
7715 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7716 E->getLocStart(),
7717 T,
7718 SubExpr.get(),
7719 E->getLocEnd());
7720}
7721
7722template<typename Derived>
7723ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007724TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7725 ExprResult SubExpr;
7726 {
7727 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7728 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7729 if (SubExpr.isInvalid())
7730 return ExprError();
7731
7732 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7733 return SemaRef.Owned(E);
7734 }
7735
7736 return getDerived().RebuildExpressionTrait(
7737 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7738}
7739
7740template<typename Derived>
7741ExprResult
John McCall865d4472009-11-19 22:55:06 +00007742TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007743 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007744 NestedNameSpecifierLoc QualifierLoc
7745 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7746 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007747 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007748 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007749
John McCall43fed0d2010-11-12 08:19:04 +00007750 // TODO: If this is a conversion-function-id, verify that the
7751 // destination type name (if present) resolves the same way after
7752 // instantiation as it did in the local scope.
7753
Abramo Bagnara25777432010-08-11 22:01:17 +00007754 DeclarationNameInfo NameInfo
7755 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7756 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007757 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007758
John McCallf7a1a742009-11-24 19:00:30 +00007759 if (!E->hasExplicitTemplateArgs()) {
7760 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007761 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007762 // Note: it is sufficient to compare the Name component of NameInfo:
7763 // if name has not changed, DNLoc has not changed either.
7764 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007765 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007766
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007767 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007768 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007769 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007770 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007771 }
John McCalld5532b62009-11-23 01:53:49 +00007772
7773 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007774 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7775 E->getNumTemplateArgs(),
7776 TransArgs))
7777 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007778
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007779 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007780 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007781 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007782 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007783}
7784
7785template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007786ExprResult
John McCall454feb92009-12-08 09:21:05 +00007787TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007788 // CXXConstructExprs are always implicit, so when we have a
7789 // 1-argument construction we just transform that argument.
7790 if (E->getNumArgs() == 1 ||
7791 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7792 return getDerived().TransformExpr(E->getArg(0));
7793
Douglas Gregorb98b1992009-08-11 05:31:07 +00007794 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7795
7796 QualType T = getDerived().TransformType(E->getType());
7797 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007798 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007799
7800 CXXConstructorDecl *Constructor
7801 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007802 getDerived().TransformDecl(E->getLocStart(),
7803 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007804 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007805 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007806
Douglas Gregorb98b1992009-08-11 05:31:07 +00007807 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007808 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007809 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7810 &ArgumentChanged))
7811 return ExprError();
7812
Douglas Gregorb98b1992009-08-11 05:31:07 +00007813 if (!getDerived().AlwaysRebuild() &&
7814 T == E->getType() &&
7815 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007816 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007817 // Mark the constructor as referenced.
7818 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007819 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007820 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007821 }
Mike Stump1eb44332009-09-09 15:08:12 +00007822
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007823 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7824 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007825 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007826 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007827 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007828 E->getConstructionKind(),
7829 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007830}
Mike Stump1eb44332009-09-09 15:08:12 +00007831
Douglas Gregorb98b1992009-08-11 05:31:07 +00007832/// \brief Transform a C++ temporary-binding expression.
7833///
Douglas Gregor51326552009-12-24 18:51:59 +00007834/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7835/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007836template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007837ExprResult
John McCall454feb92009-12-08 09:21:05 +00007838TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007839 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007840}
Mike Stump1eb44332009-09-09 15:08:12 +00007841
John McCall4765fa02010-12-06 08:20:24 +00007842/// \brief Transform a C++ expression that contains cleanups that should
7843/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007844///
John McCall4765fa02010-12-06 08:20:24 +00007845/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007846/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007847template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007848ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007849TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007850 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007851}
Mike Stump1eb44332009-09-09 15:08:12 +00007852
Douglas Gregorb98b1992009-08-11 05:31:07 +00007853template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007854ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007855TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007856 CXXTemporaryObjectExpr *E) {
7857 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7858 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007859 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007860
Douglas Gregorb98b1992009-08-11 05:31:07 +00007861 CXXConstructorDecl *Constructor
7862 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007863 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007864 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007865 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007866 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007867
Douglas Gregorb98b1992009-08-11 05:31:07 +00007868 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007869 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007870 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007871 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7872 &ArgumentChanged))
7873 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007874
Douglas Gregorb98b1992009-08-11 05:31:07 +00007875 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007876 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007877 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007878 !ArgumentChanged) {
7879 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007880 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007881 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007882 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007883
7884 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7885 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007886 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007887 E->getLocEnd());
7888}
Mike Stump1eb44332009-09-09 15:08:12 +00007889
Douglas Gregorb98b1992009-08-11 05:31:07 +00007890template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007891ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007892TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007893 // Create the local class that will describe the lambda.
7894 CXXRecordDecl *Class
Douglas Gregorf54486a2012-04-04 17:40:10 +00007895 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7896 /*KnownDependent=*/false);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007897 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7898
7899 // Transform the type of the lambda parameters and start the definition of
7900 // the lambda itself.
7901 TypeSourceInfo *MethodTy
7902 = TransformType(E->getCallOperator()->getTypeSourceInfo());
7903 if (!MethodTy)
7904 return ExprError();
7905
Douglas Gregorc6889e72012-02-14 22:28:59 +00007906 // Transform lambda parameters.
7907 bool Invalid = false;
7908 llvm::SmallVector<QualType, 4> ParamTypes;
7909 llvm::SmallVector<ParmVarDecl *, 4> Params;
7910 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7911 E->getCallOperator()->param_begin(),
7912 E->getCallOperator()->param_size(),
7913 0, ParamTypes, &Params))
7914 Invalid = true;
7915
Douglas Gregordfca6f52012-02-13 22:00:16 +00007916 // Build the call operator.
Douglas Gregorf54486a2012-04-04 17:40:10 +00007917 // Note: Once a lambda mangling number and context declaration have been
7918 // assigned, they never change.
7919 unsigned ManglingNumber = E->getLambdaClass()->getLambdaManglingNumber();
7920 Decl *ContextDecl = E->getLambdaClass()->getLambdaContextDecl();
Douglas Gregordfca6f52012-02-13 22:00:16 +00007921 CXXMethodDecl *CallOperator
7922 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
7923 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007924 E->getCallOperator()->getLocEnd(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00007925 Params, ManglingNumber, ContextDecl);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007926 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
7927
Douglas Gregord5387e82012-02-14 00:00:48 +00007928 // FIXME: Instantiation-specific.
7929 CallOperator->setInstantiationOfMemberFunction(E->getCallOperator(),
7930 TSK_ImplicitInstantiation);
7931
7932 // Introduce the context of the call operator.
7933 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7934
Douglas Gregordfca6f52012-02-13 22:00:16 +00007935 // Enter the scope of the lambda.
7936 sema::LambdaScopeInfo *LSI
7937 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7938 E->getCaptureDefault(),
7939 E->hasExplicitParameters(),
7940 E->hasExplicitResultType(),
7941 E->isMutable());
7942
7943 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00007944 bool FinishedExplicitCaptures = false;
7945 for (LambdaExpr::capture_iterator C = E->capture_begin(),
7946 CEnd = E->capture_end();
7947 C != CEnd; ++C) {
7948 // When we hit the first implicit capture, tell Sema that we've finished
7949 // the list of explicit captures.
7950 if (!FinishedExplicitCaptures && C->isImplicit()) {
7951 getSema().finishLambdaExplicitCaptures(LSI);
7952 FinishedExplicitCaptures = true;
7953 }
7954
7955 // Capturing 'this' is trivial.
7956 if (C->capturesThis()) {
7957 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7958 continue;
7959 }
7960
Douglas Gregora7365242012-02-14 19:27:52 +00007961 // Determine the capture kind for Sema.
7962 Sema::TryCaptureKind Kind
7963 = C->isImplicit()? Sema::TryCapture_Implicit
7964 : C->getCaptureKind() == LCK_ByCopy
7965 ? Sema::TryCapture_ExplicitByVal
7966 : Sema::TryCapture_ExplicitByRef;
7967 SourceLocation EllipsisLoc;
7968 if (C->isPackExpansion()) {
7969 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7970 bool ShouldExpand = false;
7971 bool RetainExpansion = false;
7972 llvm::Optional<unsigned> NumExpansions;
7973 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7974 C->getLocation(),
7975 Unexpanded,
7976 ShouldExpand, RetainExpansion,
7977 NumExpansions))
7978 return ExprError();
7979
7980 if (ShouldExpand) {
7981 // The transform has determined that we should perform an expansion;
7982 // transform and capture each of the arguments.
7983 // expansion of the pattern. Do so.
7984 VarDecl *Pack = C->getCapturedVar();
7985 for (unsigned I = 0; I != *NumExpansions; ++I) {
7986 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7987 VarDecl *CapturedVar
7988 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7989 Pack));
7990 if (!CapturedVar) {
7991 Invalid = true;
7992 continue;
7993 }
7994
7995 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007996 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregora7365242012-02-14 19:27:52 +00007997 }
7998 continue;
7999 }
8000
8001 EllipsisLoc = C->getEllipsisLoc();
8002 }
8003
Douglas Gregordfca6f52012-02-13 22:00:16 +00008004 // Transform the captured variable.
8005 VarDecl *CapturedVar
8006 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
8007 C->getCapturedVar()));
8008 if (!CapturedVar) {
8009 Invalid = true;
8010 continue;
8011 }
Douglas Gregora7365242012-02-14 19:27:52 +00008012
Douglas Gregordfca6f52012-02-13 22:00:16 +00008013 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008014 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008015 }
8016 if (!FinishedExplicitCaptures)
8017 getSema().finishLambdaExplicitCaptures(LSI);
8018
Douglas Gregordfca6f52012-02-13 22:00:16 +00008019
8020 // Enter a new evaluation context to insulate the lambda from any
8021 // cleanups from the enclosing full-expression.
8022 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
8023
8024 if (Invalid) {
8025 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
8026 /*IsInstantiation=*/true);
8027 return ExprError();
8028 }
8029
8030 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008031 StmtResult Body = getDerived().TransformStmt(E->getBody());
8032 if (Body.isInvalid()) {
8033 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
8034 /*IsInstantiation=*/true);
8035 return ExprError();
8036 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008037
Douglas Gregordfca6f52012-02-13 22:00:16 +00008038 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008039 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008040}
8041
8042template<typename Derived>
8043ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008044TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008045 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008046 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8047 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008048 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008049
Douglas Gregorb98b1992009-08-11 05:31:07 +00008050 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008051 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008052 Args.reserve(E->arg_size());
8053 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
8054 &ArgumentChanged))
8055 return ExprError();
8056
Douglas Gregorb98b1992009-08-11 05:31:07 +00008057 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008058 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008059 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008060 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008061
Douglas Gregorb98b1992009-08-11 05:31:07 +00008062 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008063 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008064 E->getLParenLoc(),
8065 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00008066 E->getRParenLoc());
8067}
Mike Stump1eb44332009-09-09 15:08:12 +00008068
Douglas Gregorb98b1992009-08-11 05:31:07 +00008069template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008070ExprResult
John McCall865d4472009-11-19 22:55:06 +00008071TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008072 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008073 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008074 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008075 Expr *OldBase;
8076 QualType BaseType;
8077 QualType ObjectType;
8078 if (!E->isImplicitAccess()) {
8079 OldBase = E->getBase();
8080 Base = getDerived().TransformExpr(OldBase);
8081 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008082 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008083
John McCallaa81e162009-12-01 22:10:20 +00008084 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008085 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008086 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008087 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008088 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008089 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008090 ObjectTy,
8091 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008092 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008093 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008094
John McCallb3d87482010-08-24 05:47:05 +00008095 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008096 BaseType = ((Expr*) Base.get())->getType();
8097 } else {
8098 OldBase = 0;
8099 BaseType = getDerived().TransformType(E->getBaseType());
8100 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8101 }
Mike Stump1eb44332009-09-09 15:08:12 +00008102
Douglas Gregor6cd21982009-10-20 05:58:46 +00008103 // Transform the first part of the nested-name-specifier that qualifies
8104 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008105 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008106 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008107 E->getFirstQualifierFoundInScope(),
8108 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008109
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008110 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008111 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008112 QualifierLoc
8113 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8114 ObjectType,
8115 FirstQualifierInScope);
8116 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008117 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008118 }
Mike Stump1eb44332009-09-09 15:08:12 +00008119
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008120 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8121
John McCall43fed0d2010-11-12 08:19:04 +00008122 // TODO: If this is a conversion-function-id, verify that the
8123 // destination type name (if present) resolves the same way after
8124 // instantiation as it did in the local scope.
8125
Abramo Bagnara25777432010-08-11 22:01:17 +00008126 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008127 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008128 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008129 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008130
John McCallaa81e162009-12-01 22:10:20 +00008131 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008132 // This is a reference to a member without an explicitly-specified
8133 // template argument list. Optimize for this common case.
8134 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008135 Base.get() == OldBase &&
8136 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008137 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008138 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008139 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008140 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008141
John McCall9ae2f072010-08-23 23:25:46 +00008142 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008143 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008144 E->isArrow(),
8145 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008146 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008147 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008148 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008149 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008150 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008151 }
8152
John McCalld5532b62009-11-23 01:53:49 +00008153 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008154 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8155 E->getNumTemplateArgs(),
8156 TransArgs))
8157 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008158
John McCall9ae2f072010-08-23 23:25:46 +00008159 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008160 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008161 E->isArrow(),
8162 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008163 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008164 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008165 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008166 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008167 &TransArgs);
8168}
8169
8170template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008171ExprResult
John McCall454feb92009-12-08 09:21:05 +00008172TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008173 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008174 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008175 QualType BaseType;
8176 if (!Old->isImplicitAccess()) {
8177 Base = getDerived().TransformExpr(Old->getBase());
8178 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008179 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008180 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8181 Old->isArrow());
8182 if (Base.isInvalid())
8183 return ExprError();
8184 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008185 } else {
8186 BaseType = getDerived().TransformType(Old->getBaseType());
8187 }
John McCall129e2df2009-11-30 22:42:35 +00008188
Douglas Gregor4c9be892011-02-28 20:01:57 +00008189 NestedNameSpecifierLoc QualifierLoc;
8190 if (Old->getQualifierLoc()) {
8191 QualifierLoc
8192 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8193 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008194 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008195 }
8196
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008197 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8198
Abramo Bagnara25777432010-08-11 22:01:17 +00008199 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008200 Sema::LookupOrdinaryName);
8201
8202 // Transform all the decls.
8203 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8204 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008205 NamedDecl *InstD = static_cast<NamedDecl*>(
8206 getDerived().TransformDecl(Old->getMemberLoc(),
8207 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008208 if (!InstD) {
8209 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8210 // This can happen because of dependent hiding.
8211 if (isa<UsingShadowDecl>(*I))
8212 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008213 else {
8214 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008215 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008216 }
John McCall9f54ad42009-12-10 09:41:52 +00008217 }
John McCall129e2df2009-11-30 22:42:35 +00008218
8219 // Expand using declarations.
8220 if (isa<UsingDecl>(InstD)) {
8221 UsingDecl *UD = cast<UsingDecl>(InstD);
8222 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8223 E = UD->shadow_end(); I != E; ++I)
8224 R.addDecl(*I);
8225 continue;
8226 }
8227
8228 R.addDecl(InstD);
8229 }
8230
8231 R.resolveKind();
8232
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008233 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008234 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00008235 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008236 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008237 Old->getMemberLoc(),
8238 Old->getNamingClass()));
8239 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008240 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008241
Douglas Gregor66c45152010-04-27 16:10:10 +00008242 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008243 }
Sean Huntc3021132010-05-05 15:23:54 +00008244
John McCall129e2df2009-11-30 22:42:35 +00008245 TemplateArgumentListInfo TransArgs;
8246 if (Old->hasExplicitTemplateArgs()) {
8247 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8248 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008249 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8250 Old->getNumTemplateArgs(),
8251 TransArgs))
8252 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008253 }
John McCallc2233c52010-01-15 08:34:02 +00008254
8255 // FIXME: to do this check properly, we will need to preserve the
8256 // first-qualifier-in-scope here, just in case we had a dependent
8257 // base (and therefore couldn't do the check) and a
8258 // nested-name-qualifier (and therefore could do the lookup).
8259 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00008260
John McCall9ae2f072010-08-23 23:25:46 +00008261 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008262 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008263 Old->getOperatorLoc(),
8264 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008265 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008266 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008267 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008268 R,
8269 (Old->hasExplicitTemplateArgs()
8270 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008271}
8272
8273template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008274ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008275TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008276 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008277 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8278 if (SubExpr.isInvalid())
8279 return ExprError();
8280
8281 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008282 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008283
8284 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8285}
8286
8287template<typename Derived>
8288ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008289TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008290 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8291 if (Pattern.isInvalid())
8292 return ExprError();
8293
8294 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8295 return SemaRef.Owned(E);
8296
Douglas Gregor67fd1252011-01-14 21:20:45 +00008297 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8298 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008299}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008300
8301template<typename Derived>
8302ExprResult
8303TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8304 // If E is not value-dependent, then nothing will change when we transform it.
8305 // Note: This is an instantiation-centric view.
8306 if (!E->isValueDependent())
8307 return SemaRef.Owned(E);
8308
8309 // Note: None of the implementations of TryExpandParameterPacks can ever
8310 // produce a diagnostic when given only a single unexpanded parameter pack,
8311 // so
8312 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8313 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008314 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008315 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00008316 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008317 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008318 ShouldExpand, RetainExpansion,
8319 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008320 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00008321
Douglas Gregor089e8932011-10-10 18:59:29 +00008322 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008323 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00008324
8325 NamedDecl *Pack = E->getPack();
8326 if (!ShouldExpand) {
8327 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
8328 Pack));
8329 if (!Pack)
8330 return ExprError();
8331 }
8332
Douglas Gregoree8aff02011-01-04 17:33:58 +00008333
8334 // We now know the length of the parameter pack, so build a new expression
8335 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00008336 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00008337 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008338 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008339}
8340
Douglas Gregorbe230c32011-01-03 17:17:50 +00008341template<typename Derived>
8342ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008343TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8344 SubstNonTypeTemplateParmPackExpr *E) {
8345 // Default behavior is to do nothing with this transformation.
8346 return SemaRef.Owned(E);
8347}
8348
8349template<typename Derived>
8350ExprResult
John McCall91a57552011-07-15 05:09:51 +00008351TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8352 SubstNonTypeTemplateParmExpr *E) {
8353 // Default behavior is to do nothing with this transformation.
8354 return SemaRef.Owned(E);
8355}
8356
8357template<typename Derived>
8358ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008359TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8360 MaterializeTemporaryExpr *E) {
8361 return getDerived().TransformExpr(E->GetTemporaryExpr());
8362}
8363
8364template<typename Derived>
8365ExprResult
John McCall454feb92009-12-08 09:21:05 +00008366TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008367 return SemaRef.MaybeBindToTemporary(E);
8368}
8369
8370template<typename Derived>
8371ExprResult
8372TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008373 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008374}
8375
8376template<typename Derived>
8377ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008378TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8379 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8380 if (SubExpr.isInvalid())
8381 return ExprError();
8382
8383 if (!getDerived().AlwaysRebuild() &&
8384 SubExpr.get() == E->getSubExpr())
8385 return SemaRef.Owned(E);
8386
8387 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008388}
8389
8390template<typename Derived>
8391ExprResult
8392TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8393 // Transform each of the elements.
8394 llvm::SmallVector<Expr *, 8> Elements;
8395 bool ArgChanged = false;
8396 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
8397 /*IsCall=*/false, Elements, &ArgChanged))
8398 return ExprError();
8399
8400 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8401 return SemaRef.MaybeBindToTemporary(E);
8402
8403 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8404 Elements.data(),
8405 Elements.size());
8406}
8407
8408template<typename Derived>
8409ExprResult
8410TreeTransform<Derived>::TransformObjCDictionaryLiteral(
8411 ObjCDictionaryLiteral *E) {
8412 // Transform each of the elements.
8413 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8414 bool ArgChanged = false;
8415 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8416 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
8417
8418 if (OrigElement.isPackExpansion()) {
8419 // This key/value element is a pack expansion.
8420 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8421 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8422 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8423 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8424
8425 // Determine whether the set of unexpanded parameter packs can
8426 // and should be expanded.
8427 bool Expand = true;
8428 bool RetainExpansion = false;
8429 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8430 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8431 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8432 OrigElement.Value->getLocEnd());
8433 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8434 PatternRange,
8435 Unexpanded,
8436 Expand, RetainExpansion,
8437 NumExpansions))
8438 return ExprError();
8439
8440 if (!Expand) {
8441 // The transform has determined that we should perform a simple
8442 // transformation on the pack expansion, producing another pack
8443 // expansion.
8444 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8445 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8446 if (Key.isInvalid())
8447 return ExprError();
8448
8449 if (Key.get() != OrigElement.Key)
8450 ArgChanged = true;
8451
8452 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8453 if (Value.isInvalid())
8454 return ExprError();
8455
8456 if (Value.get() != OrigElement.Value)
8457 ArgChanged = true;
8458
8459 ObjCDictionaryElement Expansion = {
8460 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8461 };
8462 Elements.push_back(Expansion);
8463 continue;
8464 }
8465
8466 // Record right away that the argument was changed. This needs
8467 // to happen even if the array expands to nothing.
8468 ArgChanged = true;
8469
8470 // The transform has determined that we should perform an elementwise
8471 // expansion of the pattern. Do so.
8472 for (unsigned I = 0; I != *NumExpansions; ++I) {
8473 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8474 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8475 if (Key.isInvalid())
8476 return ExprError();
8477
8478 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8479 if (Value.isInvalid())
8480 return ExprError();
8481
8482 ObjCDictionaryElement Element = {
8483 Key.get(), Value.get(), SourceLocation(), NumExpansions
8484 };
8485
8486 // If any unexpanded parameter packs remain, we still have a
8487 // pack expansion.
8488 if (Key.get()->containsUnexpandedParameterPack() ||
8489 Value.get()->containsUnexpandedParameterPack())
8490 Element.EllipsisLoc = OrigElement.EllipsisLoc;
8491
8492 Elements.push_back(Element);
8493 }
8494
8495 // We've finished with this pack expansion.
8496 continue;
8497 }
8498
8499 // Transform and check key.
8500 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8501 if (Key.isInvalid())
8502 return ExprError();
8503
8504 if (Key.get() != OrigElement.Key)
8505 ArgChanged = true;
8506
8507 // Transform and check value.
8508 ExprResult Value
8509 = getDerived().TransformExpr(OrigElement.Value);
8510 if (Value.isInvalid())
8511 return ExprError();
8512
8513 if (Value.get() != OrigElement.Value)
8514 ArgChanged = true;
8515
8516 ObjCDictionaryElement Element = {
8517 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8518 };
8519 Elements.push_back(Element);
8520 }
8521
8522 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8523 return SemaRef.MaybeBindToTemporary(E);
8524
8525 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8526 Elements.data(),
8527 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008528}
8529
Mike Stump1eb44332009-09-09 15:08:12 +00008530template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008531ExprResult
John McCall454feb92009-12-08 09:21:05 +00008532TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008533 TypeSourceInfo *EncodedTypeInfo
8534 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8535 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008536 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008537
Douglas Gregorb98b1992009-08-11 05:31:07 +00008538 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008539 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008540 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008541
8542 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008543 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008544 E->getRParenLoc());
8545}
Mike Stump1eb44332009-09-09 15:08:12 +00008546
Douglas Gregorb98b1992009-08-11 05:31:07 +00008547template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008548ExprResult TreeTransform<Derived>::
8549TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8550 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8551 if (result.isInvalid()) return ExprError();
8552 Expr *subExpr = result.take();
8553
8554 if (!getDerived().AlwaysRebuild() &&
8555 subExpr == E->getSubExpr())
8556 return SemaRef.Owned(E);
8557
8558 return SemaRef.Owned(new(SemaRef.Context)
8559 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8560}
8561
8562template<typename Derived>
8563ExprResult TreeTransform<Derived>::
8564TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
8565 TypeSourceInfo *TSInfo
8566 = getDerived().TransformType(E->getTypeInfoAsWritten());
8567 if (!TSInfo)
8568 return ExprError();
8569
8570 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
8571 if (Result.isInvalid())
8572 return ExprError();
8573
8574 if (!getDerived().AlwaysRebuild() &&
8575 TSInfo == E->getTypeInfoAsWritten() &&
8576 Result.get() == E->getSubExpr())
8577 return SemaRef.Owned(E);
8578
8579 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
8580 E->getBridgeKeywordLoc(), TSInfo,
8581 Result.get());
8582}
8583
8584template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008585ExprResult
John McCall454feb92009-12-08 09:21:05 +00008586TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008587 // Transform arguments.
8588 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008589 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008590 Args.reserve(E->getNumArgs());
8591 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
8592 &ArgChanged))
8593 return ExprError();
8594
Douglas Gregor92e986e2010-04-22 16:44:27 +00008595 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8596 // Class message: transform the receiver type.
8597 TypeSourceInfo *ReceiverTypeInfo
8598 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8599 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008600 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008601
Douglas Gregor92e986e2010-04-22 16:44:27 +00008602 // If nothing changed, just retain the existing message send.
8603 if (!getDerived().AlwaysRebuild() &&
8604 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008605 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008606
8607 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008608 SmallVector<SourceLocation, 16> SelLocs;
8609 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008610 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8611 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008612 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008613 E->getMethodDecl(),
8614 E->getLeftLoc(),
8615 move_arg(Args),
8616 E->getRightLoc());
8617 }
8618
8619 // Instance message: transform the receiver
8620 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8621 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008622 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008623 = getDerived().TransformExpr(E->getInstanceReceiver());
8624 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008625 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008626
8627 // If nothing changed, just retain the existing message send.
8628 if (!getDerived().AlwaysRebuild() &&
8629 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008630 return SemaRef.MaybeBindToTemporary(E);
Sean Huntc3021132010-05-05 15:23:54 +00008631
Douglas Gregor92e986e2010-04-22 16:44:27 +00008632 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008633 SmallVector<SourceLocation, 16> SelLocs;
8634 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008635 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008636 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008637 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008638 E->getMethodDecl(),
8639 E->getLeftLoc(),
8640 move_arg(Args),
8641 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008642}
8643
Mike Stump1eb44332009-09-09 15:08:12 +00008644template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008645ExprResult
John McCall454feb92009-12-08 09:21:05 +00008646TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008647 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008648}
8649
Mike Stump1eb44332009-09-09 15:08:12 +00008650template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008651ExprResult
John McCall454feb92009-12-08 09:21:05 +00008652TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008653 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008654}
8655
Mike Stump1eb44332009-09-09 15:08:12 +00008656template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008657ExprResult
John McCall454feb92009-12-08 09:21:05 +00008658TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008659 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008660 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008661 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008662 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008663
8664 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008665
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008666 // If nothing changed, just retain the existing expression.
8667 if (!getDerived().AlwaysRebuild() &&
8668 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008669 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008670
John McCall9ae2f072010-08-23 23:25:46 +00008671 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008672 E->getLocation(),
8673 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008674}
8675
Mike Stump1eb44332009-09-09 15:08:12 +00008676template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008677ExprResult
John McCall454feb92009-12-08 09:21:05 +00008678TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008679 // 'super' and types never change. Property never changes. Just
8680 // retain the existing expression.
8681 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008682 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00008683
Douglas Gregore3303542010-04-26 20:47:02 +00008684 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008685 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008686 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008687 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008688
Douglas Gregore3303542010-04-26 20:47:02 +00008689 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008690
Douglas Gregore3303542010-04-26 20:47:02 +00008691 // If nothing changed, just retain the existing expression.
8692 if (!getDerived().AlwaysRebuild() &&
8693 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008694 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008695
John McCall12f78a62010-12-02 01:19:52 +00008696 if (E->isExplicitProperty())
8697 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8698 E->getExplicitProperty(),
8699 E->getLocation());
8700
8701 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008702 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008703 E->getImplicitPropertyGetter(),
8704 E->getImplicitPropertySetter(),
8705 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008706}
8707
Mike Stump1eb44332009-09-09 15:08:12 +00008708template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008709ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008710TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8711 // Transform the base expression.
8712 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8713 if (Base.isInvalid())
8714 return ExprError();
8715
8716 // Transform the key expression.
8717 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8718 if (Key.isInvalid())
8719 return ExprError();
8720
8721 // If nothing changed, just retain the existing expression.
8722 if (!getDerived().AlwaysRebuild() &&
8723 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8724 return SemaRef.Owned(E);
8725
8726 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
8727 Base.get(), Key.get(),
8728 E->getAtIndexMethodDecl(),
8729 E->setAtIndexMethodDecl());
8730}
8731
8732template<typename Derived>
8733ExprResult
John McCall454feb92009-12-08 09:21:05 +00008734TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008735 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008736 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008737 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008738 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008739
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008740 // If nothing changed, just retain the existing expression.
8741 if (!getDerived().AlwaysRebuild() &&
8742 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008743 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008744
John McCall9ae2f072010-08-23 23:25:46 +00008745 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008746 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008747}
8748
Mike Stump1eb44332009-09-09 15:08:12 +00008749template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008750ExprResult
John McCall454feb92009-12-08 09:21:05 +00008751TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008752 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008753 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008754 SubExprs.reserve(E->getNumSubExprs());
8755 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8756 SubExprs, &ArgumentChanged))
8757 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008758
Douglas Gregorb98b1992009-08-11 05:31:07 +00008759 if (!getDerived().AlwaysRebuild() &&
8760 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008761 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008762
Douglas Gregorb98b1992009-08-11 05:31:07 +00008763 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8764 move_arg(SubExprs),
8765 E->getRParenLoc());
8766}
8767
Mike Stump1eb44332009-09-09 15:08:12 +00008768template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008769ExprResult
John McCall454feb92009-12-08 09:21:05 +00008770TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008771 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008772
John McCallc6ac9c32011-02-04 18:33:18 +00008773 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8774 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8775
8776 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008777 blockScope->TheDecl->setBlockMissingReturnType(
8778 oldBlock->blockMissingReturnType());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008779
Chris Lattner686775d2011-07-20 06:58:45 +00008780 SmallVector<ParmVarDecl*, 4> params;
8781 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008782
8783 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008784 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8785 oldBlock->param_begin(),
8786 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008787 0, paramTypes, &params)) {
8788 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008789 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008790 }
John McCallc6ac9c32011-02-04 18:33:18 +00008791
8792 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008793 QualType exprResultType =
8794 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008795
8796 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008797 if (exprResultType->isObjCObjectType()) {
John McCallc6ac9c32011-02-04 18:33:18 +00008798 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008799 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008800 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008801 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008802 return ExprError();
8803 }
John McCall711c52b2011-01-05 12:14:39 +00008804
John McCallc6ac9c32011-02-04 18:33:18 +00008805 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008806 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008807 paramTypes.data(),
8808 paramTypes.size(),
8809 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008810 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008811 exprFunctionType->getExtInfo());
8812 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008813
8814 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008815 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008816 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008817
8818 if (!oldBlock->blockMissingReturnType()) {
8819 blockScope->HasImplicitReturnType = false;
8820 blockScope->ReturnType = exprResultType;
8821 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008822
John McCall711c52b2011-01-05 12:14:39 +00008823 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008824 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008825 if (body.isInvalid()) {
8826 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008827 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008828 }
John McCall711c52b2011-01-05 12:14:39 +00008829
John McCallc6ac9c32011-02-04 18:33:18 +00008830#ifndef NDEBUG
8831 // In builds with assertions, make sure that we captured everything we
8832 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008833 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8834 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8835 e = oldBlock->capture_end(); i != e; ++i) {
8836 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008837
Douglas Gregorfc921372011-05-20 15:32:55 +00008838 // Ignore parameter packs.
8839 if (isa<ParmVarDecl>(oldCapture) &&
8840 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8841 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008842
Douglas Gregorfc921372011-05-20 15:32:55 +00008843 VarDecl *newCapture =
8844 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8845 oldCapture));
8846 assert(blockScope->CaptureMap.count(newCapture));
8847 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008848 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008849 }
8850#endif
8851
8852 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8853 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008854}
8855
Mike Stump1eb44332009-09-09 15:08:12 +00008856template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008857ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008858TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008859 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008860}
Eli Friedman276b0612011-10-11 02:20:01 +00008861
8862template<typename Derived>
8863ExprResult
8864TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008865 QualType RetTy = getDerived().TransformType(E->getType());
8866 bool ArgumentChanged = false;
8867 ASTOwningVector<Expr*> SubExprs(SemaRef);
8868 SubExprs.reserve(E->getNumSubExprs());
8869 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8870 SubExprs, &ArgumentChanged))
8871 return ExprError();
8872
8873 if (!getDerived().AlwaysRebuild() &&
8874 !ArgumentChanged)
8875 return SemaRef.Owned(E);
8876
8877 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8878 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008879}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008880
Douglas Gregorb98b1992009-08-11 05:31:07 +00008881//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008882// Type reconstruction
8883//===----------------------------------------------------------------------===//
8884
Mike Stump1eb44332009-09-09 15:08:12 +00008885template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008886QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8887 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008888 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008889 getDerived().getBaseEntity());
8890}
8891
Mike Stump1eb44332009-09-09 15:08:12 +00008892template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008893QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8894 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008895 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008896 getDerived().getBaseEntity());
8897}
8898
Mike Stump1eb44332009-09-09 15:08:12 +00008899template<typename Derived>
8900QualType
John McCall85737a72009-10-30 00:06:24 +00008901TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8902 bool WrittenAsLValue,
8903 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008904 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008905 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008906}
8907
8908template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008909QualType
John McCall85737a72009-10-30 00:06:24 +00008910TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8911 QualType ClassType,
8912 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008913 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008914 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008915}
8916
8917template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008918QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008919TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8920 ArrayType::ArraySizeModifier SizeMod,
8921 const llvm::APInt *Size,
8922 Expr *SizeExpr,
8923 unsigned IndexTypeQuals,
8924 SourceRange BracketsRange) {
8925 if (SizeExpr || !Size)
8926 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8927 IndexTypeQuals, BracketsRange,
8928 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008929
8930 QualType Types[] = {
8931 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8932 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8933 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008934 };
8935 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8936 QualType SizeType;
8937 for (unsigned I = 0; I != NumTypes; ++I)
8938 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8939 SizeType = Types[I];
8940 break;
8941 }
Mike Stump1eb44332009-09-09 15:08:12 +00008942
Eli Friedman01f276d2012-01-25 23:20:27 +00008943 // Note that we can return a VariableArrayType here in the case where
8944 // the element type was a dependent VariableArrayType.
8945 IntegerLiteral *ArraySize
8946 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8947 /*FIXME*/BracketsRange.getBegin());
8948 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008949 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008950 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008951}
Mike Stump1eb44332009-09-09 15:08:12 +00008952
Douglas Gregor577f75a2009-08-04 16:50:30 +00008953template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008954QualType
8955TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008956 ArrayType::ArraySizeModifier SizeMod,
8957 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008958 unsigned IndexTypeQuals,
8959 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008960 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008961 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008962}
8963
8964template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008965QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008966TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008967 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008968 unsigned IndexTypeQuals,
8969 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008970 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008971 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008972}
Mike Stump1eb44332009-09-09 15:08:12 +00008973
Douglas Gregor577f75a2009-08-04 16:50:30 +00008974template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008975QualType
8976TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008977 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008978 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008979 unsigned IndexTypeQuals,
8980 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008981 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008982 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008983 IndexTypeQuals, BracketsRange);
8984}
8985
8986template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008987QualType
8988TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008989 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008990 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008991 unsigned IndexTypeQuals,
8992 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008993 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008994 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008995 IndexTypeQuals, BracketsRange);
8996}
8997
8998template<typename Derived>
8999QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009000 unsigned NumElements,
9001 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009002 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009003 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009004}
Mike Stump1eb44332009-09-09 15:08:12 +00009005
Douglas Gregor577f75a2009-08-04 16:50:30 +00009006template<typename Derived>
9007QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9008 unsigned NumElements,
9009 SourceLocation AttributeLoc) {
9010 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9011 NumElements, true);
9012 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009013 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9014 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009015 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009016}
Mike Stump1eb44332009-09-09 15:08:12 +00009017
Douglas Gregor577f75a2009-08-04 16:50:30 +00009018template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009019QualType
9020TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009021 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009022 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009023 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009024}
Mike Stump1eb44332009-09-09 15:08:12 +00009025
Douglas Gregor577f75a2009-08-04 16:50:30 +00009026template<typename Derived>
9027QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00009028 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009029 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00009030 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009031 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00009032 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00009033 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00009034 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00009035 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009036 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009037 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009038 getDerived().getBaseEntity(),
9039 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009040}
Mike Stump1eb44332009-09-09 15:08:12 +00009041
Douglas Gregor577f75a2009-08-04 16:50:30 +00009042template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009043QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9044 return SemaRef.Context.getFunctionNoProtoType(T);
9045}
9046
9047template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009048QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9049 assert(D && "no decl found");
9050 if (D->isInvalidDecl()) return QualType();
9051
Douglas Gregor92e986e2010-04-22 16:44:27 +00009052 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009053 TypeDecl *Ty;
9054 if (isa<UsingDecl>(D)) {
9055 UsingDecl *Using = cast<UsingDecl>(D);
9056 assert(Using->isTypeName() &&
9057 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9058
9059 // A valid resolved using typename decl points to exactly one type decl.
9060 assert(++Using->shadow_begin() == Using->shadow_end());
9061 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00009062
John McCalled976492009-12-04 22:46:56 +00009063 } else {
9064 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9065 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9066 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9067 }
9068
9069 return SemaRef.Context.getTypeDeclType(Ty);
9070}
9071
9072template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009073QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9074 SourceLocation Loc) {
9075 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009076}
9077
9078template<typename Derived>
9079QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9080 return SemaRef.Context.getTypeOfType(Underlying);
9081}
9082
9083template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009084QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9085 SourceLocation Loc) {
9086 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009087}
9088
9089template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009090QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9091 UnaryTransformType::UTTKind UKind,
9092 SourceLocation Loc) {
9093 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9094}
9095
9096template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009097QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009098 TemplateName Template,
9099 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009100 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009101 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009102}
Mike Stump1eb44332009-09-09 15:08:12 +00009103
Douglas Gregordcee1a12009-08-06 05:28:30 +00009104template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009105QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9106 SourceLocation KWLoc) {
9107 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9108}
9109
9110template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009111TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009112TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009113 bool TemplateKW,
9114 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009115 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009116 Template);
9117}
9118
9119template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009120TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009121TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9122 const IdentifierInfo &Name,
9123 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009124 QualType ObjectType,
9125 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009126 UnqualifiedId TemplateName;
9127 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009128 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009129 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009130 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009131 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009132 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009133 /*EnteringContext=*/false,
9134 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009135 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009136}
Mike Stump1eb44332009-09-09 15:08:12 +00009137
Douglas Gregorb98b1992009-08-11 05:31:07 +00009138template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009139TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009140TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009141 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009142 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009143 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009144 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009145 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009146 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009147 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009148 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009149 Sema::TemplateTy Template;
9150 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009151 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009152 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009153 /*EnteringContext=*/false,
9154 Template);
9155 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009156}
Sean Huntc3021132010-05-05 15:23:54 +00009157
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009158template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009159ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009160TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9161 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009162 Expr *OrigCallee,
9163 Expr *First,
9164 Expr *Second) {
9165 Expr *Callee = OrigCallee->IgnoreParenCasts();
9166 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009167
Douglas Gregorb98b1992009-08-11 05:31:07 +00009168 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009169 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009170 if (!First->getType()->isOverloadableType() &&
9171 !Second->getType()->isOverloadableType())
9172 return getSema().CreateBuiltinArraySubscriptExpr(First,
9173 Callee->getLocStart(),
9174 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009175 } else if (Op == OO_Arrow) {
9176 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009177 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9178 } else if (Second == 0 || isPostIncDec) {
9179 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009180 // The argument is not of overloadable type, so try to create a
9181 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009182 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009183 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009184
John McCall9ae2f072010-08-23 23:25:46 +00009185 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009186 }
9187 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009188 if (!First->getType()->isOverloadableType() &&
9189 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009190 // Neither of the arguments is an overloadable type, so try to
9191 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009192 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009193 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009194 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009195 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009196 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009197
Douglas Gregorb98b1992009-08-11 05:31:07 +00009198 return move(Result);
9199 }
9200 }
Mike Stump1eb44332009-09-09 15:08:12 +00009201
9202 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009203 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009204 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009205
John McCall9ae2f072010-08-23 23:25:46 +00009206 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009207 assert(ULE->requiresADL());
9208
9209 // FIXME: Do we have to check
9210 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009211 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009212 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009213 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00009214 }
Mike Stump1eb44332009-09-09 15:08:12 +00009215
Douglas Gregorb98b1992009-08-11 05:31:07 +00009216 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009217 Expr *Args[2] = { First, Second };
9218 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009219
Douglas Gregorb98b1992009-08-11 05:31:07 +00009220 // Create the overloaded operator invocation for unary operators.
9221 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009222 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009223 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009224 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009225 }
Mike Stump1eb44332009-09-09 15:08:12 +00009226
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009227 if (Op == OO_Subscript) {
9228 SourceLocation LBrace;
9229 SourceLocation RBrace;
9230
9231 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9232 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9233 LBrace = SourceLocation::getFromRawEncoding(
9234 NameLoc.CXXOperatorName.BeginOpNameLoc);
9235 RBrace = SourceLocation::getFromRawEncoding(
9236 NameLoc.CXXOperatorName.EndOpNameLoc);
9237 } else {
9238 LBrace = Callee->getLocStart();
9239 RBrace = OpLoc;
9240 }
9241
9242 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9243 First, Second);
9244 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009245
Douglas Gregorb98b1992009-08-11 05:31:07 +00009246 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009247 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009248 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009249 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9250 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009251 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009252
Mike Stump1eb44332009-09-09 15:08:12 +00009253 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009254}
Mike Stump1eb44332009-09-09 15:08:12 +00009255
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009256template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009257ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009258TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009259 SourceLocation OperatorLoc,
9260 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009261 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009262 TypeSourceInfo *ScopeType,
9263 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009264 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009265 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009266 QualType BaseType = Base->getType();
9267 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009268 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00009269 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009270 !BaseType->getAs<PointerType>()->getPointeeType()
9271 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009272 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009273 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009274 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009275 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009276 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009277 /*FIXME?*/true);
9278 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009279
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009280 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009281 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9282 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9283 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9284 NameInfo.setNamedTypeInfo(DestroyedType);
9285
Richard Smith6314db92012-05-15 06:15:11 +00009286 // The scope type is now known to be a valid nested name specifier
9287 // component. Tack it on to the end of the nested name specifier.
9288 if (ScopeType)
9289 SS.Extend(SemaRef.Context, SourceLocation(),
9290 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009291
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009292 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009293 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009294 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009295 SS, TemplateKWLoc,
9296 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009297 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009298 /*TemplateArgs*/ 0);
9299}
9300
Douglas Gregor577f75a2009-08-04 16:50:30 +00009301} // end namespace clang
9302
9303#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H