blob: b03f86bb0ed7cb641ee588837c1e677d17838005 [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.
Alexander Kornienko49908902012-07-09 10:04:07 +00001053 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1054 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001055 Stmt *SubStmt) {
1056 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1057 }
1058
Douglas Gregor43959a92009-08-20 07:17:43 +00001059 /// \brief Build a new "if" statement.
1060 ///
1061 /// By default, performs semantic analysis to build the new statement.
1062 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001063 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001064 VarDecl *CondVar, Stmt *Then,
1065 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001066 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001067 }
Mike Stump1eb44332009-09-09 15:08:12 +00001068
Douglas Gregor43959a92009-08-20 07:17:43 +00001069 /// \brief Start building a new switch statement.
1070 ///
1071 /// By default, performs semantic analysis to build the new statement.
1072 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001073 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001074 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001075 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001076 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001077 }
Mike Stump1eb44332009-09-09 15:08:12 +00001078
Douglas Gregor43959a92009-08-20 07:17:43 +00001079 /// \brief Attach the body to the switch statement.
1080 ///
1081 /// By default, performs semantic analysis to build the new statement.
1082 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001083 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001084 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001085 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001086 }
1087
1088 /// \brief Build a new while statement.
1089 ///
1090 /// By default, performs semantic analysis to build the new statement.
1091 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001092 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1093 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001094 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001095 }
Mike Stump1eb44332009-09-09 15:08:12 +00001096
Douglas Gregor43959a92009-08-20 07:17:43 +00001097 /// \brief Build a new do-while statement.
1098 ///
1099 /// By default, performs semantic analysis to build the new statement.
1100 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001101 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001102 SourceLocation WhileLoc, SourceLocation LParenLoc,
1103 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001104 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1105 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001106 }
1107
1108 /// \brief Build a new for statement.
1109 ///
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001112 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1113 Stmt *Init, Sema::FullExprArg Cond,
1114 VarDecl *CondVar, Sema::FullExprArg Inc,
1115 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001116 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001117 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001118 }
Mike Stump1eb44332009-09-09 15:08:12 +00001119
Douglas Gregor43959a92009-08-20 07:17:43 +00001120 /// \brief Build a new goto statement.
1121 ///
1122 /// By default, performs semantic analysis to build the new statement.
1123 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001124 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1125 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001126 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001127 }
1128
1129 /// \brief Build a new indirect goto statement.
1130 ///
1131 /// By default, performs semantic analysis to build the new statement.
1132 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001133 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001134 SourceLocation StarLoc,
1135 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001136 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001137 }
Mike Stump1eb44332009-09-09 15:08:12 +00001138
Douglas Gregor43959a92009-08-20 07:17:43 +00001139 /// \brief Build a new return statement.
1140 ///
1141 /// By default, performs semantic analysis to build the new statement.
1142 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001143 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001144 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001145 }
Mike Stump1eb44332009-09-09 15:08:12 +00001146
Douglas Gregor43959a92009-08-20 07:17:43 +00001147 /// \brief Build a new declaration statement.
1148 ///
1149 /// By default, performs semantic analysis to build the new statement.
1150 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001151 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001152 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001153 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001154 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1155 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001156 }
Mike Stump1eb44332009-09-09 15:08:12 +00001157
Anders Carlsson703e3942010-01-24 05:50:09 +00001158 /// \brief Build a new inline asm statement.
1159 ///
1160 /// By default, performs semantic analysis to build the new statement.
1161 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001162 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001163 bool IsSimple,
1164 bool IsVolatile,
1165 unsigned NumOutputs,
1166 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001167 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001168 MultiExprArg Constraints,
1169 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001170 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001171 MultiExprArg Clobbers,
1172 SourceLocation RParenLoc,
1173 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001174 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001175 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001176 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001177 RParenLoc, MSAsm);
1178 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001179
Chad Rosier8cd64b42012-06-11 20:47:18 +00001180 /// \brief Build a new MS style inline asm statement.
1181 ///
1182 /// By default, performs semantic analysis to build the new statement.
1183 /// Subclasses may override this routine to provide different behavior.
1184 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc,
1185 std::string &AsmString,
1186 SourceLocation EndLoc) {
1187 return getSema().ActOnMSAsmStmt(AsmLoc, AsmString, EndLoc);
1188 }
1189
James Dennett699c9042012-06-15 07:13:21 +00001190 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001191 ///
1192 /// By default, performs semantic analysis to build the new statement.
1193 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001194 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001195 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001196 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001197 Stmt *Finally) {
1198 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1199 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001200 }
1201
Douglas Gregorbe270a02010-04-26 17:57:08 +00001202 /// \brief Rebuild an Objective-C exception declaration.
1203 ///
1204 /// By default, performs semantic analysis to build the new declaration.
1205 /// Subclasses may override this routine to provide different behavior.
1206 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1207 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001208 return getSema().BuildObjCExceptionDecl(TInfo, T,
1209 ExceptionDecl->getInnerLocStart(),
1210 ExceptionDecl->getLocation(),
1211 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001212 }
Sean Huntc3021132010-05-05 15:23:54 +00001213
James Dennett699c9042012-06-15 07:13:21 +00001214 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001215 ///
1216 /// By default, performs semantic analysis to build the new statement.
1217 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001218 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001219 SourceLocation RParenLoc,
1220 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001221 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001222 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001223 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001224 }
Sean Huntc3021132010-05-05 15:23:54 +00001225
James Dennett699c9042012-06-15 07:13:21 +00001226 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001227 ///
1228 /// By default, performs semantic analysis to build the new statement.
1229 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001230 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001231 Stmt *Body) {
1232 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001233 }
Sean Huntc3021132010-05-05 15:23:54 +00001234
James Dennett699c9042012-06-15 07:13:21 +00001235 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001236 ///
1237 /// By default, performs semantic analysis to build the new statement.
1238 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001239 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001240 Expr *Operand) {
1241 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001242 }
Sean Huntc3021132010-05-05 15:23:54 +00001243
James Dennett699c9042012-06-15 07:13:21 +00001244 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001245 ///
1246 /// By default, performs semantic analysis to build the new statement.
1247 /// Subclasses may override this routine to provide different behavior.
1248 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1249 Expr *object) {
1250 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1251 }
1252
James Dennett699c9042012-06-15 07:13:21 +00001253 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001254 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001255 /// By default, performs semantic analysis to build the new statement.
1256 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001257 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001258 Expr *Object, Stmt *Body) {
1259 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001260 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001261
James Dennett699c9042012-06-15 07:13:21 +00001262 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001263 ///
1264 /// By default, performs semantic analysis to build the new statement.
1265 /// Subclasses may override this routine to provide different behavior.
1266 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1267 Stmt *Body) {
1268 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1269 }
John McCall990567c2011-07-27 01:07:15 +00001270
Douglas Gregorc3203e72010-04-22 23:10:45 +00001271 /// \brief Build a new Objective-C fast enumeration statement.
1272 ///
1273 /// By default, performs semantic analysis to build the new statement.
1274 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001275 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001276 SourceLocation LParenLoc,
1277 Stmt *Element,
1278 Expr *Collection,
1279 SourceLocation RParenLoc,
1280 Stmt *Body) {
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001281 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
1282 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001283 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001284 RParenLoc);
1285 if (ForEachStmt.isInvalid())
1286 return StmtError();
1287
1288 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001289 }
Sean Huntc3021132010-05-05 15:23:54 +00001290
Douglas Gregor43959a92009-08-20 07:17:43 +00001291 /// \brief Build a new C++ exception declaration.
1292 ///
1293 /// By default, performs semantic analysis to build the new decaration.
1294 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001295 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001296 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001297 SourceLocation StartLoc,
1298 SourceLocation IdLoc,
1299 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001300 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1301 StartLoc, IdLoc, Id);
1302 if (Var)
1303 getSema().CurContext->addDecl(Var);
1304 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001305 }
1306
1307 /// \brief Build a new C++ catch statement.
1308 ///
1309 /// By default, performs semantic analysis to build the new statement.
1310 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001311 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001312 VarDecl *ExceptionDecl,
1313 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001314 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1315 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001316 }
Mike Stump1eb44332009-09-09 15:08:12 +00001317
Douglas Gregor43959a92009-08-20 07:17:43 +00001318 /// \brief Build a new C++ try statement.
1319 ///
1320 /// By default, performs semantic analysis to build the new statement.
1321 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001322 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001323 Stmt *TryBlock,
1324 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001325 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001326 }
Mike Stump1eb44332009-09-09 15:08:12 +00001327
Richard Smithad762fc2011-04-14 22:09:26 +00001328 /// \brief Build a new C++0x range-based for statement.
1329 ///
1330 /// By default, performs semantic analysis to build the new statement.
1331 /// Subclasses may override this routine to provide different behavior.
1332 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1333 SourceLocation ColonLoc,
1334 Stmt *Range, Stmt *BeginEnd,
1335 Expr *Cond, Expr *Inc,
1336 Stmt *LoopVar,
1337 SourceLocation RParenLoc) {
1338 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1339 Cond, Inc, LoopVar, RParenLoc);
1340 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001341
1342 /// \brief Build a new C++0x range-based for statement.
1343 ///
1344 /// By default, performs semantic analysis to build the new statement.
1345 /// Subclasses may override this routine to provide different behavior.
1346 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1347 bool IsIfExists,
1348 NestedNameSpecifierLoc QualifierLoc,
1349 DeclarationNameInfo NameInfo,
1350 Stmt *Nested) {
1351 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1352 QualifierLoc, NameInfo, Nested);
1353 }
1354
Richard Smithad762fc2011-04-14 22:09:26 +00001355 /// \brief Attach body to a C++0x range-based for statement.
1356 ///
1357 /// By default, performs semantic analysis to finish the new statement.
1358 /// Subclasses may override this routine to provide different behavior.
1359 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1360 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1361 }
1362
John Wiegley28bbe4b2011-04-28 01:08:34 +00001363 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1364 SourceLocation TryLoc,
1365 Stmt *TryBlock,
1366 Stmt *Handler) {
1367 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1368 }
1369
1370 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1371 Expr *FilterExpr,
1372 Stmt *Block) {
1373 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1374 }
1375
1376 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1377 Stmt *Block) {
1378 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1379 }
1380
Douglas Gregorb98b1992009-08-11 05:31:07 +00001381 /// \brief Build a new expression that references a declaration.
1382 ///
1383 /// By default, performs semantic analysis to build the new expression.
1384 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001385 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001386 LookupResult &R,
1387 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001388 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1389 }
1390
1391
1392 /// \brief Build a new expression that references a declaration.
1393 ///
1394 /// By default, performs semantic analysis to build the new expression.
1395 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001396 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001397 ValueDecl *VD,
1398 const DeclarationNameInfo &NameInfo,
1399 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001400 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001401 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001402
1403 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001404
1405 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001406 }
Mike Stump1eb44332009-09-09 15:08:12 +00001407
Douglas Gregorb98b1992009-08-11 05:31:07 +00001408 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001409 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001410 /// By default, performs semantic analysis to build the new expression.
1411 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001412 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001413 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001414 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 }
1416
Douglas Gregora71d8192009-09-04 17:36:40 +00001417 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001418 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001419 /// By default, performs semantic analysis to build the new expression.
1420 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001421 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001422 SourceLocation OperatorLoc,
1423 bool isArrow,
1424 CXXScopeSpec &SS,
1425 TypeSourceInfo *ScopeType,
1426 SourceLocation CCLoc,
1427 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001428 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001429
Douglas Gregorb98b1992009-08-11 05:31:07 +00001430 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001431 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001432 /// By default, performs semantic analysis to build the new expression.
1433 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001434 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001435 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001436 Expr *SubExpr) {
1437 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001438 }
Mike Stump1eb44332009-09-09 15:08:12 +00001439
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001440 /// \brief Build a new builtin offsetof expression.
1441 ///
1442 /// By default, performs semantic analysis to build the new expression.
1443 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001444 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001445 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001446 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001447 unsigned NumComponents,
1448 SourceLocation RParenLoc) {
1449 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1450 NumComponents, RParenLoc);
1451 }
Sean Huntc3021132010-05-05 15:23:54 +00001452
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001453 /// \brief Build a new sizeof, alignof or vec_step expression with a
1454 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001455 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001456 /// By default, performs semantic analysis to build the new expression.
1457 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001458 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1459 SourceLocation OpLoc,
1460 UnaryExprOrTypeTrait ExprKind,
1461 SourceRange R) {
1462 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001463 }
1464
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001465 /// \brief Build a new sizeof, alignof or vec step expression with an
1466 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001467 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001468 /// By default, performs semantic analysis to build the new expression.
1469 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001470 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1471 UnaryExprOrTypeTrait ExprKind,
1472 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001473 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001474 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001475 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001476 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001477
Douglas Gregorb98b1992009-08-11 05:31:07 +00001478 return move(Result);
1479 }
Mike Stump1eb44332009-09-09 15:08:12 +00001480
Douglas Gregorb98b1992009-08-11 05:31:07 +00001481 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001482 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001483 /// By default, performs semantic analysis to build the new expression.
1484 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001485 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001486 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001487 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001488 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001489 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1490 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001491 RBracketLoc);
1492 }
1493
1494 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001495 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001496 /// By default, performs semantic analysis to build the new expression.
1497 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001498 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001499 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001500 SourceLocation RParenLoc,
1501 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001502 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001503 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001504 }
1505
1506 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001507 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001508 /// By default, performs semantic analysis to build the new expression.
1509 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001510 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001511 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001512 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001513 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001514 const DeclarationNameInfo &MemberNameInfo,
1515 ValueDecl *Member,
1516 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001517 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001518 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001519 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1520 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001521 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001522 // We have a reference to an unnamed field. This is always the
1523 // base of an anonymous struct/union member access, i.e. the
1524 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001525 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001526 assert(Member->getType()->isRecordType() &&
1527 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001528
Richard Smith9138b4e2011-10-26 19:06:56 +00001529 BaseResult =
1530 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001531 QualifierLoc.getNestedNameSpecifier(),
1532 FoundDecl, Member);
1533 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001534 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001535 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001536 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001537 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001538 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001539 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001540 cast<FieldDecl>(Member)->getType(),
1541 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001542 return getSema().Owned(ME);
1543 }
Mike Stump1eb44332009-09-09 15:08:12 +00001544
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001545 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001546 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001547
John Wiegley429bb272011-04-08 18:41:53 +00001548 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001549 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001550
John McCall6bb80172010-03-30 21:47:33 +00001551 // FIXME: this involves duplicating earlier analysis in a lot of
1552 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001553 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001554 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001555 R.resolveKind();
1556
John McCall9ae2f072010-08-23 23:25:46 +00001557 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001558 SS, TemplateKWLoc,
1559 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001560 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001561 }
Mike Stump1eb44332009-09-09 15:08:12 +00001562
Douglas Gregorb98b1992009-08-11 05:31:07 +00001563 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001564 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 /// By default, performs semantic analysis to build the new expression.
1566 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001567 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001568 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001569 Expr *LHS, Expr *RHS) {
1570 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001571 }
1572
1573 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001574 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001575 /// By default, performs semantic analysis to build the new expression.
1576 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001577 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001578 SourceLocation QuestionLoc,
1579 Expr *LHS,
1580 SourceLocation ColonLoc,
1581 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001582 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1583 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001584 }
1585
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001587 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001588 /// By default, performs semantic analysis to build the new expression.
1589 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001590 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001591 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001593 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001594 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001595 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001596 }
Mike Stump1eb44332009-09-09 15:08:12 +00001597
Douglas Gregorb98b1992009-08-11 05:31:07 +00001598 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001599 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 /// By default, performs semantic analysis to build the new expression.
1601 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001602 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001603 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001605 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001606 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001607 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001608 }
Mike Stump1eb44332009-09-09 15:08:12 +00001609
Douglas Gregorb98b1992009-08-11 05:31:07 +00001610 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001611 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001612 /// By default, performs semantic analysis to build the new expression.
1613 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001614 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001615 SourceLocation OpLoc,
1616 SourceLocation AccessorLoc,
1617 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001618
John McCall129e2df2009-11-30 22:42:35 +00001619 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001620 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001621 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001622 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001623 SS, SourceLocation(),
1624 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001625 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001626 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001627 }
Mike Stump1eb44332009-09-09 15:08:12 +00001628
Douglas Gregorb98b1992009-08-11 05:31:07 +00001629 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001630 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001631 /// By default, performs semantic analysis to build the new expression.
1632 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001633 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001634 MultiExprArg Inits,
1635 SourceLocation RBraceLoc,
1636 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001637 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001638 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1639 if (Result.isInvalid() || ResultTy->isDependentType())
1640 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001641
Douglas Gregore48319a2009-11-09 17:16:50 +00001642 // Patch in the result type we were given, which may have been computed
1643 // when the initial InitListExpr was built.
1644 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1645 ILE->setType(ResultTy);
1646 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001647 }
Mike Stump1eb44332009-09-09 15:08:12 +00001648
Douglas Gregorb98b1992009-08-11 05:31:07 +00001649 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001650 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001651 /// By default, performs semantic analysis to build the new expression.
1652 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001653 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001654 MultiExprArg ArrayExprs,
1655 SourceLocation EqualOrColonLoc,
1656 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001657 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001658 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001660 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001662 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001663
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 ArrayExprs.release();
1665 return move(Result);
1666 }
Mike Stump1eb44332009-09-09 15:08:12 +00001667
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001669 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001670 /// By default, builds the implicit value initialization without performing
1671 /// any semantic analysis. Subclasses may override this routine to provide
1672 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001673 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001674 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1675 }
Mike Stump1eb44332009-09-09 15:08:12 +00001676
Douglas Gregorb98b1992009-08-11 05:31:07 +00001677 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001678 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 /// By default, performs semantic analysis to build the new expression.
1680 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001681 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001682 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001683 SourceLocation RParenLoc) {
1684 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001685 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001686 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001687 }
1688
1689 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001690 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 /// By default, performs semantic analysis to build the new expression.
1692 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001693 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001694 MultiExprArg SubExprs,
1695 SourceLocation RParenLoc) {
1696 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001697 }
Mike Stump1eb44332009-09-09 15:08:12 +00001698
Douglas Gregorb98b1992009-08-11 05:31:07 +00001699 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001700 ///
1701 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001702 /// rather than attempting to map the label statement itself.
1703 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001704 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001705 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001706 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001707 }
Mike Stump1eb44332009-09-09 15:08:12 +00001708
Douglas Gregorb98b1992009-08-11 05:31:07 +00001709 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001710 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001711 /// By default, performs semantic analysis to build the new expression.
1712 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001713 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001714 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001715 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001716 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717 }
Mike Stump1eb44332009-09-09 15:08:12 +00001718
Douglas Gregorb98b1992009-08-11 05:31:07 +00001719 /// \brief Build a new __builtin_choose_expr expression.
1720 ///
1721 /// By default, performs semantic analysis to build the new expression.
1722 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001723 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001724 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001725 SourceLocation RParenLoc) {
1726 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001727 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001728 RParenLoc);
1729 }
Mike Stump1eb44332009-09-09 15:08:12 +00001730
Peter Collingbournef111d932011-04-15 00:35:48 +00001731 /// \brief Build a new generic selection expression.
1732 ///
1733 /// By default, performs semantic analysis to build the new expression.
1734 /// Subclasses may override this routine to provide different behavior.
1735 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1736 SourceLocation DefaultLoc,
1737 SourceLocation RParenLoc,
1738 Expr *ControllingExpr,
1739 TypeSourceInfo **Types,
1740 Expr **Exprs,
1741 unsigned NumAssocs) {
1742 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1743 ControllingExpr, Types, Exprs,
1744 NumAssocs);
1745 }
1746
Douglas Gregorb98b1992009-08-11 05:31:07 +00001747 /// \brief Build a new overloaded operator call expression.
1748 ///
1749 /// By default, performs semantic analysis to build the new expression.
1750 /// The semantic analysis provides the behavior of template instantiation,
1751 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001752 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001753 /// argument-dependent lookup, etc. Subclasses may override this routine to
1754 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001755 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001757 Expr *Callee,
1758 Expr *First,
1759 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001760
1761 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001762 /// reinterpret_cast.
1763 ///
1764 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001765 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001766 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001767 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001768 Stmt::StmtClass Class,
1769 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001770 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001771 SourceLocation RAngleLoc,
1772 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001773 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001774 SourceLocation RParenLoc) {
1775 switch (Class) {
1776 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001777 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001778 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001779 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001780
1781 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001782 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001783 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001784 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001785
Douglas Gregorb98b1992009-08-11 05:31:07 +00001786 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001787 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001788 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001789 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001790 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001791
Douglas Gregorb98b1992009-08-11 05:31:07 +00001792 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001793 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001794 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001795 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001796
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001798 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800 }
Mike Stump1eb44332009-09-09 15:08:12 +00001801
Douglas Gregorb98b1992009-08-11 05:31:07 +00001802 /// \brief Build a new C++ static_cast expression.
1803 ///
1804 /// By default, performs semantic analysis to build the new expression.
1805 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001806 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001807 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001808 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 SourceLocation RAngleLoc,
1810 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001811 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001812 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001813 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001814 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001815 SourceRange(LAngleLoc, RAngleLoc),
1816 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001817 }
1818
1819 /// \brief Build a new C++ dynamic_cast expression.
1820 ///
1821 /// By default, performs semantic analysis to build the new expression.
1822 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001823 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001824 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001825 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001826 SourceLocation RAngleLoc,
1827 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001828 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001829 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001830 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001831 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001832 SourceRange(LAngleLoc, RAngleLoc),
1833 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001834 }
1835
1836 /// \brief Build a new C++ reinterpret_cast expression.
1837 ///
1838 /// By default, performs semantic analysis to build the new expression.
1839 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001840 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001841 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001842 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001843 SourceLocation RAngleLoc,
1844 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001845 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001846 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001847 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001848 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001849 SourceRange(LAngleLoc, RAngleLoc),
1850 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001851 }
1852
1853 /// \brief Build a new C++ const_cast expression.
1854 ///
1855 /// By default, performs semantic analysis to build the new expression.
1856 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001857 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001858 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001859 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001860 SourceLocation RAngleLoc,
1861 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001862 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001863 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001864 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001865 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001866 SourceRange(LAngleLoc, RAngleLoc),
1867 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001868 }
Mike Stump1eb44332009-09-09 15:08:12 +00001869
Douglas Gregorb98b1992009-08-11 05:31:07 +00001870 /// \brief Build a new C++ functional-style cast expression.
1871 ///
1872 /// By default, performs semantic analysis to build the new expression.
1873 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001874 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1875 SourceLocation LParenLoc,
1876 Expr *Sub,
1877 SourceLocation RParenLoc) {
1878 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001879 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001880 RParenLoc);
1881 }
Mike Stump1eb44332009-09-09 15:08:12 +00001882
Douglas Gregorb98b1992009-08-11 05:31:07 +00001883 /// \brief Build a new C++ typeid(type) expression.
1884 ///
1885 /// By default, performs semantic analysis to build the new expression.
1886 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001887 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001888 SourceLocation TypeidLoc,
1889 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001890 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001891 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001892 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001893 }
Mike Stump1eb44332009-09-09 15:08:12 +00001894
Francois Pichet01b7c302010-09-08 12:20:18 +00001895
Douglas Gregorb98b1992009-08-11 05:31:07 +00001896 /// \brief Build a new C++ typeid(expr) expression.
1897 ///
1898 /// By default, performs semantic analysis to build the new expression.
1899 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001900 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001901 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001902 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001903 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001904 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001905 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001906 }
1907
Francois Pichet01b7c302010-09-08 12:20:18 +00001908 /// \brief Build a new C++ __uuidof(type) expression.
1909 ///
1910 /// By default, performs semantic analysis to build the new expression.
1911 /// Subclasses may override this routine to provide different behavior.
1912 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1913 SourceLocation TypeidLoc,
1914 TypeSourceInfo *Operand,
1915 SourceLocation RParenLoc) {
1916 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1917 RParenLoc);
1918 }
1919
1920 /// \brief Build a new C++ __uuidof(expr) expression.
1921 ///
1922 /// By default, performs semantic analysis to build the new expression.
1923 /// Subclasses may override this routine to provide different behavior.
1924 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1925 SourceLocation TypeidLoc,
1926 Expr *Operand,
1927 SourceLocation RParenLoc) {
1928 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1929 RParenLoc);
1930 }
1931
Douglas Gregorb98b1992009-08-11 05:31:07 +00001932 /// \brief Build a new C++ "this" expression.
1933 ///
1934 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001935 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001936 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001937 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001938 QualType ThisType,
1939 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001940 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001941 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001942 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1943 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001944 }
1945
1946 /// \brief Build a new C++ throw expression.
1947 ///
1948 /// By default, performs semantic analysis to build the new expression.
1949 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001950 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1951 bool IsThrownVariableInScope) {
1952 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001953 }
1954
1955 /// \brief Build a new C++ default-argument expression.
1956 ///
1957 /// By default, builds a new default-argument expression, which does not
1958 /// require any semantic analysis. Subclasses may override this routine to
1959 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001960 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001961 ParmVarDecl *Param) {
1962 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1963 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001964 }
1965
1966 /// \brief Build a new C++ zero-initialization expression.
1967 ///
1968 /// By default, performs semantic analysis to build the new expression.
1969 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001970 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1971 SourceLocation LParenLoc,
1972 SourceLocation RParenLoc) {
1973 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001974 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001975 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001976 }
Mike Stump1eb44332009-09-09 15:08:12 +00001977
Douglas Gregorb98b1992009-08-11 05:31:07 +00001978 /// \brief Build a new C++ "new" expression.
1979 ///
1980 /// By default, performs semantic analysis to build the new expression.
1981 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001982 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001983 bool UseGlobal,
1984 SourceLocation PlacementLParen,
1985 MultiExprArg PlacementArgs,
1986 SourceLocation PlacementRParen,
1987 SourceRange TypeIdParens,
1988 QualType AllocatedType,
1989 TypeSourceInfo *AllocatedTypeInfo,
1990 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001991 SourceRange DirectInitRange,
1992 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001993 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001994 PlacementLParen,
1995 move(PlacementArgs),
1996 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001997 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001998 AllocatedType,
1999 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002000 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002001 DirectInitRange,
2002 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002003 }
Mike Stump1eb44332009-09-09 15:08:12 +00002004
Douglas Gregorb98b1992009-08-11 05:31:07 +00002005 /// \brief Build a new C++ "delete" expression.
2006 ///
2007 /// By default, performs semantic analysis to build the new expression.
2008 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002009 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002010 bool IsGlobalDelete,
2011 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002012 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002013 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002014 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002015 }
Mike Stump1eb44332009-09-09 15:08:12 +00002016
Douglas Gregorb98b1992009-08-11 05:31:07 +00002017 /// \brief Build a new unary type trait expression.
2018 ///
2019 /// By default, performs semantic analysis to build the new expression.
2020 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002021 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002022 SourceLocation StartLoc,
2023 TypeSourceInfo *T,
2024 SourceLocation RParenLoc) {
2025 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002026 }
2027
Francois Pichet6ad6f282010-12-07 00:08:36 +00002028 /// \brief Build a new binary type trait expression.
2029 ///
2030 /// By default, performs semantic analysis to build the new expression.
2031 /// Subclasses may override this routine to provide different behavior.
2032 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2033 SourceLocation StartLoc,
2034 TypeSourceInfo *LhsT,
2035 TypeSourceInfo *RhsT,
2036 SourceLocation RParenLoc) {
2037 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2038 }
2039
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002040 /// \brief Build a new type trait expression.
2041 ///
2042 /// By default, performs semantic analysis to build the new expression.
2043 /// Subclasses may override this routine to provide different behavior.
2044 ExprResult RebuildTypeTrait(TypeTrait Trait,
2045 SourceLocation StartLoc,
2046 ArrayRef<TypeSourceInfo *> Args,
2047 SourceLocation RParenLoc) {
2048 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2049 }
2050
John Wiegley21ff2e52011-04-28 00:16:57 +00002051 /// \brief Build a new array type trait expression.
2052 ///
2053 /// By default, performs semantic analysis to build the new expression.
2054 /// Subclasses may override this routine to provide different behavior.
2055 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2056 SourceLocation StartLoc,
2057 TypeSourceInfo *TSInfo,
2058 Expr *DimExpr,
2059 SourceLocation RParenLoc) {
2060 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2061 }
2062
John Wiegley55262202011-04-25 06:54:41 +00002063 /// \brief Build a new expression trait expression.
2064 ///
2065 /// By default, performs semantic analysis to build the new expression.
2066 /// Subclasses may override this routine to provide different behavior.
2067 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2068 SourceLocation StartLoc,
2069 Expr *Queried,
2070 SourceLocation RParenLoc) {
2071 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2072 }
2073
Mike Stump1eb44332009-09-09 15:08:12 +00002074 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002075 /// expression.
2076 ///
2077 /// By default, performs semantic analysis to build the new expression.
2078 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002079 ExprResult RebuildDependentScopeDeclRefExpr(
2080 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002081 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002082 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002083 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002084 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002085 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002086
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002087 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002088 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002089 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002090
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002091 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002092 }
2093
2094 /// \brief Build a new template-id expression.
2095 ///
2096 /// By default, performs semantic analysis to build the new expression.
2097 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002098 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002099 SourceLocation TemplateKWLoc,
2100 LookupResult &R,
2101 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002102 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002103 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2104 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002105 }
2106
2107 /// \brief Build a new object-construction expression.
2108 ///
2109 /// By default, performs semantic analysis to build the new expression.
2110 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002111 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002112 SourceLocation Loc,
2113 CXXConstructorDecl *Constructor,
2114 bool IsElidable,
2115 MultiExprArg Args,
2116 bool HadMultipleCandidates,
2117 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002118 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002119 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002120 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002121 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002122 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002123 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002124
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002125 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002126 move_arg(ConvertedArgs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002127 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002128 RequiresZeroInit, ConstructKind,
2129 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002130 }
2131
2132 /// \brief Build a new object-construction expression.
2133 ///
2134 /// By default, performs semantic analysis to build the new expression.
2135 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002136 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2137 SourceLocation LParenLoc,
2138 MultiExprArg Args,
2139 SourceLocation RParenLoc) {
2140 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002141 LParenLoc,
2142 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002143 RParenLoc);
2144 }
2145
2146 /// \brief Build a new object-construction expression.
2147 ///
2148 /// By default, performs semantic analysis to build the new expression.
2149 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002150 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2151 SourceLocation LParenLoc,
2152 MultiExprArg Args,
2153 SourceLocation RParenLoc) {
2154 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002155 LParenLoc,
2156 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002157 RParenLoc);
2158 }
Mike Stump1eb44332009-09-09 15:08:12 +00002159
Douglas Gregorb98b1992009-08-11 05:31:07 +00002160 /// \brief Build a new member reference expression.
2161 ///
2162 /// By default, performs semantic analysis to build the new expression.
2163 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002164 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002165 QualType BaseType,
2166 bool IsArrow,
2167 SourceLocation OperatorLoc,
2168 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002169 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002170 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002171 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002172 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002173 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002174 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002175
John McCall9ae2f072010-08-23 23:25:46 +00002176 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002177 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002178 SS, TemplateKWLoc,
2179 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002180 MemberNameInfo,
2181 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002182 }
2183
John McCall129e2df2009-11-30 22:42:35 +00002184 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002185 ///
2186 /// By default, performs semantic analysis to build the new expression.
2187 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002188 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2189 SourceLocation OperatorLoc,
2190 bool IsArrow,
2191 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002192 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002193 NamedDecl *FirstQualifierInScope,
2194 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002195 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002196 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002197 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002198
John McCall9ae2f072010-08-23 23:25:46 +00002199 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002200 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002201 SS, TemplateKWLoc,
2202 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002203 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002204 }
Mike Stump1eb44332009-09-09 15:08:12 +00002205
Sebastian Redl2e156222010-09-10 20:55:43 +00002206 /// \brief Build a new noexcept expression.
2207 ///
2208 /// By default, performs semantic analysis to build the new expression.
2209 /// Subclasses may override this routine to provide different behavior.
2210 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2211 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2212 }
2213
Douglas Gregoree8aff02011-01-04 17:33:58 +00002214 /// \brief Build a new expression to compute the length of a parameter pack.
2215 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2216 SourceLocation PackLoc,
2217 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002218 llvm::Optional<unsigned> Length) {
2219 if (Length)
2220 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2221 OperatorLoc, Pack, PackLoc,
2222 RParenLoc, *Length);
2223
Douglas Gregoree8aff02011-01-04 17:33:58 +00002224 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2225 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002226 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002227 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002228
Patrick Beardeb382ec2012-04-19 00:25:12 +00002229 /// \brief Build a new Objective-C boxed expression.
2230 ///
2231 /// By default, performs semantic analysis to build the new expression.
2232 /// Subclasses may override this routine to provide different behavior.
2233 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2234 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2235 }
2236
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002237 /// \brief Build a new Objective-C array literal.
2238 ///
2239 /// By default, performs semantic analysis to build the new expression.
2240 /// Subclasses may override this routine to provide different behavior.
2241 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2242 Expr **Elements, unsigned NumElements) {
2243 return getSema().BuildObjCArrayLiteral(Range,
2244 MultiExprArg(Elements, NumElements));
2245 }
2246
2247 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
2248 Expr *Base, Expr *Key,
2249 ObjCMethodDecl *getterMethod,
2250 ObjCMethodDecl *setterMethod) {
2251 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2252 getterMethod, setterMethod);
2253 }
2254
2255 /// \brief Build a new Objective-C dictionary literal.
2256 ///
2257 /// By default, performs semantic analysis to build the new expression.
2258 /// Subclasses may override this routine to provide different behavior.
2259 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2260 ObjCDictionaryElement *Elements,
2261 unsigned NumElements) {
2262 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2263 }
2264
James Dennett699c9042012-06-15 07:13:21 +00002265 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002266 ///
2267 /// By default, performs semantic analysis to build the new expression.
2268 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002269 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002270 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002271 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002272 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002273 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002274 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002275
Douglas Gregor92e986e2010-04-22 16:44:27 +00002276 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002277 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002278 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002279 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002280 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002281 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002282 MultiExprArg Args,
2283 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002284 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2285 ReceiverTypeInfo->getType(),
2286 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002287 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002288 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002289 }
2290
2291 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002292 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002293 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002294 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002295 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002296 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002297 MultiExprArg Args,
2298 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002299 return SemaRef.BuildInstanceMessage(Receiver,
2300 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002301 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002302 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002303 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002304 }
2305
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002306 /// \brief Build a new Objective-C ivar reference expression.
2307 ///
2308 /// By default, performs semantic analysis to build the new expression.
2309 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002310 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002311 SourceLocation IvarLoc,
2312 bool IsArrow, bool IsFreeIvar) {
2313 // FIXME: We lose track of the IsFreeIvar bit.
2314 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002315 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002316 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2317 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002318 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002319 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002320 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002321 false);
John Wiegley429bb272011-04-08 18:41:53 +00002322 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002323 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002324
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002325 if (Result.get())
2326 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002327
John Wiegley429bb272011-04-08 18:41:53 +00002328 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002329 /*FIXME:*/IvarLoc, IsArrow,
2330 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002331 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002332 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002333 /*TemplateArgs=*/0);
2334 }
Douglas Gregore3303542010-04-26 20:47:02 +00002335
2336 /// \brief Build a new Objective-C property reference expression.
2337 ///
2338 /// By default, performs semantic analysis to build the new expression.
2339 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002340 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002341 ObjCPropertyDecl *Property,
2342 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002343 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002344 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002345 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2346 Sema::LookupMemberName);
2347 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002348 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002349 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002350 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002351 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002352 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002353
Douglas Gregore3303542010-04-26 20:47:02 +00002354 if (Result.get())
2355 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002356
John Wiegley429bb272011-04-08 18:41:53 +00002357 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002358 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002359 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002360 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002361 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002362 /*TemplateArgs=*/0);
2363 }
Sean Huntc3021132010-05-05 15:23:54 +00002364
John McCall12f78a62010-12-02 01:19:52 +00002365 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002366 ///
2367 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002368 /// Subclasses may override this routine to provide different behavior.
2369 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2370 ObjCMethodDecl *Getter,
2371 ObjCMethodDecl *Setter,
2372 SourceLocation PropertyLoc) {
2373 // Since these expressions can only be value-dependent, we do not
2374 // need to perform semantic analysis again.
2375 return Owned(
2376 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2377 VK_LValue, OK_ObjCProperty,
2378 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002379 }
2380
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002381 /// \brief Build a new Objective-C "isa" expression.
2382 ///
2383 /// By default, performs semantic analysis to build the new expression.
2384 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002385 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002386 bool IsArrow) {
2387 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002388 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002389 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2390 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002391 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002392 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002393 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002394 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002395 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002396
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002397 if (Result.get())
2398 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002399
John Wiegley429bb272011-04-08 18:41:53 +00002400 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002401 /*FIXME:*/IsaLoc, IsArrow,
2402 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002403 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002404 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002405 /*TemplateArgs=*/0);
2406 }
Sean Huntc3021132010-05-05 15:23:54 +00002407
Douglas Gregorb98b1992009-08-11 05:31:07 +00002408 /// \brief Build a new shuffle vector expression.
2409 ///
2410 /// By default, performs semantic analysis to build the new expression.
2411 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002412 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002413 MultiExprArg SubExprs,
2414 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002415 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002416 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002417 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2418 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2419 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2420 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002421
Douglas Gregorb98b1992009-08-11 05:31:07 +00002422 // Build a reference to the __builtin_shufflevector builtin
2423 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002424 ExprResult Callee
John McCallf4b88a42012-03-10 09:33:50 +00002425 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false,
2426 Builtin->getType(),
John Wiegley429bb272011-04-08 18:41:53 +00002427 VK_LValue, BuiltinLoc));
2428 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2429 if (Callee.isInvalid())
2430 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002431
2432 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002433 unsigned NumSubExprs = SubExprs.size();
2434 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002435 ExprResult TheCall = SemaRef.Owned(
2436 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002437 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002438 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002439 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002440 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002441
Douglas Gregorb98b1992009-08-11 05:31:07 +00002442 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002443 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002444 }
John McCall43fed0d2010-11-12 08:19:04 +00002445
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002446 /// \brief Build a new template argument pack expansion.
2447 ///
2448 /// By default, performs semantic analysis to build a new pack expansion
2449 /// for a template argument. Subclasses may override this routine to provide
2450 /// different behavior.
2451 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002452 SourceLocation EllipsisLoc,
2453 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002454 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002455 case TemplateArgument::Expression: {
2456 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002457 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2458 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002459 if (Result.isInvalid())
2460 return TemplateArgumentLoc();
2461
2462 return TemplateArgumentLoc(Result.get(), Result.get());
2463 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002464
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002465 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002466 return TemplateArgumentLoc(TemplateArgument(
2467 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002468 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002469 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002470 Pattern.getTemplateNameLoc(),
2471 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002472
2473 case TemplateArgument::Null:
2474 case TemplateArgument::Integral:
2475 case TemplateArgument::Declaration:
2476 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002477 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002478 llvm_unreachable("Pack expansion pattern has no parameter packs");
2479
2480 case TemplateArgument::Type:
2481 if (TypeSourceInfo *Expansion
2482 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002483 EllipsisLoc,
2484 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002485 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2486 Expansion);
2487 break;
2488 }
2489
2490 return TemplateArgumentLoc();
2491 }
2492
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002493 /// \brief Build a new expression pack expansion.
2494 ///
2495 /// By default, performs semantic analysis to build a new pack expansion
2496 /// for an expression. Subclasses may override this routine to provide
2497 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002498 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2499 llvm::Optional<unsigned> NumExpansions) {
2500 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002501 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002502
2503 /// \brief Build a new atomic operation expression.
2504 ///
2505 /// By default, performs semantic analysis to build the new expression.
2506 /// Subclasses may override this routine to provide different behavior.
2507 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2508 MultiExprArg SubExprs,
2509 QualType RetTy,
2510 AtomicExpr::AtomicOp Op,
2511 SourceLocation RParenLoc) {
2512 // Just create the expression; there is not any interesting semantic
2513 // analysis here because we can't actually build an AtomicExpr until
2514 // we are sure it is semantically sound.
2515 unsigned NumSubExprs = SubExprs.size();
2516 Expr **Subs = (Expr **)SubExprs.release();
2517 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2518 NumSubExprs, RetTy, Op,
2519 RParenLoc);
2520 }
2521
John McCall43fed0d2010-11-12 08:19:04 +00002522private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002523 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2524 QualType ObjectType,
2525 NamedDecl *FirstQualifierInScope,
2526 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002527
2528 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2529 QualType ObjectType,
2530 NamedDecl *FirstQualifierInScope,
2531 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002532};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002533
Douglas Gregor43959a92009-08-20 07:17:43 +00002534template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002535StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002536 if (!S)
2537 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002538
Douglas Gregor43959a92009-08-20 07:17:43 +00002539 switch (S->getStmtClass()) {
2540 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002541
Douglas Gregor43959a92009-08-20 07:17:43 +00002542 // Transform individual statement nodes
2543#define STMT(Node, Parent) \
2544 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002545#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002546#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002547#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002548
Douglas Gregor43959a92009-08-20 07:17:43 +00002549 // Transform expressions by calling TransformExpr.
2550#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002551#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002552#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002553#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002554 {
John McCall60d7b3a2010-08-24 06:29:42 +00002555 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002556 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002557 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002558
John McCall9ae2f072010-08-23 23:25:46 +00002559 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002560 }
Mike Stump1eb44332009-09-09 15:08:12 +00002561 }
2562
John McCall3fa5cae2010-10-26 07:05:15 +00002563 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002564}
Mike Stump1eb44332009-09-09 15:08:12 +00002565
2566
Douglas Gregor670444e2009-08-04 22:27:00 +00002567template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002568ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002569 if (!E)
2570 return SemaRef.Owned(E);
2571
2572 switch (E->getStmtClass()) {
2573 case Stmt::NoStmtClass: break;
2574#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002575#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002576#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002577 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002578#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002579 }
2580
John McCall3fa5cae2010-10-26 07:05:15 +00002581 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002582}
2583
2584template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002585bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2586 unsigned NumInputs,
2587 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002588 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002589 bool *ArgChanged) {
2590 for (unsigned I = 0; I != NumInputs; ++I) {
2591 // If requested, drop call arguments that need to be dropped.
2592 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2593 if (ArgChanged)
2594 *ArgChanged = true;
2595
2596 break;
2597 }
2598
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002599 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2600 Expr *Pattern = Expansion->getPattern();
2601
Chris Lattner686775d2011-07-20 06:58:45 +00002602 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002603 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2604 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2605
2606 // Determine whether the set of unexpanded parameter packs can and should
2607 // be expanded.
2608 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002609 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002610 llvm::Optional<unsigned> OrigNumExpansions
2611 = Expansion->getNumExpansions();
2612 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002613 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2614 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002615 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002616 Expand, RetainExpansion,
2617 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002618 return true;
2619
2620 if (!Expand) {
2621 // The transform has determined that we should perform a simple
2622 // transformation on the pack expansion, producing another pack
2623 // expansion.
2624 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2625 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2626 if (OutPattern.isInvalid())
2627 return true;
2628
2629 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002630 Expansion->getEllipsisLoc(),
2631 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002632 if (Out.isInvalid())
2633 return true;
2634
2635 if (ArgChanged)
2636 *ArgChanged = true;
2637 Outputs.push_back(Out.get());
2638 continue;
2639 }
John McCallc8fc90a2011-07-06 07:30:07 +00002640
2641 // Record right away that the argument was changed. This needs
2642 // to happen even if the array expands to nothing.
2643 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002644
2645 // The transform has determined that we should perform an elementwise
2646 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002647 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002648 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2649 ExprResult Out = getDerived().TransformExpr(Pattern);
2650 if (Out.isInvalid())
2651 return true;
2652
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002653 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002654 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2655 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002656 if (Out.isInvalid())
2657 return true;
2658 }
2659
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002660 Outputs.push_back(Out.get());
2661 }
2662
2663 continue;
2664 }
2665
Douglas Gregoraa165f82011-01-03 19:04:46 +00002666 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2667 if (Result.isInvalid())
2668 return true;
2669
2670 if (Result.get() != Inputs[I] && ArgChanged)
2671 *ArgChanged = true;
2672
2673 Outputs.push_back(Result.get());
2674 }
2675
2676 return false;
2677}
2678
2679template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002680NestedNameSpecifierLoc
2681TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2682 NestedNameSpecifierLoc NNS,
2683 QualType ObjectType,
2684 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002685 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002686 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2687 Qualifier = Qualifier.getPrefix())
2688 Qualifiers.push_back(Qualifier);
2689
2690 CXXScopeSpec SS;
2691 while (!Qualifiers.empty()) {
2692 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2693 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2694
2695 switch (QNNS->getKind()) {
2696 case NestedNameSpecifier::Identifier:
2697 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2698 *QNNS->getAsIdentifier(),
2699 Q.getLocalBeginLoc(),
2700 Q.getLocalEndLoc(),
2701 ObjectType, false, SS,
2702 FirstQualifierInScope, false))
2703 return NestedNameSpecifierLoc();
2704
2705 break;
2706
2707 case NestedNameSpecifier::Namespace: {
2708 NamespaceDecl *NS
2709 = cast_or_null<NamespaceDecl>(
2710 getDerived().TransformDecl(
2711 Q.getLocalBeginLoc(),
2712 QNNS->getAsNamespace()));
2713 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2714 break;
2715 }
2716
2717 case NestedNameSpecifier::NamespaceAlias: {
2718 NamespaceAliasDecl *Alias
2719 = cast_or_null<NamespaceAliasDecl>(
2720 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2721 QNNS->getAsNamespaceAlias()));
2722 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2723 Q.getLocalEndLoc());
2724 break;
2725 }
2726
2727 case NestedNameSpecifier::Global:
2728 // There is no meaningful transformation that one could perform on the
2729 // global scope.
2730 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2731 break;
2732
2733 case NestedNameSpecifier::TypeSpecWithTemplate:
2734 case NestedNameSpecifier::TypeSpec: {
2735 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2736 FirstQualifierInScope, SS);
2737
2738 if (!TL)
2739 return NestedNameSpecifierLoc();
2740
2741 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
David Blaikie4e4d0842012-03-11 07:00:24 +00002742 (SemaRef.getLangOpts().CPlusPlus0x &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002743 TL.getType()->isEnumeralType())) {
2744 assert(!TL.getType().hasLocalQualifiers() &&
2745 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002746 if (TL.getType()->isEnumeralType())
2747 SemaRef.Diag(TL.getBeginLoc(),
2748 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002749 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2750 Q.getLocalEndLoc());
2751 break;
2752 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002753 // If the nested-name-specifier is an invalid type def, don't emit an
2754 // error because a previous error should have already been emitted.
2755 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2756 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2757 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2758 << TL.getType() << SS.getRange();
2759 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002760 return NestedNameSpecifierLoc();
2761 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002762 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002763
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002764 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002765 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002766 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002767 }
2768
2769 // Don't rebuild the nested-name-specifier if we don't have to.
2770 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2771 !getDerived().AlwaysRebuild())
2772 return NNS;
2773
2774 // If we can re-use the source-location data from the original
2775 // nested-name-specifier, do so.
2776 if (SS.location_size() == NNS.getDataLength() &&
2777 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2778 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2779
2780 // Allocate new nested-name-specifier location information.
2781 return SS.getWithLocInContext(SemaRef.Context);
2782}
2783
2784template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002785DeclarationNameInfo
2786TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002787::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002788 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002789 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002790 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002791
2792 switch (Name.getNameKind()) {
2793 case DeclarationName::Identifier:
2794 case DeclarationName::ObjCZeroArgSelector:
2795 case DeclarationName::ObjCOneArgSelector:
2796 case DeclarationName::ObjCMultiArgSelector:
2797 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002798 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002799 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002800 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002801
Douglas Gregor81499bb2009-09-03 22:13:48 +00002802 case DeclarationName::CXXConstructorName:
2803 case DeclarationName::CXXDestructorName:
2804 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002805 TypeSourceInfo *NewTInfo;
2806 CanQualType NewCanTy;
2807 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002808 NewTInfo = getDerived().TransformType(OldTInfo);
2809 if (!NewTInfo)
2810 return DeclarationNameInfo();
2811 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002812 }
2813 else {
2814 NewTInfo = 0;
2815 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002816 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002817 if (NewT.isNull())
2818 return DeclarationNameInfo();
2819 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2820 }
Mike Stump1eb44332009-09-09 15:08:12 +00002821
Abramo Bagnara25777432010-08-11 22:01:17 +00002822 DeclarationName NewName
2823 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2824 NewCanTy);
2825 DeclarationNameInfo NewNameInfo(NameInfo);
2826 NewNameInfo.setName(NewName);
2827 NewNameInfo.setNamedTypeInfo(NewTInfo);
2828 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002829 }
Mike Stump1eb44332009-09-09 15:08:12 +00002830 }
2831
David Blaikieb219cfc2011-09-23 05:06:16 +00002832 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002833}
2834
2835template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002836TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002837TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2838 TemplateName Name,
2839 SourceLocation NameLoc,
2840 QualType ObjectType,
2841 NamedDecl *FirstQualifierInScope) {
2842 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2843 TemplateDecl *Template = QTN->getTemplateDecl();
2844 assert(Template && "qualified template name must refer to a template");
2845
2846 TemplateDecl *TransTemplate
2847 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2848 Template));
2849 if (!TransTemplate)
2850 return TemplateName();
2851
2852 if (!getDerived().AlwaysRebuild() &&
2853 SS.getScopeRep() == QTN->getQualifier() &&
2854 TransTemplate == Template)
2855 return Name;
2856
2857 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2858 TransTemplate);
2859 }
2860
2861 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2862 if (SS.getScopeRep()) {
2863 // These apply to the scope specifier, not the template.
2864 ObjectType = QualType();
2865 FirstQualifierInScope = 0;
2866 }
2867
2868 if (!getDerived().AlwaysRebuild() &&
2869 SS.getScopeRep() == DTN->getQualifier() &&
2870 ObjectType.isNull())
2871 return Name;
2872
2873 if (DTN->isIdentifier()) {
2874 return getDerived().RebuildTemplateName(SS,
2875 *DTN->getIdentifier(),
2876 NameLoc,
2877 ObjectType,
2878 FirstQualifierInScope);
2879 }
2880
2881 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2882 ObjectType);
2883 }
2884
2885 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2886 TemplateDecl *TransTemplate
2887 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2888 Template));
2889 if (!TransTemplate)
2890 return TemplateName();
2891
2892 if (!getDerived().AlwaysRebuild() &&
2893 TransTemplate == Template)
2894 return Name;
2895
2896 return TemplateName(TransTemplate);
2897 }
2898
2899 if (SubstTemplateTemplateParmPackStorage *SubstPack
2900 = Name.getAsSubstTemplateTemplateParmPack()) {
2901 TemplateTemplateParmDecl *TransParam
2902 = cast_or_null<TemplateTemplateParmDecl>(
2903 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2904 if (!TransParam)
2905 return TemplateName();
2906
2907 if (!getDerived().AlwaysRebuild() &&
2908 TransParam == SubstPack->getParameterPack())
2909 return Name;
2910
2911 return getDerived().RebuildTemplateName(TransParam,
2912 SubstPack->getArgumentPack());
2913 }
2914
2915 // These should be getting filtered out before they reach the AST.
2916 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002917}
2918
2919template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002920void TreeTransform<Derived>::InventTemplateArgumentLoc(
2921 const TemplateArgument &Arg,
2922 TemplateArgumentLoc &Output) {
2923 SourceLocation Loc = getDerived().getBaseLocation();
2924 switch (Arg.getKind()) {
2925 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002926 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002927 break;
2928
2929 case TemplateArgument::Type:
2930 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002931 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002932
John McCall833ca992009-10-29 08:12:44 +00002933 break;
2934
Douglas Gregor788cd062009-11-11 01:00:40 +00002935 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002936 case TemplateArgument::TemplateExpansion: {
2937 NestedNameSpecifierLocBuilder Builder;
2938 TemplateName Template = Arg.getAsTemplate();
2939 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2940 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2941 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2942 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2943
2944 if (Arg.getKind() == TemplateArgument::Template)
2945 Output = TemplateArgumentLoc(Arg,
2946 Builder.getWithLocInContext(SemaRef.Context),
2947 Loc);
2948 else
2949 Output = TemplateArgumentLoc(Arg,
2950 Builder.getWithLocInContext(SemaRef.Context),
2951 Loc, Loc);
2952
Douglas Gregor788cd062009-11-11 01:00:40 +00002953 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002954 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002955
John McCall833ca992009-10-29 08:12:44 +00002956 case TemplateArgument::Expression:
2957 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2958 break;
2959
2960 case TemplateArgument::Declaration:
2961 case TemplateArgument::Integral:
2962 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002963 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002964 break;
2965 }
2966}
2967
2968template<typename Derived>
2969bool TreeTransform<Derived>::TransformTemplateArgument(
2970 const TemplateArgumentLoc &Input,
2971 TemplateArgumentLoc &Output) {
2972 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002973 switch (Arg.getKind()) {
2974 case TemplateArgument::Null:
2975 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002976 Output = Input;
2977 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002978
Douglas Gregor670444e2009-08-04 22:27:00 +00002979 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002980 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002981 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002982 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002983
2984 DI = getDerived().TransformType(DI);
2985 if (!DI) return true;
2986
2987 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2988 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002989 }
Mike Stump1eb44332009-09-09 15:08:12 +00002990
Douglas Gregor670444e2009-08-04 22:27:00 +00002991 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002992 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002993 DeclarationName Name;
2994 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2995 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002996 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002997 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002998 if (!D) return true;
2999
John McCall828bff22009-10-29 18:45:58 +00003000 Expr *SourceExpr = Input.getSourceDeclExpression();
3001 if (SourceExpr) {
3002 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003003 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00003004 ExprResult E = getDerived().TransformExpr(SourceExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003005 E = SemaRef.ActOnConstantExpression(E);
John McCall9ae2f072010-08-23 23:25:46 +00003006 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00003007 }
3008
3009 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00003010 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003011 }
Mike Stump1eb44332009-09-09 15:08:12 +00003012
Douglas Gregor788cd062009-11-11 01:00:40 +00003013 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003014 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3015 if (QualifierLoc) {
3016 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3017 if (!QualifierLoc)
3018 return true;
3019 }
3020
Douglas Gregor1d752d72011-03-02 18:46:51 +00003021 CXXScopeSpec SS;
3022 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003023 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003024 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3025 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003026 if (Template.isNull())
3027 return true;
Sean Huntc3021132010-05-05 15:23:54 +00003028
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003029 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003030 Input.getTemplateNameLoc());
3031 return false;
3032 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003033
3034 case TemplateArgument::TemplateExpansion:
3035 llvm_unreachable("Caller should expand pack expansions");
3036
Douglas Gregor670444e2009-08-04 22:27:00 +00003037 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003038 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003039 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003040 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003041
John McCall833ca992009-10-29 08:12:44 +00003042 Expr *InputExpr = Input.getSourceExpression();
3043 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3044
Chris Lattner223de242011-04-25 20:37:58 +00003045 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003046 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003047 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003048 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003049 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003050 }
Mike Stump1eb44332009-09-09 15:08:12 +00003051
Douglas Gregor670444e2009-08-04 22:27:00 +00003052 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00003053 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00003054 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00003055 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00003056 AEnd = Arg.pack_end();
3057 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00003058
John McCall833ca992009-10-29 08:12:44 +00003059 // FIXME: preserve source information here when we start
3060 // caring about parameter packs.
3061
John McCall828bff22009-10-29 18:45:58 +00003062 TemplateArgumentLoc InputArg;
3063 TemplateArgumentLoc OutputArg;
3064 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3065 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00003066 return true;
3067
John McCall828bff22009-10-29 18:45:58 +00003068 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00003069 }
Douglas Gregor910f8002010-11-07 23:05:16 +00003070
3071 TemplateArgument *TransformedArgsPtr
3072 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3073 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3074 TransformedArgsPtr);
3075 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3076 TransformedArgs.size()),
3077 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003078 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003079 }
3080 }
Mike Stump1eb44332009-09-09 15:08:12 +00003081
Douglas Gregor670444e2009-08-04 22:27:00 +00003082 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003083 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003084}
3085
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003086/// \brief Iterator adaptor that invents template argument location information
3087/// for each of the template arguments in its underlying iterator.
3088template<typename Derived, typename InputIterator>
3089class TemplateArgumentLocInventIterator {
3090 TreeTransform<Derived> &Self;
3091 InputIterator Iter;
3092
3093public:
3094 typedef TemplateArgumentLoc value_type;
3095 typedef TemplateArgumentLoc reference;
3096 typedef typename std::iterator_traits<InputIterator>::difference_type
3097 difference_type;
3098 typedef std::input_iterator_tag iterator_category;
3099
3100 class pointer {
3101 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003102
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003103 public:
3104 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3105
3106 const TemplateArgumentLoc *operator->() const { return &Arg; }
3107 };
3108
3109 TemplateArgumentLocInventIterator() { }
3110
3111 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3112 InputIterator Iter)
3113 : Self(Self), Iter(Iter) { }
3114
3115 TemplateArgumentLocInventIterator &operator++() {
3116 ++Iter;
3117 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003118 }
3119
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003120 TemplateArgumentLocInventIterator operator++(int) {
3121 TemplateArgumentLocInventIterator Old(*this);
3122 ++(*this);
3123 return Old;
3124 }
3125
3126 reference operator*() const {
3127 TemplateArgumentLoc Result;
3128 Self.InventTemplateArgumentLoc(*Iter, Result);
3129 return Result;
3130 }
3131
3132 pointer operator->() const { return pointer(**this); }
3133
3134 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3135 const TemplateArgumentLocInventIterator &Y) {
3136 return X.Iter == Y.Iter;
3137 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003138
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003139 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3140 const TemplateArgumentLocInventIterator &Y) {
3141 return X.Iter != Y.Iter;
3142 }
3143};
3144
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003145template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003146template<typename InputIterator>
3147bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3148 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003149 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003150 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003151 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003152 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003153
3154 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3155 // Unpack argument packs, which we translate them into separate
3156 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003157 // FIXME: We could do much better if we could guarantee that the
3158 // TemplateArgumentLocInfo for the pack expansion would be usable for
3159 // all of the template arguments in the argument pack.
3160 typedef TemplateArgumentLocInventIterator<Derived,
3161 TemplateArgument::pack_iterator>
3162 PackLocIterator;
3163 if (TransformTemplateArguments(PackLocIterator(*this,
3164 In.getArgument().pack_begin()),
3165 PackLocIterator(*this,
3166 In.getArgument().pack_end()),
3167 Outputs))
3168 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003169
3170 continue;
3171 }
3172
3173 if (In.getArgument().isPackExpansion()) {
3174 // We have a pack expansion, for which we will be substituting into
3175 // the pattern.
3176 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003177 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003178 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003179 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3180 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003181
Chris Lattner686775d2011-07-20 06:58:45 +00003182 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003183 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3184 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3185
3186 // Determine whether the set of unexpanded parameter packs can and should
3187 // be expanded.
3188 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003189 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003190 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003191 if (getDerived().TryExpandParameterPacks(Ellipsis,
3192 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003193 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003194 Expand,
3195 RetainExpansion,
3196 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003197 return true;
3198
3199 if (!Expand) {
3200 // The transform has determined that we should perform a simple
3201 // transformation on the pack expansion, producing another pack
3202 // expansion.
3203 TemplateArgumentLoc OutPattern;
3204 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3205 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3206 return true;
3207
Douglas Gregorcded4f62011-01-14 17:04:44 +00003208 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3209 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003210 if (Out.getArgument().isNull())
3211 return true;
3212
3213 Outputs.addArgument(Out);
3214 continue;
3215 }
3216
3217 // The transform has determined that we should perform an elementwise
3218 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003219 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003220 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3221
3222 if (getDerived().TransformTemplateArgument(Pattern, Out))
3223 return true;
3224
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003225 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003226 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3227 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003228 if (Out.getArgument().isNull())
3229 return true;
3230 }
3231
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003232 Outputs.addArgument(Out);
3233 }
3234
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003235 // If we're supposed to retain a pack expansion, do so by temporarily
3236 // forgetting the partially-substituted parameter pack.
3237 if (RetainExpansion) {
3238 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3239
3240 if (getDerived().TransformTemplateArgument(Pattern, Out))
3241 return true;
3242
Douglas Gregorcded4f62011-01-14 17:04:44 +00003243 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3244 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003245 if (Out.getArgument().isNull())
3246 return true;
3247
3248 Outputs.addArgument(Out);
3249 }
Douglas Gregord3731192011-01-10 07:32:04 +00003250
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003251 continue;
3252 }
3253
3254 // The simple case:
3255 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003256 return true;
3257
3258 Outputs.addArgument(Out);
3259 }
3260
3261 return false;
3262
3263}
3264
Douglas Gregor577f75a2009-08-04 16:50:30 +00003265//===----------------------------------------------------------------------===//
3266// Type transformation
3267//===----------------------------------------------------------------------===//
3268
3269template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003270QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003271 if (getDerived().AlreadyTransformed(T))
3272 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003273
John McCalla2becad2009-10-21 00:40:46 +00003274 // Temporary workaround. All of these transformations should
3275 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003276 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3277 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003278
John McCall43fed0d2010-11-12 08:19:04 +00003279 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003280
John McCalla2becad2009-10-21 00:40:46 +00003281 if (!NewDI)
3282 return QualType();
3283
3284 return NewDI->getType();
3285}
3286
3287template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003288TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003289 // Refine the base location to the type's location.
3290 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3291 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003292 if (getDerived().AlreadyTransformed(DI->getType()))
3293 return DI;
3294
3295 TypeLocBuilder TLB;
3296
3297 TypeLoc TL = DI->getTypeLoc();
3298 TLB.reserve(TL.getFullDataSize());
3299
John McCall43fed0d2010-11-12 08:19:04 +00003300 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003301 if (Result.isNull())
3302 return 0;
3303
John McCalla93c9342009-12-07 02:54:59 +00003304 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003305}
3306
3307template<typename Derived>
3308QualType
John McCall43fed0d2010-11-12 08:19:04 +00003309TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003310 switch (T.getTypeLocClass()) {
3311#define ABSTRACT_TYPELOC(CLASS, PARENT)
3312#define TYPELOC(CLASS, PARENT) \
3313 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003314 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003315#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003316 }
Mike Stump1eb44332009-09-09 15:08:12 +00003317
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003318 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003319}
3320
3321/// FIXME: By default, this routine adds type qualifiers only to types
3322/// that can have qualifiers, and silently suppresses those qualifiers
3323/// that are not permitted (e.g., qualifiers on reference or function
3324/// types). This is the right thing for template instantiation, but
3325/// probably not for other clients.
3326template<typename Derived>
3327QualType
3328TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003329 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003330 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003331
John McCall43fed0d2010-11-12 08:19:04 +00003332 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003333 if (Result.isNull())
3334 return QualType();
3335
3336 // Silently suppress qualifiers if the result type can't be qualified.
3337 // FIXME: this is the right thing for template instantiation, but
3338 // probably not for other clients.
3339 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003340 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003341
John McCallf85e1932011-06-15 23:02:42 +00003342 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003343 // resulting type.
3344 if (Quals.hasObjCLifetime()) {
3345 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3346 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003347 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003348 // Objective-C ARC:
3349 // A lifetime qualifier applied to a substituted template parameter
3350 // overrides the lifetime qualifier from the template argument.
3351 if (const SubstTemplateTypeParmType *SubstTypeParam
3352 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3353 QualType Replacement = SubstTypeParam->getReplacementType();
3354 Qualifiers Qs = Replacement.getQualifiers();
3355 Qs.removeObjCLifetime();
3356 Replacement
3357 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3358 Qs);
3359 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3360 SubstTypeParam->getReplacedParameter(),
3361 Replacement);
3362 TLB.TypeWasModifiedSafely(Result);
3363 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003364 // Otherwise, complain about the addition of a qualifier to an
3365 // already-qualified type.
3366 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003367 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003368 << Result << R;
3369
Douglas Gregore559ca12011-06-17 22:11:49 +00003370 Quals.removeObjCLifetime();
3371 }
3372 }
3373 }
John McCall28654742010-06-05 06:41:15 +00003374 if (!Quals.empty()) {
3375 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3376 TLB.push<QualifiedTypeLoc>(Result);
3377 // No location information to preserve.
3378 }
John McCalla2becad2009-10-21 00:40:46 +00003379
3380 return Result;
3381}
3382
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003383template<typename Derived>
3384TypeLoc
3385TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3386 QualType ObjectType,
3387 NamedDecl *UnqualLookup,
3388 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003389 QualType T = TL.getType();
3390 if (getDerived().AlreadyTransformed(T))
3391 return TL;
3392
3393 TypeLocBuilder TLB;
3394 QualType Result;
3395
3396 if (isa<TemplateSpecializationType>(T)) {
3397 TemplateSpecializationTypeLoc SpecTL
3398 = cast<TemplateSpecializationTypeLoc>(TL);
3399
3400 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003401 getDerived().TransformTemplateName(SS,
3402 SpecTL.getTypePtr()->getTemplateName(),
3403 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003404 ObjectType, UnqualLookup);
3405 if (Template.isNull())
3406 return TypeLoc();
3407
3408 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3409 Template);
3410 } else if (isa<DependentTemplateSpecializationType>(T)) {
3411 DependentTemplateSpecializationTypeLoc SpecTL
3412 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3413
Douglas Gregora88f09f2011-02-28 17:23:35 +00003414 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003415 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003416 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003417 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003418 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003419 if (Template.isNull())
3420 return TypeLoc();
3421
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003422 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003423 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003424 Template,
3425 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003426 } else {
3427 // Nothing special needs to be done for these.
3428 Result = getDerived().TransformType(TLB, TL);
3429 }
3430
3431 if (Result.isNull())
3432 return TypeLoc();
3433
3434 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3435}
3436
Douglas Gregorb71d8212011-03-02 18:32:08 +00003437template<typename Derived>
3438TypeSourceInfo *
3439TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3440 QualType ObjectType,
3441 NamedDecl *UnqualLookup,
3442 CXXScopeSpec &SS) {
3443 // FIXME: Painfully copy-paste from the above!
3444
3445 QualType T = TSInfo->getType();
3446 if (getDerived().AlreadyTransformed(T))
3447 return TSInfo;
3448
3449 TypeLocBuilder TLB;
3450 QualType Result;
3451
3452 TypeLoc TL = TSInfo->getTypeLoc();
3453 if (isa<TemplateSpecializationType>(T)) {
3454 TemplateSpecializationTypeLoc SpecTL
3455 = cast<TemplateSpecializationTypeLoc>(TL);
3456
3457 TemplateName Template
3458 = getDerived().TransformTemplateName(SS,
3459 SpecTL.getTypePtr()->getTemplateName(),
3460 SpecTL.getTemplateNameLoc(),
3461 ObjectType, UnqualLookup);
3462 if (Template.isNull())
3463 return 0;
3464
3465 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3466 Template);
3467 } else if (isa<DependentTemplateSpecializationType>(T)) {
3468 DependentTemplateSpecializationTypeLoc SpecTL
3469 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3470
3471 TemplateName Template
3472 = getDerived().RebuildTemplateName(SS,
3473 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003474 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003475 ObjectType, UnqualLookup);
3476 if (Template.isNull())
3477 return 0;
3478
3479 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3480 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003481 Template,
3482 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003483 } else {
3484 // Nothing special needs to be done for these.
3485 Result = getDerived().TransformType(TLB, TL);
3486 }
3487
3488 if (Result.isNull())
3489 return 0;
3490
3491 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3492}
3493
John McCalla2becad2009-10-21 00:40:46 +00003494template <class TyLoc> static inline
3495QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3496 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3497 NewT.setNameLoc(T.getNameLoc());
3498 return T.getType();
3499}
3500
John McCalla2becad2009-10-21 00:40:46 +00003501template<typename Derived>
3502QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003503 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003504 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3505 NewT.setBuiltinLoc(T.getBuiltinLoc());
3506 if (T.needsExtraLocalData())
3507 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3508 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003509}
Mike Stump1eb44332009-09-09 15:08:12 +00003510
Douglas Gregor577f75a2009-08-04 16:50:30 +00003511template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003512QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003513 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003514 // FIXME: recurse?
3515 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003516}
Mike Stump1eb44332009-09-09 15:08:12 +00003517
Douglas Gregor577f75a2009-08-04 16:50:30 +00003518template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003519QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003520 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003521 QualType PointeeType
3522 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003523 if (PointeeType.isNull())
3524 return QualType();
3525
3526 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003527 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003528 // A dependent pointer type 'T *' has is being transformed such
3529 // that an Objective-C class type is being replaced for 'T'. The
3530 // resulting pointer type is an ObjCObjectPointerType, not a
3531 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003532 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003533
John McCallc12c5bb2010-05-15 11:32:37 +00003534 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3535 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003536 return Result;
3537 }
John McCall43fed0d2010-11-12 08:19:04 +00003538
Douglas Gregor92e986e2010-04-22 16:44:27 +00003539 if (getDerived().AlwaysRebuild() ||
3540 PointeeType != TL.getPointeeLoc().getType()) {
3541 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3542 if (Result.isNull())
3543 return QualType();
3544 }
John McCallf85e1932011-06-15 23:02:42 +00003545
3546 // Objective-C ARC can add lifetime qualifiers to the type that we're
3547 // pointing to.
3548 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3549
Douglas Gregor92e986e2010-04-22 16:44:27 +00003550 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3551 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003552 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003553}
Mike Stump1eb44332009-09-09 15:08:12 +00003554
3555template<typename Derived>
3556QualType
John McCalla2becad2009-10-21 00:40:46 +00003557TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003558 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003559 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003560 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3561 if (PointeeType.isNull())
3562 return QualType();
3563
3564 QualType Result = TL.getType();
3565 if (getDerived().AlwaysRebuild() ||
3566 PointeeType != TL.getPointeeLoc().getType()) {
3567 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003568 TL.getSigilLoc());
3569 if (Result.isNull())
3570 return QualType();
3571 }
3572
Douglas Gregor39968ad2010-04-22 16:50:51 +00003573 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003574 NewT.setSigilLoc(TL.getSigilLoc());
3575 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003576}
3577
John McCall85737a72009-10-30 00:06:24 +00003578/// Transforms a reference type. Note that somewhat paradoxically we
3579/// don't care whether the type itself is an l-value type or an r-value
3580/// type; we only care if the type was *written* as an l-value type
3581/// or an r-value type.
3582template<typename Derived>
3583QualType
3584TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003585 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003586 const ReferenceType *T = TL.getTypePtr();
3587
3588 // Note that this works with the pointee-as-written.
3589 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3590 if (PointeeType.isNull())
3591 return QualType();
3592
3593 QualType Result = TL.getType();
3594 if (getDerived().AlwaysRebuild() ||
3595 PointeeType != T->getPointeeTypeAsWritten()) {
3596 Result = getDerived().RebuildReferenceType(PointeeType,
3597 T->isSpelledAsLValue(),
3598 TL.getSigilLoc());
3599 if (Result.isNull())
3600 return QualType();
3601 }
3602
John McCallf85e1932011-06-15 23:02:42 +00003603 // Objective-C ARC can add lifetime qualifiers to the type that we're
3604 // referring to.
3605 TLB.TypeWasModifiedSafely(
3606 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3607
John McCall85737a72009-10-30 00:06:24 +00003608 // r-value references can be rebuilt as l-value references.
3609 ReferenceTypeLoc NewTL;
3610 if (isa<LValueReferenceType>(Result))
3611 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3612 else
3613 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3614 NewTL.setSigilLoc(TL.getSigilLoc());
3615
3616 return Result;
3617}
3618
Mike Stump1eb44332009-09-09 15:08:12 +00003619template<typename Derived>
3620QualType
John McCalla2becad2009-10-21 00:40:46 +00003621TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003622 LValueReferenceTypeLoc TL) {
3623 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003624}
3625
Mike Stump1eb44332009-09-09 15:08:12 +00003626template<typename Derived>
3627QualType
John McCalla2becad2009-10-21 00:40:46 +00003628TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003629 RValueReferenceTypeLoc TL) {
3630 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003631}
Mike Stump1eb44332009-09-09 15:08:12 +00003632
Douglas Gregor577f75a2009-08-04 16:50:30 +00003633template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003634QualType
John McCalla2becad2009-10-21 00:40:46 +00003635TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003636 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003637 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003638 if (PointeeType.isNull())
3639 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003640
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003641 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3642 TypeSourceInfo* NewClsTInfo = 0;
3643 if (OldClsTInfo) {
3644 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3645 if (!NewClsTInfo)
3646 return QualType();
3647 }
3648
3649 const MemberPointerType *T = TL.getTypePtr();
3650 QualType OldClsType = QualType(T->getClass(), 0);
3651 QualType NewClsType;
3652 if (NewClsTInfo)
3653 NewClsType = NewClsTInfo->getType();
3654 else {
3655 NewClsType = getDerived().TransformType(OldClsType);
3656 if (NewClsType.isNull())
3657 return QualType();
3658 }
Mike Stump1eb44332009-09-09 15:08:12 +00003659
John McCalla2becad2009-10-21 00:40:46 +00003660 QualType Result = TL.getType();
3661 if (getDerived().AlwaysRebuild() ||
3662 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003663 NewClsType != OldClsType) {
3664 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003665 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003666 if (Result.isNull())
3667 return QualType();
3668 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003669
John McCalla2becad2009-10-21 00:40:46 +00003670 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3671 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003672 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003673
3674 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003675}
3676
Mike Stump1eb44332009-09-09 15:08:12 +00003677template<typename Derived>
3678QualType
John McCalla2becad2009-10-21 00:40:46 +00003679TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003680 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003681 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003682 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003683 if (ElementType.isNull())
3684 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003685
John McCalla2becad2009-10-21 00:40:46 +00003686 QualType Result = TL.getType();
3687 if (getDerived().AlwaysRebuild() ||
3688 ElementType != T->getElementType()) {
3689 Result = getDerived().RebuildConstantArrayType(ElementType,
3690 T->getSizeModifier(),
3691 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003692 T->getIndexTypeCVRQualifiers(),
3693 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003694 if (Result.isNull())
3695 return QualType();
3696 }
Eli Friedman457a3772012-01-25 22:19:07 +00003697
3698 // We might have either a ConstantArrayType or a VariableArrayType now:
3699 // a ConstantArrayType is allowed to have an element type which is a
3700 // VariableArrayType if the type is dependent. Fortunately, all array
3701 // types have the same location layout.
3702 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003703 NewTL.setLBracketLoc(TL.getLBracketLoc());
3704 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003705
John McCalla2becad2009-10-21 00:40:46 +00003706 Expr *Size = TL.getSizeExpr();
3707 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003708 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3709 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003710 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003711 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003712 }
3713 NewTL.setSizeExpr(Size);
3714
3715 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003716}
Mike Stump1eb44332009-09-09 15:08:12 +00003717
Douglas Gregor577f75a2009-08-04 16:50:30 +00003718template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003719QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003720 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003721 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003722 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003723 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003724 if (ElementType.isNull())
3725 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003726
John McCalla2becad2009-10-21 00:40:46 +00003727 QualType Result = TL.getType();
3728 if (getDerived().AlwaysRebuild() ||
3729 ElementType != T->getElementType()) {
3730 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003731 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003732 T->getIndexTypeCVRQualifiers(),
3733 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003734 if (Result.isNull())
3735 return QualType();
3736 }
Sean Huntc3021132010-05-05 15:23:54 +00003737
John McCalla2becad2009-10-21 00:40:46 +00003738 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3739 NewTL.setLBracketLoc(TL.getLBracketLoc());
3740 NewTL.setRBracketLoc(TL.getRBracketLoc());
3741 NewTL.setSizeExpr(0);
3742
3743 return Result;
3744}
3745
3746template<typename Derived>
3747QualType
3748TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003749 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003750 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003751 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3752 if (ElementType.isNull())
3753 return QualType();
3754
John McCall60d7b3a2010-08-24 06:29:42 +00003755 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003756 = getDerived().TransformExpr(T->getSizeExpr());
3757 if (SizeResult.isInvalid())
3758 return QualType();
3759
John McCall9ae2f072010-08-23 23:25:46 +00003760 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003761
3762 QualType Result = TL.getType();
3763 if (getDerived().AlwaysRebuild() ||
3764 ElementType != T->getElementType() ||
3765 Size != T->getSizeExpr()) {
3766 Result = getDerived().RebuildVariableArrayType(ElementType,
3767 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003768 Size,
John McCalla2becad2009-10-21 00:40:46 +00003769 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003770 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003771 if (Result.isNull())
3772 return QualType();
3773 }
Sean Huntc3021132010-05-05 15:23:54 +00003774
John McCalla2becad2009-10-21 00:40:46 +00003775 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3776 NewTL.setLBracketLoc(TL.getLBracketLoc());
3777 NewTL.setRBracketLoc(TL.getRBracketLoc());
3778 NewTL.setSizeExpr(Size);
3779
3780 return Result;
3781}
3782
3783template<typename Derived>
3784QualType
3785TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003786 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003787 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003788 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3789 if (ElementType.isNull())
3790 return QualType();
3791
Richard Smithf6702a32011-12-20 02:08:33 +00003792 // Array bounds are constant expressions.
3793 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3794 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003795
John McCall3b657512011-01-19 10:06:00 +00003796 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3797 Expr *origSize = TL.getSizeExpr();
3798 if (!origSize) origSize = T->getSizeExpr();
3799
3800 ExprResult sizeResult
3801 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003802 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003803 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003804 return QualType();
3805
John McCall3b657512011-01-19 10:06:00 +00003806 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003807
3808 QualType Result = TL.getType();
3809 if (getDerived().AlwaysRebuild() ||
3810 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003811 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003812 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3813 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003814 size,
John McCalla2becad2009-10-21 00:40:46 +00003815 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003816 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003817 if (Result.isNull())
3818 return QualType();
3819 }
John McCalla2becad2009-10-21 00:40:46 +00003820
3821 // We might have any sort of array type now, but fortunately they
3822 // all have the same location layout.
3823 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3824 NewTL.setLBracketLoc(TL.getLBracketLoc());
3825 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003826 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003827
3828 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003829}
Mike Stump1eb44332009-09-09 15:08:12 +00003830
3831template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003832QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003833 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003834 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003835 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003836
3837 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003838 QualType ElementType = getDerived().TransformType(T->getElementType());
3839 if (ElementType.isNull())
3840 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003841
Richard Smithf6702a32011-12-20 02:08:33 +00003842 // Vector sizes are constant expressions.
3843 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3844 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003845
John McCall60d7b3a2010-08-24 06:29:42 +00003846 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003847 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003848 if (Size.isInvalid())
3849 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003850
John McCalla2becad2009-10-21 00:40:46 +00003851 QualType Result = TL.getType();
3852 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003853 ElementType != T->getElementType() ||
3854 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003855 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003856 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003857 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003858 if (Result.isNull())
3859 return QualType();
3860 }
John McCalla2becad2009-10-21 00:40:46 +00003861
3862 // Result might be dependent or not.
3863 if (isa<DependentSizedExtVectorType>(Result)) {
3864 DependentSizedExtVectorTypeLoc NewTL
3865 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3866 NewTL.setNameLoc(TL.getNameLoc());
3867 } else {
3868 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3869 NewTL.setNameLoc(TL.getNameLoc());
3870 }
3871
3872 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003873}
Mike Stump1eb44332009-09-09 15:08:12 +00003874
3875template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003876QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003877 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003878 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003879 QualType ElementType = getDerived().TransformType(T->getElementType());
3880 if (ElementType.isNull())
3881 return QualType();
3882
John McCalla2becad2009-10-21 00:40:46 +00003883 QualType Result = TL.getType();
3884 if (getDerived().AlwaysRebuild() ||
3885 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003886 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003887 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003888 if (Result.isNull())
3889 return QualType();
3890 }
Sean Huntc3021132010-05-05 15:23:54 +00003891
John McCalla2becad2009-10-21 00:40:46 +00003892 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3893 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003894
John McCalla2becad2009-10-21 00:40:46 +00003895 return Result;
3896}
3897
3898template<typename Derived>
3899QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003900 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003901 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003902 QualType ElementType = getDerived().TransformType(T->getElementType());
3903 if (ElementType.isNull())
3904 return QualType();
3905
3906 QualType Result = TL.getType();
3907 if (getDerived().AlwaysRebuild() ||
3908 ElementType != T->getElementType()) {
3909 Result = getDerived().RebuildExtVectorType(ElementType,
3910 T->getNumElements(),
3911 /*FIXME*/ SourceLocation());
3912 if (Result.isNull())
3913 return QualType();
3914 }
Sean Huntc3021132010-05-05 15:23:54 +00003915
John McCalla2becad2009-10-21 00:40:46 +00003916 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3917 NewTL.setNameLoc(TL.getNameLoc());
3918
3919 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003920}
Mike Stump1eb44332009-09-09 15:08:12 +00003921
3922template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003923ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003924TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003925 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003926 llvm::Optional<unsigned> NumExpansions,
3927 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003928 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003929 TypeSourceInfo *NewDI = 0;
3930
3931 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3932 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003933 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003934 TypeLoc OldTL = OldDI->getTypeLoc();
3935 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3936
3937 TypeLocBuilder TLB;
3938 TypeLoc NewTL = OldDI->getTypeLoc();
3939 TLB.reserve(NewTL.getFullDataSize());
3940
3941 QualType Result = getDerived().TransformType(TLB,
3942 OldExpansionTL.getPatternLoc());
3943 if (Result.isNull())
3944 return 0;
3945
3946 Result = RebuildPackExpansionType(Result,
3947 OldExpansionTL.getPatternLoc().getSourceRange(),
3948 OldExpansionTL.getEllipsisLoc(),
3949 NumExpansions);
3950 if (Result.isNull())
3951 return 0;
3952
3953 PackExpansionTypeLoc NewExpansionTL
3954 = TLB.push<PackExpansionTypeLoc>(Result);
3955 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3956 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3957 } else
3958 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003959 if (!NewDI)
3960 return 0;
3961
John McCallfb44de92011-05-01 22:35:37 +00003962 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003963 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003964
3965 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3966 OldParm->getDeclContext(),
3967 OldParm->getInnerLocStart(),
3968 OldParm->getLocation(),
3969 OldParm->getIdentifier(),
3970 NewDI->getType(),
3971 NewDI,
3972 OldParm->getStorageClass(),
3973 OldParm->getStorageClassAsWritten(),
3974 /* DefArg */ NULL);
3975 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3976 OldParm->getFunctionScopeIndex() + indexAdjustment);
3977 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003978}
3979
3980template<typename Derived>
3981bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003982 TransformFunctionTypeParams(SourceLocation Loc,
3983 ParmVarDecl **Params, unsigned NumParams,
3984 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003985 SmallVectorImpl<QualType> &OutParamTypes,
3986 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003987 int indexAdjustment = 0;
3988
Douglas Gregora009b592011-01-07 00:20:55 +00003989 for (unsigned i = 0; i != NumParams; ++i) {
3990 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003991 assert(OldParm->getFunctionScopeIndex() == i);
3992
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003993 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003994 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003995 if (OldParm->isParameterPack()) {
3996 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003997 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003998
Douglas Gregor603cfb42011-01-05 23:12:31 +00003999 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004000 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4001 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
4002 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4003 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004004 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4005
Douglas Gregor603cfb42011-01-05 23:12:31 +00004006 // Determine whether we should expand the parameter packs.
4007 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004008 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004009 llvm::Optional<unsigned> OrigNumExpansions
4010 = ExpansionTL.getTypePtr()->getNumExpansions();
4011 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004012 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4013 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004014 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004015 ShouldExpand,
4016 RetainExpansion,
4017 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004018 return true;
4019 }
4020
4021 if (ShouldExpand) {
4022 // Expand the function parameter pack into multiple, separate
4023 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004024 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004025 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004026 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4027 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004028 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004029 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004030 OrigNumExpansions,
4031 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004032 if (!NewParm)
4033 return true;
4034
Douglas Gregora009b592011-01-07 00:20:55 +00004035 OutParamTypes.push_back(NewParm->getType());
4036 if (PVars)
4037 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004038 }
Douglas Gregord3731192011-01-10 07:32:04 +00004039
4040 // If we're supposed to retain a pack expansion, do so by temporarily
4041 // forgetting the partially-substituted parameter pack.
4042 if (RetainExpansion) {
4043 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4044 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004045 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004046 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004047 OrigNumExpansions,
4048 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004049 if (!NewParm)
4050 return true;
4051
4052 OutParamTypes.push_back(NewParm->getType());
4053 if (PVars)
4054 PVars->push_back(NewParm);
4055 }
4056
John McCallfb44de92011-05-01 22:35:37 +00004057 // The next parameter should have the same adjustment as the
4058 // last thing we pushed, but we post-incremented indexAdjustment
4059 // on every push. Also, if we push nothing, the adjustment should
4060 // go down by one.
4061 indexAdjustment--;
4062
Douglas Gregor603cfb42011-01-05 23:12:31 +00004063 // We're done with the pack expansion.
4064 continue;
4065 }
4066
4067 // We'll substitute the parameter now without expanding the pack
4068 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004069 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4070 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004071 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004072 NumExpansions,
4073 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004074 } else {
4075 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004076 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004077 llvm::Optional<unsigned>(),
4078 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004079 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004080
John McCall21ef0fa2010-03-11 09:03:00 +00004081 if (!NewParm)
4082 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004083
Douglas Gregora009b592011-01-07 00:20:55 +00004084 OutParamTypes.push_back(NewParm->getType());
4085 if (PVars)
4086 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004087 continue;
4088 }
John McCall21ef0fa2010-03-11 09:03:00 +00004089
4090 // Deal with the possibility that we don't have a parameter
4091 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004092 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004093 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004094 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004095 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004096 if (const PackExpansionType *Expansion
4097 = dyn_cast<PackExpansionType>(OldType)) {
4098 // We have a function parameter pack that may need to be expanded.
4099 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004100 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004101 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4102
4103 // Determine whether we should expand the parameter packs.
4104 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004105 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004106 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004107 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004108 ShouldExpand,
4109 RetainExpansion,
4110 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004111 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004112 }
4113
4114 if (ShouldExpand) {
4115 // Expand the function parameter pack into multiple, separate
4116 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004117 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004118 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4119 QualType NewType = getDerived().TransformType(Pattern);
4120 if (NewType.isNull())
4121 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004122
Douglas Gregora009b592011-01-07 00:20:55 +00004123 OutParamTypes.push_back(NewType);
4124 if (PVars)
4125 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004126 }
4127
4128 // We're done with the pack expansion.
4129 continue;
4130 }
4131
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004132 // If we're supposed to retain a pack expansion, do so by temporarily
4133 // forgetting the partially-substituted parameter pack.
4134 if (RetainExpansion) {
4135 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4136 QualType NewType = getDerived().TransformType(Pattern);
4137 if (NewType.isNull())
4138 return true;
4139
4140 OutParamTypes.push_back(NewType);
4141 if (PVars)
4142 PVars->push_back(0);
4143 }
Douglas Gregord3731192011-01-10 07:32:04 +00004144
Douglas Gregor603cfb42011-01-05 23:12:31 +00004145 // We'll substitute the parameter now without expanding the pack
4146 // expansion.
4147 OldType = Expansion->getPattern();
4148 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004149 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4150 NewType = getDerived().TransformType(OldType);
4151 } else {
4152 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004153 }
4154
Douglas Gregor603cfb42011-01-05 23:12:31 +00004155 if (NewType.isNull())
4156 return true;
4157
4158 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004159 NewType = getSema().Context.getPackExpansionType(NewType,
4160 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004161
Douglas Gregora009b592011-01-07 00:20:55 +00004162 OutParamTypes.push_back(NewType);
4163 if (PVars)
4164 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004165 }
4166
John McCallfb44de92011-05-01 22:35:37 +00004167#ifndef NDEBUG
4168 if (PVars) {
4169 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4170 if (ParmVarDecl *parm = (*PVars)[i])
4171 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004172 }
John McCallfb44de92011-05-01 22:35:37 +00004173#endif
4174
4175 return false;
4176}
John McCall21ef0fa2010-03-11 09:03:00 +00004177
4178template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004179QualType
John McCalla2becad2009-10-21 00:40:46 +00004180TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004181 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004182 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4183}
4184
4185template<typename Derived>
4186QualType
4187TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4188 FunctionProtoTypeLoc TL,
4189 CXXRecordDecl *ThisContext,
4190 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004191 // Transform the parameters and return type.
4192 //
Richard Smithe6975e92012-04-17 00:58:00 +00004193 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004194 // When the function has a trailing return type, we instantiate the
4195 // parameters before the return type, since the return type can then refer
4196 // to the parameters themselves (via decltype, sizeof, etc.).
4197 //
Chris Lattner686775d2011-07-20 06:58:45 +00004198 SmallVector<QualType, 4> ParamTypes;
4199 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004200 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004201
Douglas Gregordab60ad2010-10-01 18:44:50 +00004202 QualType ResultType;
4203
4204 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004205 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4206 TL.getParmArray(),
4207 TL.getNumArgs(),
4208 TL.getTypePtr()->arg_type_begin(),
4209 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004210 return QualType();
4211
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004212 {
4213 // C++11 [expr.prim.general]p3:
4214 // If a declaration declares a member function or member function
4215 // template of a class X, the expression this is a prvalue of type
4216 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
4217 // and the end of the function-definition, member-declarator, or
4218 // declarator.
4219 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
4220
4221 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4222 if (ResultType.isNull())
4223 return QualType();
4224 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004225 }
4226 else {
4227 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4228 if (ResultType.isNull())
4229 return QualType();
4230
Douglas Gregora009b592011-01-07 00:20:55 +00004231 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4232 TL.getParmArray(),
4233 TL.getNumArgs(),
4234 TL.getTypePtr()->arg_type_begin(),
4235 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004236 return QualType();
4237 }
4238
Richard Smithe6975e92012-04-17 00:58:00 +00004239 // FIXME: Need to transform the exception-specification too.
4240
John McCalla2becad2009-10-21 00:40:46 +00004241 QualType Result = TL.getType();
4242 if (getDerived().AlwaysRebuild() ||
4243 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004244 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004245 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4246 Result = getDerived().RebuildFunctionProtoType(ResultType,
4247 ParamTypes.data(),
4248 ParamTypes.size(),
4249 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004250 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004251 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004252 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004253 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004254 if (Result.isNull())
4255 return QualType();
4256 }
Mike Stump1eb44332009-09-09 15:08:12 +00004257
John McCalla2becad2009-10-21 00:40:46 +00004258 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004259 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4260 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004261 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004262 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4263 NewTL.setArg(i, ParamDecls[i]);
4264
4265 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004266}
Mike Stump1eb44332009-09-09 15:08:12 +00004267
Douglas Gregor577f75a2009-08-04 16:50:30 +00004268template<typename Derived>
4269QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004270 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004271 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004272 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004273 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4274 if (ResultType.isNull())
4275 return QualType();
4276
4277 QualType Result = TL.getType();
4278 if (getDerived().AlwaysRebuild() ||
4279 ResultType != T->getResultType())
4280 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4281
4282 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004283 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4284 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004285 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004286
4287 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004288}
Mike Stump1eb44332009-09-09 15:08:12 +00004289
John McCalled976492009-12-04 22:46:56 +00004290template<typename Derived> QualType
4291TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004292 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004293 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004294 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004295 if (!D)
4296 return QualType();
4297
4298 QualType Result = TL.getType();
4299 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4300 Result = getDerived().RebuildUnresolvedUsingType(D);
4301 if (Result.isNull())
4302 return QualType();
4303 }
4304
4305 // We might get an arbitrary type spec type back. We should at
4306 // least always get a type spec type, though.
4307 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4308 NewTL.setNameLoc(TL.getNameLoc());
4309
4310 return Result;
4311}
4312
Douglas Gregor577f75a2009-08-04 16:50:30 +00004313template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004314QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004315 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004316 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004317 TypedefNameDecl *Typedef
4318 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4319 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004320 if (!Typedef)
4321 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004322
John McCalla2becad2009-10-21 00:40:46 +00004323 QualType Result = TL.getType();
4324 if (getDerived().AlwaysRebuild() ||
4325 Typedef != T->getDecl()) {
4326 Result = getDerived().RebuildTypedefType(Typedef);
4327 if (Result.isNull())
4328 return QualType();
4329 }
Mike Stump1eb44332009-09-09 15:08:12 +00004330
John McCalla2becad2009-10-21 00:40:46 +00004331 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4332 NewTL.setNameLoc(TL.getNameLoc());
4333
4334 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004335}
Mike Stump1eb44332009-09-09 15:08:12 +00004336
Douglas Gregor577f75a2009-08-04 16:50:30 +00004337template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004338QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004339 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004340 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004341 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004342
John McCall60d7b3a2010-08-24 06:29:42 +00004343 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004344 if (E.isInvalid())
4345 return QualType();
4346
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004347 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4348 if (E.isInvalid())
4349 return QualType();
4350
John McCalla2becad2009-10-21 00:40:46 +00004351 QualType Result = TL.getType();
4352 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004353 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004354 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004355 if (Result.isNull())
4356 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004357 }
John McCalla2becad2009-10-21 00:40:46 +00004358 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004359
John McCalla2becad2009-10-21 00:40:46 +00004360 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004361 NewTL.setTypeofLoc(TL.getTypeofLoc());
4362 NewTL.setLParenLoc(TL.getLParenLoc());
4363 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004364
4365 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004366}
Mike Stump1eb44332009-09-09 15:08:12 +00004367
4368template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004369QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004370 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004371 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4372 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4373 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004374 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004375
John McCalla2becad2009-10-21 00:40:46 +00004376 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004377 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4378 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004379 if (Result.isNull())
4380 return QualType();
4381 }
Mike Stump1eb44332009-09-09 15:08:12 +00004382
John McCalla2becad2009-10-21 00:40:46 +00004383 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004384 NewTL.setTypeofLoc(TL.getTypeofLoc());
4385 NewTL.setLParenLoc(TL.getLParenLoc());
4386 NewTL.setRParenLoc(TL.getRParenLoc());
4387 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004388
4389 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004390}
Mike Stump1eb44332009-09-09 15:08:12 +00004391
4392template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004393QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004394 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004395 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004396
Douglas Gregor670444e2009-08-04 22:27:00 +00004397 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004398 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4399 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004400
John McCall60d7b3a2010-08-24 06:29:42 +00004401 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004402 if (E.isInvalid())
4403 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004404
Richard Smith76f3f692012-02-22 02:04:18 +00004405 E = getSema().ActOnDecltypeExpression(E.take());
4406 if (E.isInvalid())
4407 return QualType();
4408
John McCalla2becad2009-10-21 00:40:46 +00004409 QualType Result = TL.getType();
4410 if (getDerived().AlwaysRebuild() ||
4411 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004412 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004413 if (Result.isNull())
4414 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004415 }
John McCalla2becad2009-10-21 00:40:46 +00004416 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004417
John McCalla2becad2009-10-21 00:40:46 +00004418 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4419 NewTL.setNameLoc(TL.getNameLoc());
4420
4421 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004422}
4423
4424template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004425QualType TreeTransform<Derived>::TransformUnaryTransformType(
4426 TypeLocBuilder &TLB,
4427 UnaryTransformTypeLoc TL) {
4428 QualType Result = TL.getType();
4429 if (Result->isDependentType()) {
4430 const UnaryTransformType *T = TL.getTypePtr();
4431 QualType NewBase =
4432 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4433 Result = getDerived().RebuildUnaryTransformType(NewBase,
4434 T->getUTTKind(),
4435 TL.getKWLoc());
4436 if (Result.isNull())
4437 return QualType();
4438 }
4439
4440 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4441 NewTL.setKWLoc(TL.getKWLoc());
4442 NewTL.setParensRange(TL.getParensRange());
4443 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4444 return Result;
4445}
4446
4447template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004448QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4449 AutoTypeLoc TL) {
4450 const AutoType *T = TL.getTypePtr();
4451 QualType OldDeduced = T->getDeducedType();
4452 QualType NewDeduced;
4453 if (!OldDeduced.isNull()) {
4454 NewDeduced = getDerived().TransformType(OldDeduced);
4455 if (NewDeduced.isNull())
4456 return QualType();
4457 }
4458
4459 QualType Result = TL.getType();
4460 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4461 Result = getDerived().RebuildAutoType(NewDeduced);
4462 if (Result.isNull())
4463 return QualType();
4464 }
4465
4466 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4467 NewTL.setNameLoc(TL.getNameLoc());
4468
4469 return Result;
4470}
4471
4472template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004473QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004474 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004475 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004476 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004477 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4478 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004479 if (!Record)
4480 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004481
John McCalla2becad2009-10-21 00:40:46 +00004482 QualType Result = TL.getType();
4483 if (getDerived().AlwaysRebuild() ||
4484 Record != T->getDecl()) {
4485 Result = getDerived().RebuildRecordType(Record);
4486 if (Result.isNull())
4487 return QualType();
4488 }
Mike Stump1eb44332009-09-09 15:08:12 +00004489
John McCalla2becad2009-10-21 00:40:46 +00004490 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4491 NewTL.setNameLoc(TL.getNameLoc());
4492
4493 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004494}
Mike Stump1eb44332009-09-09 15:08:12 +00004495
4496template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004497QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004498 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004499 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004500 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004501 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4502 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004503 if (!Enum)
4504 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004505
John McCalla2becad2009-10-21 00:40:46 +00004506 QualType Result = TL.getType();
4507 if (getDerived().AlwaysRebuild() ||
4508 Enum != T->getDecl()) {
4509 Result = getDerived().RebuildEnumType(Enum);
4510 if (Result.isNull())
4511 return QualType();
4512 }
Mike Stump1eb44332009-09-09 15:08:12 +00004513
John McCalla2becad2009-10-21 00:40:46 +00004514 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4515 NewTL.setNameLoc(TL.getNameLoc());
4516
4517 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004518}
John McCall7da24312009-09-05 00:15:47 +00004519
John McCall3cb0ebd2010-03-10 03:28:59 +00004520template<typename Derived>
4521QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4522 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004523 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004524 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4525 TL.getTypePtr()->getDecl());
4526 if (!D) return QualType();
4527
4528 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4529 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4530 return T;
4531}
4532
Douglas Gregor577f75a2009-08-04 16:50:30 +00004533template<typename Derived>
4534QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004535 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004536 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004537 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004538}
4539
Mike Stump1eb44332009-09-09 15:08:12 +00004540template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004541QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004542 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004543 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004544 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4545
4546 // Substitute into the replacement type, which itself might involve something
4547 // that needs to be transformed. This only tends to occur with default
4548 // template arguments of template template parameters.
4549 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4550 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4551 if (Replacement.isNull())
4552 return QualType();
4553
4554 // Always canonicalize the replacement type.
4555 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4556 QualType Result
4557 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4558 Replacement);
4559
4560 // Propagate type-source information.
4561 SubstTemplateTypeParmTypeLoc NewTL
4562 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4563 NewTL.setNameLoc(TL.getNameLoc());
4564 return Result;
4565
John McCall49a832b2009-10-18 09:09:24 +00004566}
4567
4568template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004569QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4570 TypeLocBuilder &TLB,
4571 SubstTemplateTypeParmPackTypeLoc TL) {
4572 return TransformTypeSpecType(TLB, TL);
4573}
4574
4575template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004576QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004577 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004578 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004579 const TemplateSpecializationType *T = TL.getTypePtr();
4580
Douglas Gregor1d752d72011-03-02 18:46:51 +00004581 // The nested-name-specifier never matters in a TemplateSpecializationType,
4582 // because we can't have a dependent nested-name-specifier anyway.
4583 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004584 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004585 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4586 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004587 if (Template.isNull())
4588 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004589
John McCall43fed0d2010-11-12 08:19:04 +00004590 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4591}
4592
Eli Friedmanb001de72011-10-06 23:00:33 +00004593template<typename Derived>
4594QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4595 AtomicTypeLoc TL) {
4596 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4597 if (ValueType.isNull())
4598 return QualType();
4599
4600 QualType Result = TL.getType();
4601 if (getDerived().AlwaysRebuild() ||
4602 ValueType != TL.getValueLoc().getType()) {
4603 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4604 if (Result.isNull())
4605 return QualType();
4606 }
4607
4608 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4609 NewTL.setKWLoc(TL.getKWLoc());
4610 NewTL.setLParenLoc(TL.getLParenLoc());
4611 NewTL.setRParenLoc(TL.getRParenLoc());
4612
4613 return Result;
4614}
4615
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004616namespace {
4617 /// \brief Simple iterator that traverses the template arguments in a
4618 /// container that provides a \c getArgLoc() member function.
4619 ///
4620 /// This iterator is intended to be used with the iterator form of
4621 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4622 template<typename ArgLocContainer>
4623 class TemplateArgumentLocContainerIterator {
4624 ArgLocContainer *Container;
4625 unsigned Index;
4626
4627 public:
4628 typedef TemplateArgumentLoc value_type;
4629 typedef TemplateArgumentLoc reference;
4630 typedef int difference_type;
4631 typedef std::input_iterator_tag iterator_category;
4632
4633 class pointer {
4634 TemplateArgumentLoc Arg;
4635
4636 public:
4637 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4638
4639 const TemplateArgumentLoc *operator->() const {
4640 return &Arg;
4641 }
4642 };
4643
4644
4645 TemplateArgumentLocContainerIterator() {}
4646
4647 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4648 unsigned Index)
4649 : Container(&Container), Index(Index) { }
4650
4651 TemplateArgumentLocContainerIterator &operator++() {
4652 ++Index;
4653 return *this;
4654 }
4655
4656 TemplateArgumentLocContainerIterator operator++(int) {
4657 TemplateArgumentLocContainerIterator Old(*this);
4658 ++(*this);
4659 return Old;
4660 }
4661
4662 TemplateArgumentLoc operator*() const {
4663 return Container->getArgLoc(Index);
4664 }
4665
4666 pointer operator->() const {
4667 return pointer(Container->getArgLoc(Index));
4668 }
4669
4670 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004671 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004672 return X.Container == Y.Container && X.Index == Y.Index;
4673 }
4674
4675 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004676 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004677 return !(X == Y);
4678 }
4679 };
4680}
4681
4682
John McCall43fed0d2010-11-12 08:19:04 +00004683template <typename Derived>
4684QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4685 TypeLocBuilder &TLB,
4686 TemplateSpecializationTypeLoc TL,
4687 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004688 TemplateArgumentListInfo NewTemplateArgs;
4689 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4690 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004691 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4692 ArgIterator;
4693 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4694 ArgIterator(TL, TL.getNumArgs()),
4695 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004696 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004697
John McCall833ca992009-10-29 08:12:44 +00004698 // FIXME: maybe don't rebuild if all the template arguments are the same.
4699
4700 QualType Result =
4701 getDerived().RebuildTemplateSpecializationType(Template,
4702 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004703 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004704
4705 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004706 // Specializations of template template parameters are represented as
4707 // TemplateSpecializationTypes, and substitution of type alias templates
4708 // within a dependent context can transform them into
4709 // DependentTemplateSpecializationTypes.
4710 if (isa<DependentTemplateSpecializationType>(Result)) {
4711 DependentTemplateSpecializationTypeLoc NewTL
4712 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004713 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004714 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004715 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004716 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004717 NewTL.setLAngleLoc(TL.getLAngleLoc());
4718 NewTL.setRAngleLoc(TL.getRAngleLoc());
4719 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4720 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4721 return Result;
4722 }
4723
John McCall833ca992009-10-29 08:12:44 +00004724 TemplateSpecializationTypeLoc NewTL
4725 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004726 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004727 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4728 NewTL.setLAngleLoc(TL.getLAngleLoc());
4729 NewTL.setRAngleLoc(TL.getRAngleLoc());
4730 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4731 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004732 }
Mike Stump1eb44332009-09-09 15:08:12 +00004733
John McCall833ca992009-10-29 08:12:44 +00004734 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004735}
Mike Stump1eb44332009-09-09 15:08:12 +00004736
Douglas Gregora88f09f2011-02-28 17:23:35 +00004737template <typename Derived>
4738QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4739 TypeLocBuilder &TLB,
4740 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004741 TemplateName Template,
4742 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004743 TemplateArgumentListInfo NewTemplateArgs;
4744 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4745 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4746 typedef TemplateArgumentLocContainerIterator<
4747 DependentTemplateSpecializationTypeLoc> ArgIterator;
4748 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4749 ArgIterator(TL, TL.getNumArgs()),
4750 NewTemplateArgs))
4751 return QualType();
4752
4753 // FIXME: maybe don't rebuild if all the template arguments are the same.
4754
4755 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4756 QualType Result
4757 = getSema().Context.getDependentTemplateSpecializationType(
4758 TL.getTypePtr()->getKeyword(),
4759 DTN->getQualifier(),
4760 DTN->getIdentifier(),
4761 NewTemplateArgs);
4762
4763 DependentTemplateSpecializationTypeLoc NewTL
4764 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004765 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004766 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004767 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004768 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004769 NewTL.setLAngleLoc(TL.getLAngleLoc());
4770 NewTL.setRAngleLoc(TL.getRAngleLoc());
4771 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4772 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4773 return Result;
4774 }
4775
4776 QualType Result
4777 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004778 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004779 NewTemplateArgs);
4780
4781 if (!Result.isNull()) {
4782 /// FIXME: Wrap this in an elaborated-type-specifier?
4783 TemplateSpecializationTypeLoc NewTL
4784 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004785 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004786 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004787 NewTL.setLAngleLoc(TL.getLAngleLoc());
4788 NewTL.setRAngleLoc(TL.getRAngleLoc());
4789 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4790 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4791 }
4792
4793 return Result;
4794}
4795
Mike Stump1eb44332009-09-09 15:08:12 +00004796template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004797QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004798TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004799 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004800 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004801
Douglas Gregor9e876872011-03-01 18:12:44 +00004802 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004803 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004804 if (TL.getQualifierLoc()) {
4805 QualifierLoc
4806 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4807 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004808 return QualType();
4809 }
Mike Stump1eb44332009-09-09 15:08:12 +00004810
John McCall43fed0d2010-11-12 08:19:04 +00004811 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4812 if (NamedT.isNull())
4813 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004814
Richard Smith3e4c6c42011-05-05 21:57:07 +00004815 // C++0x [dcl.type.elab]p2:
4816 // If the identifier resolves to a typedef-name or the simple-template-id
4817 // resolves to an alias template specialization, the
4818 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004819 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4820 if (const TemplateSpecializationType *TST =
4821 NamedT->getAs<TemplateSpecializationType>()) {
4822 TemplateName Template = TST->getTemplateName();
4823 if (TypeAliasTemplateDecl *TAT =
4824 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4825 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4826 diag::err_tag_reference_non_tag) << 4;
4827 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4828 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004829 }
4830 }
4831
John McCalla2becad2009-10-21 00:40:46 +00004832 QualType Result = TL.getType();
4833 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004834 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004835 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004836 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004837 T->getKeyword(),
4838 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004839 if (Result.isNull())
4840 return QualType();
4841 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004842
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004843 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004844 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004845 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004846 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004847}
Mike Stump1eb44332009-09-09 15:08:12 +00004848
4849template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004850QualType TreeTransform<Derived>::TransformAttributedType(
4851 TypeLocBuilder &TLB,
4852 AttributedTypeLoc TL) {
4853 const AttributedType *oldType = TL.getTypePtr();
4854 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4855 if (modifiedType.isNull())
4856 return QualType();
4857
4858 QualType result = TL.getType();
4859
4860 // FIXME: dependent operand expressions?
4861 if (getDerived().AlwaysRebuild() ||
4862 modifiedType != oldType->getModifiedType()) {
4863 // TODO: this is really lame; we should really be rebuilding the
4864 // equivalent type from first principles.
4865 QualType equivalentType
4866 = getDerived().TransformType(oldType->getEquivalentType());
4867 if (equivalentType.isNull())
4868 return QualType();
4869 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4870 modifiedType,
4871 equivalentType);
4872 }
4873
4874 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4875 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4876 if (TL.hasAttrOperand())
4877 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4878 if (TL.hasAttrExprOperand())
4879 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4880 else if (TL.hasAttrEnumOperand())
4881 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4882
4883 return result;
4884}
4885
4886template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004887QualType
4888TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4889 ParenTypeLoc TL) {
4890 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4891 if (Inner.isNull())
4892 return QualType();
4893
4894 QualType Result = TL.getType();
4895 if (getDerived().AlwaysRebuild() ||
4896 Inner != TL.getInnerLoc().getType()) {
4897 Result = getDerived().RebuildParenType(Inner);
4898 if (Result.isNull())
4899 return QualType();
4900 }
4901
4902 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4903 NewTL.setLParenLoc(TL.getLParenLoc());
4904 NewTL.setRParenLoc(TL.getRParenLoc());
4905 return Result;
4906}
4907
4908template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004909QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004910 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004911 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004912
Douglas Gregor2494dd02011-03-01 01:34:45 +00004913 NestedNameSpecifierLoc QualifierLoc
4914 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4915 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004916 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004917
John McCall33500952010-06-11 00:33:02 +00004918 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004919 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004920 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004921 QualifierLoc,
4922 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004923 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004924 if (Result.isNull())
4925 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004926
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004927 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4928 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004929 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4930
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004931 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004932 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004933 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004934 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004935 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004936 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004937 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004938 NewTL.setNameLoc(TL.getNameLoc());
4939 }
John McCalla2becad2009-10-21 00:40:46 +00004940 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004941}
Mike Stump1eb44332009-09-09 15:08:12 +00004942
Douglas Gregor577f75a2009-08-04 16:50:30 +00004943template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004944QualType TreeTransform<Derived>::
4945 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004946 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004947 NestedNameSpecifierLoc QualifierLoc;
4948 if (TL.getQualifierLoc()) {
4949 QualifierLoc
4950 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4951 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004952 return QualType();
4953 }
4954
John McCall43fed0d2010-11-12 08:19:04 +00004955 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004956 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004957}
4958
4959template<typename Derived>
4960QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004961TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4962 DependentTemplateSpecializationTypeLoc TL,
4963 NestedNameSpecifierLoc QualifierLoc) {
4964 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4965
4966 TemplateArgumentListInfo NewTemplateArgs;
4967 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4968 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4969
4970 typedef TemplateArgumentLocContainerIterator<
4971 DependentTemplateSpecializationTypeLoc> ArgIterator;
4972 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4973 ArgIterator(TL, TL.getNumArgs()),
4974 NewTemplateArgs))
4975 return QualType();
4976
4977 QualType Result
4978 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4979 QualifierLoc,
4980 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004981 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004982 NewTemplateArgs);
4983 if (Result.isNull())
4984 return QualType();
4985
4986 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4987 QualType NamedT = ElabT->getNamedType();
4988
4989 // Copy information relevant to the template specialization.
4990 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004991 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004992 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004993 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004994 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4995 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004996 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004997 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004998
4999 // Copy information relevant to the elaborated type.
5000 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005001 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005002 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005003 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5004 DependentTemplateSpecializationTypeLoc SpecTL
5005 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005006 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005007 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005008 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005009 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005010 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5011 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005012 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005013 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005014 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005015 TemplateSpecializationTypeLoc SpecTL
5016 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005017 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005018 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005019 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5020 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005021 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005022 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005023 }
5024 return Result;
5025}
5026
5027template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005028QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5029 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005030 QualType Pattern
5031 = getDerived().TransformType(TLB, TL.getPatternLoc());
5032 if (Pattern.isNull())
5033 return QualType();
5034
5035 QualType Result = TL.getType();
5036 if (getDerived().AlwaysRebuild() ||
5037 Pattern != TL.getPatternLoc().getType()) {
5038 Result = getDerived().RebuildPackExpansionType(Pattern,
5039 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005040 TL.getEllipsisLoc(),
5041 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005042 if (Result.isNull())
5043 return QualType();
5044 }
5045
5046 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5047 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5048 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005049}
5050
5051template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005052QualType
5053TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005054 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005055 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005056 TLB.pushFullCopy(TL);
5057 return TL.getType();
5058}
5059
5060template<typename Derived>
5061QualType
5062TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005063 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005064 // ObjCObjectType is never dependent.
5065 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005066 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005067}
Mike Stump1eb44332009-09-09 15:08:12 +00005068
5069template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005070QualType
5071TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005072 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005073 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005074 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005075 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005076}
5077
Douglas Gregor577f75a2009-08-04 16:50:30 +00005078//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005079// Statement transformation
5080//===----------------------------------------------------------------------===//
5081template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005082StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005083TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005084 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005085}
5086
5087template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005088StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005089TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5090 return getDerived().TransformCompoundStmt(S, false);
5091}
5092
5093template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005094StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005095TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005096 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005097 Sema::CompoundScopeRAII CompoundScope(getSema());
5098
John McCall7114cba2010-08-27 19:56:05 +00005099 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005100 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005101 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00005102 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5103 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005104 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005105 if (Result.isInvalid()) {
5106 // Immediately fail if this was a DeclStmt, since it's very
5107 // likely that this will cause problems for future statements.
5108 if (isa<DeclStmt>(*B))
5109 return StmtError();
5110
5111 // Otherwise, just keep processing substatements and fail later.
5112 SubStmtInvalid = true;
5113 continue;
5114 }
Mike Stump1eb44332009-09-09 15:08:12 +00005115
Douglas Gregor43959a92009-08-20 07:17:43 +00005116 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5117 Statements.push_back(Result.takeAs<Stmt>());
5118 }
Mike Stump1eb44332009-09-09 15:08:12 +00005119
John McCall7114cba2010-08-27 19:56:05 +00005120 if (SubStmtInvalid)
5121 return StmtError();
5122
Douglas Gregor43959a92009-08-20 07:17:43 +00005123 if (!getDerived().AlwaysRebuild() &&
5124 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005125 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005126
5127 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5128 move_arg(Statements),
5129 S->getRBracLoc(),
5130 IsStmtExpr);
5131}
Mike Stump1eb44332009-09-09 15:08:12 +00005132
Douglas Gregor43959a92009-08-20 07:17:43 +00005133template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005134StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005135TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005136 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005137 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005138 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5139 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005140
Eli Friedman264c1f82009-11-19 03:14:00 +00005141 // Transform the left-hand case value.
5142 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005143 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005144 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005145 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005146
Eli Friedman264c1f82009-11-19 03:14:00 +00005147 // Transform the right-hand case value (for the GNU case-range extension).
5148 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005149 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005150 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005151 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005152 }
Mike Stump1eb44332009-09-09 15:08:12 +00005153
Douglas Gregor43959a92009-08-20 07:17:43 +00005154 // Build the case statement.
5155 // Case statements are always rebuilt so that they will attached to their
5156 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005157 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005158 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005159 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005160 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005161 S->getColonLoc());
5162 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005163 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005164
Douglas Gregor43959a92009-08-20 07:17:43 +00005165 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005166 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005167 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005168 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005169
Douglas Gregor43959a92009-08-20 07:17:43 +00005170 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005171 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005172}
5173
5174template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005175StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005176TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005177 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005178 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005179 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005180 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005181
Douglas Gregor43959a92009-08-20 07:17:43 +00005182 // Default statements are always rebuilt
5183 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005184 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005185}
Mike Stump1eb44332009-09-09 15:08:12 +00005186
Douglas Gregor43959a92009-08-20 07:17:43 +00005187template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005188StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005189TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005190 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005191 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005192 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005193
Chris Lattner57ad3782011-02-17 20:34:02 +00005194 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5195 S->getDecl());
5196 if (!LD)
5197 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005198
5199
Douglas Gregor43959a92009-08-20 07:17:43 +00005200 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005201 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005202 cast<LabelDecl>(LD), SourceLocation(),
5203 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005204}
Mike Stump1eb44332009-09-09 15:08:12 +00005205
Douglas Gregor43959a92009-08-20 07:17:43 +00005206template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005207StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005208TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5209 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5210 if (SubStmt.isInvalid())
5211 return StmtError();
5212
5213 // TODO: transform attributes
5214 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5215 return S;
5216
5217 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5218 S->getAttrs(),
5219 SubStmt.get());
5220}
5221
5222template<typename Derived>
5223StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005224TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005225 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005226 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005227 VarDecl *ConditionVar = 0;
5228 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005229 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005230 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005231 getDerived().TransformDefinition(
5232 S->getConditionVariable()->getLocation(),
5233 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005234 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005235 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005236 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005237 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005238
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005239 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005240 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005241
5242 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005243 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005244 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5245 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005246 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005247 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005248
John McCall9ae2f072010-08-23 23:25:46 +00005249 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005250 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005251 }
Sean Huntc3021132010-05-05 15:23:54 +00005252
John McCall9ae2f072010-08-23 23:25:46 +00005253 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5254 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005255 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005256
Douglas Gregor43959a92009-08-20 07:17:43 +00005257 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005258 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005259 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005260 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005261
Douglas Gregor43959a92009-08-20 07:17:43 +00005262 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005263 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005264 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005265 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005266
Douglas Gregor43959a92009-08-20 07:17:43 +00005267 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005268 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005269 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005270 Then.get() == S->getThen() &&
5271 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005272 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005273
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005274 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005275 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005276 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005277}
5278
5279template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005280StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005281TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005282 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005283 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005284 VarDecl *ConditionVar = 0;
5285 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005286 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005287 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005288 getDerived().TransformDefinition(
5289 S->getConditionVariable()->getLocation(),
5290 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005291 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005292 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005293 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005294 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005295
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005296 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005297 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005298 }
Mike Stump1eb44332009-09-09 15:08:12 +00005299
Douglas Gregor43959a92009-08-20 07:17:43 +00005300 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005301 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005302 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005303 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005304 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005305 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005306
Douglas Gregor43959a92009-08-20 07:17:43 +00005307 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005308 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005309 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005310 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005311
Douglas Gregor43959a92009-08-20 07:17:43 +00005312 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005313 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5314 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005315}
Mike Stump1eb44332009-09-09 15:08:12 +00005316
Douglas Gregor43959a92009-08-20 07:17:43 +00005317template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005318StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005319TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005320 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005321 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005322 VarDecl *ConditionVar = 0;
5323 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005324 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005325 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005326 getDerived().TransformDefinition(
5327 S->getConditionVariable()->getLocation(),
5328 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005329 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005330 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005331 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005332 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005333
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005334 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005335 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005336
5337 if (S->getCond()) {
5338 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005339 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5340 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005341 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005342 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005343 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005344 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005345 }
Mike Stump1eb44332009-09-09 15:08:12 +00005346
John McCall9ae2f072010-08-23 23:25:46 +00005347 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5348 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005349 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005350
Douglas Gregor43959a92009-08-20 07:17:43 +00005351 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005352 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005353 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005354 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005355
Douglas Gregor43959a92009-08-20 07:17:43 +00005356 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005357 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005358 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005359 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005360 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005361
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005362 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005363 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005364}
Mike Stump1eb44332009-09-09 15:08:12 +00005365
Douglas Gregor43959a92009-08-20 07:17:43 +00005366template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005367StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005368TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005369 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005370 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005371 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005372 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005373
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005374 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005375 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005376 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005377 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005378
Douglas Gregor43959a92009-08-20 07:17:43 +00005379 if (!getDerived().AlwaysRebuild() &&
5380 Cond.get() == S->getCond() &&
5381 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005382 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005383
John McCall9ae2f072010-08-23 23:25:46 +00005384 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5385 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005386 S->getRParenLoc());
5387}
Mike Stump1eb44332009-09-09 15:08:12 +00005388
Douglas Gregor43959a92009-08-20 07:17:43 +00005389template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005390StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005391TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005392 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005393 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005394 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005395 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005396
Douglas Gregor43959a92009-08-20 07:17:43 +00005397 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005398 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005399 VarDecl *ConditionVar = 0;
5400 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005401 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005402 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005403 getDerived().TransformDefinition(
5404 S->getConditionVariable()->getLocation(),
5405 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005406 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005407 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005408 } else {
5409 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005410
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005411 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005412 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005413
5414 if (S->getCond()) {
5415 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005416 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5417 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005418 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005419 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005420
John McCall9ae2f072010-08-23 23:25:46 +00005421 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005422 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005423 }
Mike Stump1eb44332009-09-09 15:08:12 +00005424
John McCall9ae2f072010-08-23 23:25:46 +00005425 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5426 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005427 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005428
Douglas Gregor43959a92009-08-20 07:17:43 +00005429 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005430 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005431 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005432 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005433
John McCall9ae2f072010-08-23 23:25:46 +00005434 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5435 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005436 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005437
Douglas Gregor43959a92009-08-20 07:17:43 +00005438 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005439 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005440 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005441 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005442
Douglas Gregor43959a92009-08-20 07:17:43 +00005443 if (!getDerived().AlwaysRebuild() &&
5444 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005445 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005446 Inc.get() == S->getInc() &&
5447 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005448 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005449
Douglas Gregor43959a92009-08-20 07:17:43 +00005450 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005451 Init.get(), FullCond, ConditionVar,
5452 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005453}
5454
5455template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005456StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005457TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005458 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5459 S->getLabel());
5460 if (!LD)
5461 return StmtError();
5462
Douglas Gregor43959a92009-08-20 07:17:43 +00005463 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005464 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005465 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005466}
5467
5468template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005469StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005470TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005471 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005472 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005473 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005474 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005475
Douglas Gregor43959a92009-08-20 07:17:43 +00005476 if (!getDerived().AlwaysRebuild() &&
5477 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005478 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005479
5480 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005481 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005482}
5483
5484template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005485StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005486TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005487 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005488}
Mike Stump1eb44332009-09-09 15:08:12 +00005489
Douglas Gregor43959a92009-08-20 07:17:43 +00005490template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005491StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005492TreeTransform<Derived>::TransformBreakStmt(BreakStmt *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>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005499 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005500 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005501 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005502
Mike Stump1eb44332009-09-09 15:08:12 +00005503 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005504 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005505 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005506}
Mike Stump1eb44332009-09-09 15:08:12 +00005507
Douglas Gregor43959a92009-08-20 07:17:43 +00005508template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005509StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005510TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005511 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005512 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005513 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5514 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005515 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5516 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005517 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005518 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005519
Douglas Gregor43959a92009-08-20 07:17:43 +00005520 if (Transformed != *D)
5521 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005522
Douglas Gregor43959a92009-08-20 07:17:43 +00005523 Decls.push_back(Transformed);
5524 }
Mike Stump1eb44332009-09-09 15:08:12 +00005525
Douglas Gregor43959a92009-08-20 07:17:43 +00005526 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005527 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005528
5529 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005530 S->getStartLoc(), S->getEndLoc());
5531}
Mike Stump1eb44332009-09-09 15:08:12 +00005532
Douglas Gregor43959a92009-08-20 07:17:43 +00005533template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005534StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005535TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005536
John McCallca0408f2010-08-23 06:44:23 +00005537 ASTOwningVector<Expr*> Constraints(getSema());
5538 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005539 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005540
John McCall60d7b3a2010-08-24 06:29:42 +00005541 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005542 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005543
5544 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005545
Anders Carlsson703e3942010-01-24 05:50:09 +00005546 // Go through the outputs.
5547 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005548 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005549
Anders Carlsson703e3942010-01-24 05:50:09 +00005550 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005551 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005552
Anders Carlsson703e3942010-01-24 05:50:09 +00005553 // Transform the output expr.
5554 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005555 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005556 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005557 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005558
Anders Carlsson703e3942010-01-24 05:50:09 +00005559 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005560
John McCall9ae2f072010-08-23 23:25:46 +00005561 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005562 }
Sean Huntc3021132010-05-05 15:23:54 +00005563
Anders Carlsson703e3942010-01-24 05:50:09 +00005564 // Go through the inputs.
5565 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005566 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005567
Anders Carlsson703e3942010-01-24 05:50:09 +00005568 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005569 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005570
Anders Carlsson703e3942010-01-24 05:50:09 +00005571 // Transform the input expr.
5572 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005573 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005574 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005575 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005576
Anders Carlsson703e3942010-01-24 05:50:09 +00005577 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005578
John McCall9ae2f072010-08-23 23:25:46 +00005579 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005580 }
Sean Huntc3021132010-05-05 15:23:54 +00005581
Anders Carlsson703e3942010-01-24 05:50:09 +00005582 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005583 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005584
5585 // Go through the clobbers.
5586 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005587 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005588
5589 // No need to transform the asm string literal.
5590 AsmString = SemaRef.Owned(S->getAsmString());
5591
5592 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5593 S->isSimple(),
5594 S->isVolatile(),
5595 S->getNumOutputs(),
5596 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005597 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005598 move_arg(Constraints),
5599 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005600 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005601 move_arg(Clobbers),
5602 S->getRParenLoc(),
5603 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005604}
5605
Chad Rosier8cd64b42012-06-11 20:47:18 +00005606template<typename Derived>
5607StmtResult
5608TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
5609 // No need to transform the asm string literal.
5610 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(),
5611 *S->getAsmString(),
5612 S->getEndLoc());
5613}
Douglas Gregor43959a92009-08-20 07:17:43 +00005614
5615template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005616StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005617TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005618 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005619 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005620 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005621 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005622
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005623 // Transform the @catch statements (if present).
5624 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005625 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005626 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005627 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005628 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005629 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005630 if (Catch.get() != S->getCatchStmt(I))
5631 AnyCatchChanged = true;
5632 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005633 }
Sean Huntc3021132010-05-05 15:23:54 +00005634
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005635 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005636 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005637 if (S->getFinallyStmt()) {
5638 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5639 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005640 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005641 }
5642
5643 // If nothing changed, just retain this statement.
5644 if (!getDerived().AlwaysRebuild() &&
5645 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005646 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005647 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005648 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005649
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005650 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005651 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5652 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005653}
Mike Stump1eb44332009-09-09 15:08:12 +00005654
Douglas Gregor43959a92009-08-20 07:17:43 +00005655template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005656StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005657TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005658 // Transform the @catch parameter, if there is one.
5659 VarDecl *Var = 0;
5660 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5661 TypeSourceInfo *TSInfo = 0;
5662 if (FromVar->getTypeSourceInfo()) {
5663 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5664 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005665 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005666 }
Sean Huntc3021132010-05-05 15:23:54 +00005667
Douglas Gregorbe270a02010-04-26 17:57:08 +00005668 QualType T;
5669 if (TSInfo)
5670 T = TSInfo->getType();
5671 else {
5672 T = getDerived().TransformType(FromVar->getType());
5673 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005674 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005675 }
Sean Huntc3021132010-05-05 15:23:54 +00005676
Douglas Gregorbe270a02010-04-26 17:57:08 +00005677 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5678 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005679 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005680 }
Sean Huntc3021132010-05-05 15:23:54 +00005681
John McCall60d7b3a2010-08-24 06:29:42 +00005682 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005683 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005684 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005685
5686 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005687 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005688 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005689}
Mike Stump1eb44332009-09-09 15:08:12 +00005690
Douglas Gregor43959a92009-08-20 07:17:43 +00005691template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005692StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005693TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005694 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005695 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005696 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005697 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005698
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005699 // If nothing changed, just retain this statement.
5700 if (!getDerived().AlwaysRebuild() &&
5701 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005702 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005703
5704 // Build a new statement.
5705 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005706 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005707}
Mike Stump1eb44332009-09-09 15:08:12 +00005708
Douglas Gregor43959a92009-08-20 07:17:43 +00005709template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005710StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005711TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005712 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005713 if (S->getThrowExpr()) {
5714 Operand = getDerived().TransformExpr(S->getThrowExpr());
5715 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005716 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005717 }
Sean Huntc3021132010-05-05 15:23:54 +00005718
Douglas Gregord1377b22010-04-22 21:44:01 +00005719 if (!getDerived().AlwaysRebuild() &&
5720 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005721 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005722
John McCall9ae2f072010-08-23 23:25:46 +00005723 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005724}
Mike Stump1eb44332009-09-09 15:08:12 +00005725
Douglas Gregor43959a92009-08-20 07:17:43 +00005726template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005727StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005728TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005729 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005730 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005731 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005732 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005733 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005734 Object =
5735 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5736 Object.get());
5737 if (Object.isInvalid())
5738 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005739
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005740 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005741 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005742 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005743 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005744
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005745 // If nothing change, just retain the current statement.
5746 if (!getDerived().AlwaysRebuild() &&
5747 Object.get() == S->getSynchExpr() &&
5748 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005749 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005750
5751 // Build a new statement.
5752 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005753 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005754}
5755
5756template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005757StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005758TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5759 ObjCAutoreleasePoolStmt *S) {
5760 // Transform the body.
5761 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5762 if (Body.isInvalid())
5763 return StmtError();
5764
5765 // If nothing changed, just retain this statement.
5766 if (!getDerived().AlwaysRebuild() &&
5767 Body.get() == S->getSubStmt())
5768 return SemaRef.Owned(S);
5769
5770 // Build a new statement.
5771 return getDerived().RebuildObjCAutoreleasePoolStmt(
5772 S->getAtLoc(), Body.get());
5773}
5774
5775template<typename Derived>
5776StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005777TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005778 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005779 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005780 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005781 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005782 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005783
Douglas Gregorc3203e72010-04-22 23:10:45 +00005784 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005785 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005786 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005787 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005788
Douglas Gregorc3203e72010-04-22 23:10:45 +00005789 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005790 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005791 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005792 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005793
Douglas Gregorc3203e72010-04-22 23:10:45 +00005794 // If nothing changed, just retain this statement.
5795 if (!getDerived().AlwaysRebuild() &&
5796 Element.get() == S->getElement() &&
5797 Collection.get() == S->getCollection() &&
5798 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005799 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005800
Douglas Gregorc3203e72010-04-22 23:10:45 +00005801 // Build a new statement.
5802 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5803 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005804 Element.get(),
5805 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005806 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005807 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005808}
5809
5810
5811template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005812StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005813TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5814 // Transform the exception declaration, if any.
5815 VarDecl *Var = 0;
5816 if (S->getExceptionDecl()) {
5817 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005818 TypeSourceInfo *T = getDerived().TransformType(
5819 ExceptionDecl->getTypeSourceInfo());
5820 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005821 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005822
Douglas Gregor83cb9422010-09-09 17:09:21 +00005823 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005824 ExceptionDecl->getInnerLocStart(),
5825 ExceptionDecl->getLocation(),
5826 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005827 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005828 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005829 }
Mike Stump1eb44332009-09-09 15:08:12 +00005830
Douglas Gregor43959a92009-08-20 07:17:43 +00005831 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005832 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005833 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005834 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005835
Douglas Gregor43959a92009-08-20 07:17:43 +00005836 if (!getDerived().AlwaysRebuild() &&
5837 !Var &&
5838 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005839 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005840
5841 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5842 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005843 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005844}
Mike Stump1eb44332009-09-09 15:08:12 +00005845
Douglas Gregor43959a92009-08-20 07:17:43 +00005846template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005847StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005848TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5849 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005850 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005851 = getDerived().TransformCompoundStmt(S->getTryBlock());
5852 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005853 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005854
Douglas Gregor43959a92009-08-20 07:17:43 +00005855 // Transform the handlers.
5856 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005857 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005858 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005859 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005860 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5861 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005862 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005863
Douglas Gregor43959a92009-08-20 07:17:43 +00005864 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5865 Handlers.push_back(Handler.takeAs<Stmt>());
5866 }
Mike Stump1eb44332009-09-09 15:08:12 +00005867
Douglas Gregor43959a92009-08-20 07:17:43 +00005868 if (!getDerived().AlwaysRebuild() &&
5869 TryBlock.get() == S->getTryBlock() &&
5870 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005871 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005872
John McCall9ae2f072010-08-23 23:25:46 +00005873 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005874 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005875}
Mike Stump1eb44332009-09-09 15:08:12 +00005876
Richard Smithad762fc2011-04-14 22:09:26 +00005877template<typename Derived>
5878StmtResult
5879TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5880 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5881 if (Range.isInvalid())
5882 return StmtError();
5883
5884 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5885 if (BeginEnd.isInvalid())
5886 return StmtError();
5887
5888 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5889 if (Cond.isInvalid())
5890 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005891 if (Cond.get())
5892 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5893 if (Cond.isInvalid())
5894 return StmtError();
5895 if (Cond.get())
5896 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005897
5898 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5899 if (Inc.isInvalid())
5900 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005901 if (Inc.get())
5902 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005903
5904 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5905 if (LoopVar.isInvalid())
5906 return StmtError();
5907
5908 StmtResult NewStmt = S;
5909 if (getDerived().AlwaysRebuild() ||
5910 Range.get() != S->getRangeStmt() ||
5911 BeginEnd.get() != S->getBeginEndStmt() ||
5912 Cond.get() != S->getCond() ||
5913 Inc.get() != S->getInc() ||
5914 LoopVar.get() != S->getLoopVarStmt())
5915 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5916 S->getColonLoc(), Range.get(),
5917 BeginEnd.get(), Cond.get(),
5918 Inc.get(), LoopVar.get(),
5919 S->getRParenLoc());
5920
5921 StmtResult Body = getDerived().TransformStmt(S->getBody());
5922 if (Body.isInvalid())
5923 return StmtError();
5924
5925 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5926 // it now so we have a new statement to attach the body to.
5927 if (Body.get() != S->getBody() && NewStmt.get() == S)
5928 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5929 S->getColonLoc(), Range.get(),
5930 BeginEnd.get(), Cond.get(),
5931 Inc.get(), LoopVar.get(),
5932 S->getRParenLoc());
5933
5934 if (NewStmt.get() == S)
5935 return SemaRef.Owned(S);
5936
5937 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5938}
5939
John Wiegley28bbe4b2011-04-28 01:08:34 +00005940template<typename Derived>
5941StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005942TreeTransform<Derived>::TransformMSDependentExistsStmt(
5943 MSDependentExistsStmt *S) {
5944 // Transform the nested-name-specifier, if any.
5945 NestedNameSpecifierLoc QualifierLoc;
5946 if (S->getQualifierLoc()) {
5947 QualifierLoc
5948 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5949 if (!QualifierLoc)
5950 return StmtError();
5951 }
5952
5953 // Transform the declaration name.
5954 DeclarationNameInfo NameInfo = S->getNameInfo();
5955 if (NameInfo.getName()) {
5956 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5957 if (!NameInfo.getName())
5958 return StmtError();
5959 }
5960
5961 // Check whether anything changed.
5962 if (!getDerived().AlwaysRebuild() &&
5963 QualifierLoc == S->getQualifierLoc() &&
5964 NameInfo.getName() == S->getNameInfo().getName())
5965 return S;
5966
5967 // Determine whether this name exists, if we can.
5968 CXXScopeSpec SS;
5969 SS.Adopt(QualifierLoc);
5970 bool Dependent = false;
5971 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5972 case Sema::IER_Exists:
5973 if (S->isIfExists())
5974 break;
5975
5976 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5977
5978 case Sema::IER_DoesNotExist:
5979 if (S->isIfNotExists())
5980 break;
5981
5982 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5983
5984 case Sema::IER_Dependent:
5985 Dependent = true;
5986 break;
Douglas Gregor65019ac2011-10-25 03:44:56 +00005987
5988 case Sema::IER_Error:
5989 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005990 }
5991
5992 // We need to continue with the instantiation, so do so now.
5993 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5994 if (SubStmt.isInvalid())
5995 return StmtError();
5996
5997 // If we have resolved the name, just transform to the substatement.
5998 if (!Dependent)
5999 return SubStmt;
6000
6001 // The name is still dependent, so build a dependent expression again.
6002 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6003 S->isIfExists(),
6004 QualifierLoc,
6005 NameInfo,
6006 SubStmt.get());
6007}
6008
6009template<typename Derived>
6010StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006011TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6012 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6013 if(TryBlock.isInvalid()) return StmtError();
6014
6015 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6016 if(!getDerived().AlwaysRebuild() &&
6017 TryBlock.get() == S->getTryBlock() &&
6018 Handler.get() == S->getHandler())
6019 return SemaRef.Owned(S);
6020
6021 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6022 S->getTryLoc(),
6023 TryBlock.take(),
6024 Handler.take());
6025}
6026
6027template<typename Derived>
6028StmtResult
6029TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6030 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6031 if(Block.isInvalid()) return StmtError();
6032
6033 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6034 Block.take());
6035}
6036
6037template<typename Derived>
6038StmtResult
6039TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6040 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6041 if(FilterExpr.isInvalid()) return StmtError();
6042
6043 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6044 if(Block.isInvalid()) return StmtError();
6045
6046 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6047 FilterExpr.take(),
6048 Block.take());
6049}
6050
6051template<typename Derived>
6052StmtResult
6053TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6054 if(isa<SEHFinallyStmt>(Handler))
6055 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6056 else
6057 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6058}
6059
Douglas Gregor43959a92009-08-20 07:17:43 +00006060//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006061// Expression transformation
6062//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006063template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006064ExprResult
John McCall454feb92009-12-08 09:21:05 +00006065TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006066 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006067}
Mike Stump1eb44332009-09-09 15:08:12 +00006068
6069template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006070ExprResult
John McCall454feb92009-12-08 09:21:05 +00006071TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006072 NestedNameSpecifierLoc QualifierLoc;
6073 if (E->getQualifierLoc()) {
6074 QualifierLoc
6075 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6076 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006077 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006078 }
John McCalldbd872f2009-12-08 09:08:17 +00006079
6080 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006081 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6082 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006083 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006084 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006085
John McCallec8045d2010-08-17 21:27:17 +00006086 DeclarationNameInfo NameInfo = E->getNameInfo();
6087 if (NameInfo.getName()) {
6088 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6089 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006090 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006091 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006092
6093 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006094 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006095 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006096 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006097 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006098
6099 // Mark it referenced in the new context regardless.
6100 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006101 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006102
John McCall3fa5cae2010-10-26 07:05:15 +00006103 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006104 }
John McCalldbd872f2009-12-08 09:08:17 +00006105
6106 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006107 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006108 TemplateArgs = &TransArgs;
6109 TransArgs.setLAngleLoc(E->getLAngleLoc());
6110 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006111 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6112 E->getNumTemplateArgs(),
6113 TransArgs))
6114 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006115 }
6116
Douglas Gregor40d96a62011-02-28 21:54:11 +00006117 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
6118 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006119}
Mike Stump1eb44332009-09-09 15:08:12 +00006120
Douglas Gregorb98b1992009-08-11 05:31:07 +00006121template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006122ExprResult
John McCall454feb92009-12-08 09:21:05 +00006123TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006124 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006125}
Mike Stump1eb44332009-09-09 15:08:12 +00006126
Douglas Gregorb98b1992009-08-11 05:31:07 +00006127template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006128ExprResult
John McCall454feb92009-12-08 09:21:05 +00006129TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006130 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006131}
Mike Stump1eb44332009-09-09 15:08:12 +00006132
Douglas Gregorb98b1992009-08-11 05:31:07 +00006133template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006134ExprResult
John McCall454feb92009-12-08 09:21:05 +00006135TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006136 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006137}
Mike Stump1eb44332009-09-09 15:08:12 +00006138
Douglas Gregorb98b1992009-08-11 05:31:07 +00006139template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006140ExprResult
John McCall454feb92009-12-08 09:21:05 +00006141TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006142 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006143}
Mike Stump1eb44332009-09-09 15:08:12 +00006144
Douglas Gregorb98b1992009-08-11 05:31:07 +00006145template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006146ExprResult
John McCall454feb92009-12-08 09:21:05 +00006147TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006148 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006149}
6150
6151template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006152ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006153TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6154 return SemaRef.MaybeBindToTemporary(E);
6155}
6156
6157template<typename Derived>
6158ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006159TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6160 ExprResult ControllingExpr =
6161 getDerived().TransformExpr(E->getControllingExpr());
6162 if (ControllingExpr.isInvalid())
6163 return ExprError();
6164
Chris Lattner686775d2011-07-20 06:58:45 +00006165 SmallVector<Expr *, 4> AssocExprs;
6166 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006167 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6168 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6169 if (TS) {
6170 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6171 if (!AssocType)
6172 return ExprError();
6173 AssocTypes.push_back(AssocType);
6174 } else {
6175 AssocTypes.push_back(0);
6176 }
6177
6178 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6179 if (AssocExpr.isInvalid())
6180 return ExprError();
6181 AssocExprs.push_back(AssocExpr.release());
6182 }
6183
6184 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6185 E->getDefaultLoc(),
6186 E->getRParenLoc(),
6187 ControllingExpr.release(),
6188 AssocTypes.data(),
6189 AssocExprs.data(),
6190 E->getNumAssocs());
6191}
6192
6193template<typename Derived>
6194ExprResult
John McCall454feb92009-12-08 09:21:05 +00006195TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006196 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006197 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006198 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006199
Douglas Gregorb98b1992009-08-11 05:31:07 +00006200 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006201 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006202
John McCall9ae2f072010-08-23 23:25:46 +00006203 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006204 E->getRParen());
6205}
6206
Mike Stump1eb44332009-09-09 15:08:12 +00006207template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006208ExprResult
John McCall454feb92009-12-08 09:21:05 +00006209TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006210 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006211 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006212 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006213
Douglas Gregorb98b1992009-08-11 05:31:07 +00006214 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006215 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006216
Douglas Gregorb98b1992009-08-11 05:31:07 +00006217 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6218 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006219 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006220}
Mike Stump1eb44332009-09-09 15:08:12 +00006221
Douglas Gregorb98b1992009-08-11 05:31:07 +00006222template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006223ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006224TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6225 // Transform the type.
6226 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6227 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006228 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006229
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006230 // Transform all of the components into components similar to what the
6231 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00006232 // FIXME: It would be slightly more efficient in the non-dependent case to
6233 // just map FieldDecls, rather than requiring the rebuilder to look for
6234 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006235 // template code that we don't care.
6236 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006237 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006238 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006239 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006240 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6241 const Node &ON = E->getComponent(I);
6242 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006243 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006244 Comp.LocStart = ON.getSourceRange().getBegin();
6245 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006246 switch (ON.getKind()) {
6247 case Node::Array: {
6248 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006249 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006250 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006251 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006252
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006253 ExprChanged = ExprChanged || Index.get() != FromIndex;
6254 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006255 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006256 break;
6257 }
Sean Huntc3021132010-05-05 15:23:54 +00006258
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006259 case Node::Field:
6260 case Node::Identifier:
6261 Comp.isBrackets = false;
6262 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006263 if (!Comp.U.IdentInfo)
6264 continue;
Sean Huntc3021132010-05-05 15:23:54 +00006265
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006266 break;
Sean Huntc3021132010-05-05 15:23:54 +00006267
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006268 case Node::Base:
6269 // Will be recomputed during the rebuild.
6270 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006271 }
Sean Huntc3021132010-05-05 15:23:54 +00006272
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006273 Components.push_back(Comp);
6274 }
Sean Huntc3021132010-05-05 15:23:54 +00006275
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006276 // If nothing changed, retain the existing expression.
6277 if (!getDerived().AlwaysRebuild() &&
6278 Type == E->getTypeSourceInfo() &&
6279 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006280 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006281
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006282 // Build a new offsetof expression.
6283 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6284 Components.data(), Components.size(),
6285 E->getRParenLoc());
6286}
6287
6288template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006289ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006290TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6291 assert(getDerived().AlreadyTransformed(E->getType()) &&
6292 "opaque value expression requires transformation");
6293 return SemaRef.Owned(E);
6294}
6295
6296template<typename Derived>
6297ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006298TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006299 // Rebuild the syntactic form. The original syntactic form has
6300 // opaque-value expressions in it, so strip those away and rebuild
6301 // the result. This is a really awful way of doing this, but the
6302 // better solution (rebuilding the semantic expressions and
6303 // rebinding OVEs as necessary) doesn't work; we'd need
6304 // TreeTransform to not strip away implicit conversions.
6305 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6306 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006307 if (result.isInvalid()) return ExprError();
6308
6309 // If that gives us a pseudo-object result back, the pseudo-object
6310 // expression must have been an lvalue-to-rvalue conversion which we
6311 // should reapply.
6312 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6313 result = SemaRef.checkPseudoObjectRValue(result.take());
6314
6315 return result;
6316}
6317
6318template<typename Derived>
6319ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006320TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6321 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006322 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006323 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006324
John McCalla93c9342009-12-07 02:54:59 +00006325 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006326 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006327 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006328
John McCall5ab75172009-11-04 07:28:41 +00006329 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006330 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006331
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006332 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6333 E->getKind(),
6334 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006335 }
Mike Stump1eb44332009-09-09 15:08:12 +00006336
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006337 // C++0x [expr.sizeof]p1:
6338 // The operand is either an expression, which is an unevaluated operand
6339 // [...]
6340 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006341
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006342 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6343 if (SubExpr.isInvalid())
6344 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006345
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006346 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6347 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006348
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006349 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6350 E->getOperatorLoc(),
6351 E->getKind(),
6352 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006353}
Mike Stump1eb44332009-09-09 15:08:12 +00006354
Douglas Gregorb98b1992009-08-11 05:31:07 +00006355template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006356ExprResult
John McCall454feb92009-12-08 09:21:05 +00006357TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006358 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006359 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006360 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006361
John McCall60d7b3a2010-08-24 06:29:42 +00006362 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006363 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006364 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006365
6366
Douglas Gregorb98b1992009-08-11 05:31:07 +00006367 if (!getDerived().AlwaysRebuild() &&
6368 LHS.get() == E->getLHS() &&
6369 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006370 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006371
John McCall9ae2f072010-08-23 23:25:46 +00006372 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006373 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006374 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006375 E->getRBracketLoc());
6376}
Mike Stump1eb44332009-09-09 15:08:12 +00006377
6378template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006379ExprResult
John McCall454feb92009-12-08 09:21:05 +00006380TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006381 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006382 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006383 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006384 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006385
6386 // Transform arguments.
6387 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006388 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006389 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6390 &ArgChanged))
6391 return ExprError();
6392
Douglas Gregorb98b1992009-08-11 05:31:07 +00006393 if (!getDerived().AlwaysRebuild() &&
6394 Callee.get() == E->getCallee() &&
6395 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006396 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006397
Douglas Gregorb98b1992009-08-11 05:31:07 +00006398 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006399 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006400 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006401 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006402 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006403 E->getRParenLoc());
6404}
Mike Stump1eb44332009-09-09 15:08:12 +00006405
6406template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006407ExprResult
John McCall454feb92009-12-08 09:21:05 +00006408TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006409 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006410 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006411 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006412
Douglas Gregor40d96a62011-02-28 21:54:11 +00006413 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006414 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006415 QualifierLoc
6416 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6417
6418 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006419 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006420 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006421 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006422
Eli Friedmanf595cc42009-12-04 06:40:45 +00006423 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006424 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6425 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006426 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006427 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006428
John McCall6bb80172010-03-30 21:47:33 +00006429 NamedDecl *FoundDecl = E->getFoundDecl();
6430 if (FoundDecl == E->getMemberDecl()) {
6431 FoundDecl = Member;
6432 } else {
6433 FoundDecl = cast_or_null<NamedDecl>(
6434 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6435 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006436 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006437 }
6438
Douglas Gregorb98b1992009-08-11 05:31:07 +00006439 if (!getDerived().AlwaysRebuild() &&
6440 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006441 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006442 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006443 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006444 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006445
Anders Carlsson1f240322009-12-22 05:24:09 +00006446 // Mark it referenced in the new context regardless.
6447 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006448 SemaRef.MarkMemberReferenced(E);
6449
John McCall3fa5cae2010-10-26 07:05:15 +00006450 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006451 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006452
John McCalld5532b62009-11-23 01:53:49 +00006453 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006454 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006455 TransArgs.setLAngleLoc(E->getLAngleLoc());
6456 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006457 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6458 E->getNumTemplateArgs(),
6459 TransArgs))
6460 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006461 }
Sean Huntc3021132010-05-05 15:23:54 +00006462
Douglas Gregorb98b1992009-08-11 05:31:07 +00006463 // FIXME: Bogus source location for the operator
6464 SourceLocation FakeOperatorLoc
6465 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6466
John McCallc2233c52010-01-15 08:34:02 +00006467 // FIXME: to do this check properly, we will need to preserve the
6468 // first-qualifier-in-scope here, just in case we had a dependent
6469 // base (and therefore couldn't do the check) and a
6470 // nested-name-qualifier (and therefore could do the lookup).
6471 NamedDecl *FirstQualifierInScope = 0;
6472
John McCall9ae2f072010-08-23 23:25:46 +00006473 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006474 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006475 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006476 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006477 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006478 Member,
John McCall6bb80172010-03-30 21:47:33 +00006479 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006480 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006481 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006482 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006483}
Mike Stump1eb44332009-09-09 15:08:12 +00006484
Douglas Gregorb98b1992009-08-11 05:31:07 +00006485template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006486ExprResult
John McCall454feb92009-12-08 09:21:05 +00006487TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006488 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006489 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006490 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006491
John McCall60d7b3a2010-08-24 06:29:42 +00006492 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006493 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006494 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006495
Douglas Gregorb98b1992009-08-11 05:31:07 +00006496 if (!getDerived().AlwaysRebuild() &&
6497 LHS.get() == E->getLHS() &&
6498 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006499 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006500
Douglas Gregorb98b1992009-08-11 05:31:07 +00006501 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006502 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006503}
6504
Mike Stump1eb44332009-09-09 15:08:12 +00006505template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006506ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006507TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006508 CompoundAssignOperator *E) {
6509 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006510}
Mike Stump1eb44332009-09-09 15:08:12 +00006511
Douglas Gregorb98b1992009-08-11 05:31:07 +00006512template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006513ExprResult TreeTransform<Derived>::
6514TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6515 // Just rebuild the common and RHS expressions and see whether we
6516 // get any changes.
6517
6518 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6519 if (commonExpr.isInvalid())
6520 return ExprError();
6521
6522 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6523 if (rhs.isInvalid())
6524 return ExprError();
6525
6526 if (!getDerived().AlwaysRebuild() &&
6527 commonExpr.get() == e->getCommon() &&
6528 rhs.get() == e->getFalseExpr())
6529 return SemaRef.Owned(e);
6530
6531 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6532 e->getQuestionLoc(),
6533 0,
6534 e->getColonLoc(),
6535 rhs.get());
6536}
6537
6538template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006539ExprResult
John McCall454feb92009-12-08 09:21:05 +00006540TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006541 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006542 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006543 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006544
John McCall60d7b3a2010-08-24 06:29:42 +00006545 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006546 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006547 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006548
John McCall60d7b3a2010-08-24 06:29:42 +00006549 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006550 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006551 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006552
Douglas Gregorb98b1992009-08-11 05:31:07 +00006553 if (!getDerived().AlwaysRebuild() &&
6554 Cond.get() == E->getCond() &&
6555 LHS.get() == E->getLHS() &&
6556 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006557 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006558
John McCall9ae2f072010-08-23 23:25:46 +00006559 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006560 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006561 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006562 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006563 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006564}
Mike Stump1eb44332009-09-09 15:08:12 +00006565
6566template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006567ExprResult
John McCall454feb92009-12-08 09:21:05 +00006568TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006569 // Implicit casts are eliminated during transformation, since they
6570 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006571 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006572}
Mike Stump1eb44332009-09-09 15:08:12 +00006573
Douglas Gregorb98b1992009-08-11 05:31:07 +00006574template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006575ExprResult
John McCall454feb92009-12-08 09:21:05 +00006576TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006577 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6578 if (!Type)
6579 return ExprError();
6580
John McCall60d7b3a2010-08-24 06:29:42 +00006581 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006582 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006583 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006584 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006585
Douglas Gregorb98b1992009-08-11 05:31:07 +00006586 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006587 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006588 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006589 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006590
John McCall9d125032010-01-15 18:39:57 +00006591 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006592 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006593 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006594 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006595}
Mike Stump1eb44332009-09-09 15:08:12 +00006596
Douglas Gregorb98b1992009-08-11 05:31:07 +00006597template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006598ExprResult
John McCall454feb92009-12-08 09:21:05 +00006599TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006600 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6601 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6602 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006603 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006604
John McCall60d7b3a2010-08-24 06:29:42 +00006605 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006606 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006607 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006608
Douglas Gregorb98b1992009-08-11 05:31:07 +00006609 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006610 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006611 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006612 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006613
John McCall1d7d8d62010-01-19 22:33:45 +00006614 // Note: the expression type doesn't necessarily match the
6615 // type-as-written, but that's okay, because it should always be
6616 // derivable from the initializer.
6617
John McCall42f56b52010-01-18 19:35:47 +00006618 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006619 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006620 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621}
Mike Stump1eb44332009-09-09 15:08:12 +00006622
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006624ExprResult
John McCall454feb92009-12-08 09:21:05 +00006625TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006626 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006627 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006628 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006629
Douglas Gregorb98b1992009-08-11 05:31:07 +00006630 if (!getDerived().AlwaysRebuild() &&
6631 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006632 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006633
Douglas Gregorb98b1992009-08-11 05:31:07 +00006634 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006635 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006636 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006637 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006638 E->getAccessorLoc(),
6639 E->getAccessor());
6640}
Mike Stump1eb44332009-09-09 15:08:12 +00006641
Douglas Gregorb98b1992009-08-11 05:31:07 +00006642template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006643ExprResult
John McCall454feb92009-12-08 09:21:05 +00006644TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006645 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006646
John McCallca0408f2010-08-23 06:44:23 +00006647 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006648 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6649 Inits, &InitChanged))
6650 return ExprError();
6651
Douglas Gregorb98b1992009-08-11 05:31:07 +00006652 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006653 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006654
Douglas Gregorb98b1992009-08-11 05:31:07 +00006655 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006656 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006657}
Mike Stump1eb44332009-09-09 15:08:12 +00006658
Douglas Gregorb98b1992009-08-11 05:31:07 +00006659template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006660ExprResult
John McCall454feb92009-12-08 09:21:05 +00006661TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006662 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006663
Douglas Gregor43959a92009-08-20 07:17:43 +00006664 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006665 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006666 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006667 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006668
Douglas Gregor43959a92009-08-20 07:17:43 +00006669 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006670 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006671 bool ExprChanged = false;
6672 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6673 DEnd = E->designators_end();
6674 D != DEnd; ++D) {
6675 if (D->isFieldDesignator()) {
6676 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6677 D->getDotLoc(),
6678 D->getFieldLoc()));
6679 continue;
6680 }
Mike Stump1eb44332009-09-09 15:08:12 +00006681
Douglas Gregorb98b1992009-08-11 05:31:07 +00006682 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006683 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006684 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006685 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006686
6687 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006688 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006689
Douglas Gregorb98b1992009-08-11 05:31:07 +00006690 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6691 ArrayExprs.push_back(Index.release());
6692 continue;
6693 }
Mike Stump1eb44332009-09-09 15:08:12 +00006694
Douglas Gregorb98b1992009-08-11 05:31:07 +00006695 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006696 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006697 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6698 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006699 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006700
John McCall60d7b3a2010-08-24 06:29:42 +00006701 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006702 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006703 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006704
6705 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006706 End.get(),
6707 D->getLBracketLoc(),
6708 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006709
Douglas Gregorb98b1992009-08-11 05:31:07 +00006710 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6711 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006712
Douglas Gregorb98b1992009-08-11 05:31:07 +00006713 ArrayExprs.push_back(Start.release());
6714 ArrayExprs.push_back(End.release());
6715 }
Mike Stump1eb44332009-09-09 15:08:12 +00006716
Douglas Gregorb98b1992009-08-11 05:31:07 +00006717 if (!getDerived().AlwaysRebuild() &&
6718 Init.get() == E->getInit() &&
6719 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006720 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006721
Douglas Gregorb98b1992009-08-11 05:31:07 +00006722 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6723 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006724 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006725}
Mike Stump1eb44332009-09-09 15:08:12 +00006726
Douglas Gregorb98b1992009-08-11 05:31:07 +00006727template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006728ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006729TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006730 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006731 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006732
Douglas Gregor5557b252009-10-28 00:29:27 +00006733 // FIXME: Will we ever have proper type location here? Will we actually
6734 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006735 QualType T = getDerived().TransformType(E->getType());
6736 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006737 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006738
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739 if (!getDerived().AlwaysRebuild() &&
6740 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006741 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006742
Douglas Gregorb98b1992009-08-11 05:31:07 +00006743 return getDerived().RebuildImplicitValueInitExpr(T);
6744}
Mike Stump1eb44332009-09-09 15:08:12 +00006745
Douglas Gregorb98b1992009-08-11 05:31:07 +00006746template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006747ExprResult
John McCall454feb92009-12-08 09:21:05 +00006748TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006749 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6750 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006751 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006752
John McCall60d7b3a2010-08-24 06:29:42 +00006753 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006754 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006755 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006756
Douglas Gregorb98b1992009-08-11 05:31:07 +00006757 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006758 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006759 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006760 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006761
John McCall9ae2f072010-08-23 23:25:46 +00006762 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006763 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006764}
6765
6766template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006767ExprResult
John McCall454feb92009-12-08 09:21:05 +00006768TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006769 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006770 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006771 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6772 &ArgumentChanged))
6773 return ExprError();
6774
Douglas Gregorb98b1992009-08-11 05:31:07 +00006775 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6776 move_arg(Inits),
6777 E->getRParenLoc());
6778}
Mike Stump1eb44332009-09-09 15:08:12 +00006779
Douglas Gregorb98b1992009-08-11 05:31:07 +00006780/// \brief Transform an address-of-label expression.
6781///
6782/// By default, the transformation of an address-of-label expression always
6783/// rebuilds the expression, so that the label identifier can be resolved to
6784/// the corresponding label statement by semantic analysis.
6785template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006786ExprResult
John McCall454feb92009-12-08 09:21:05 +00006787TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006788 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6789 E->getLabel());
6790 if (!LD)
6791 return ExprError();
6792
Douglas Gregorb98b1992009-08-11 05:31:07 +00006793 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006794 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006795}
Mike Stump1eb44332009-09-09 15:08:12 +00006796
6797template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006798ExprResult
John McCall454feb92009-12-08 09:21:05 +00006799TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006800 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006801 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006802 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006803 if (SubStmt.isInvalid()) {
6804 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006805 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006806 }
Mike Stump1eb44332009-09-09 15:08:12 +00006807
Douglas Gregorb98b1992009-08-11 05:31:07 +00006808 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006809 SubStmt.get() == E->getSubStmt()) {
6810 // Calling this an 'error' is unintuitive, but it does the right thing.
6811 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006812 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006813 }
Mike Stump1eb44332009-09-09 15:08:12 +00006814
6815 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006816 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006817 E->getRParenLoc());
6818}
Mike Stump1eb44332009-09-09 15:08:12 +00006819
Douglas Gregorb98b1992009-08-11 05:31:07 +00006820template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006821ExprResult
John McCall454feb92009-12-08 09:21:05 +00006822TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006823 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006824 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006825 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006826
John McCall60d7b3a2010-08-24 06:29:42 +00006827 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006828 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006829 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006830
John McCall60d7b3a2010-08-24 06:29:42 +00006831 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006832 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006833 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006834
Douglas Gregorb98b1992009-08-11 05:31:07 +00006835 if (!getDerived().AlwaysRebuild() &&
6836 Cond.get() == E->getCond() &&
6837 LHS.get() == E->getLHS() &&
6838 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006839 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006840
Douglas Gregorb98b1992009-08-11 05:31:07 +00006841 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006842 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006843 E->getRParenLoc());
6844}
Mike Stump1eb44332009-09-09 15:08:12 +00006845
Douglas Gregorb98b1992009-08-11 05:31:07 +00006846template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006847ExprResult
John McCall454feb92009-12-08 09:21:05 +00006848TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006849 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006850}
6851
6852template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006853ExprResult
John McCall454feb92009-12-08 09:21:05 +00006854TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006855 switch (E->getOperator()) {
6856 case OO_New:
6857 case OO_Delete:
6858 case OO_Array_New:
6859 case OO_Array_Delete:
6860 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Sean Huntc3021132010-05-05 15:23:54 +00006861
Douglas Gregor668d6d92009-12-13 20:44:55 +00006862 case OO_Call: {
6863 // This is a call to an object's operator().
6864 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6865
6866 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006867 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006868 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006869 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006870
6871 // FIXME: Poor location information
6872 SourceLocation FakeLParenLoc
6873 = SemaRef.PP.getLocForEndOfToken(
6874 static_cast<Expr *>(Object.get())->getLocEnd());
6875
6876 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006877 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006878 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6879 Args))
6880 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006881
John McCall9ae2f072010-08-23 23:25:46 +00006882 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006883 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006884 E->getLocEnd());
6885 }
6886
6887#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6888 case OO_##Name:
6889#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6890#include "clang/Basic/OperatorKinds.def"
6891 case OO_Subscript:
6892 // Handled below.
6893 break;
6894
6895 case OO_Conditional:
6896 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006897
6898 case OO_None:
6899 case NUM_OVERLOADED_OPERATORS:
6900 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006901 }
6902
John McCall60d7b3a2010-08-24 06:29:42 +00006903 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006904 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006905 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006906
John McCall60d7b3a2010-08-24 06:29:42 +00006907 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006908 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006909 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006910
John McCall60d7b3a2010-08-24 06:29:42 +00006911 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006912 if (E->getNumArgs() == 2) {
6913 Second = getDerived().TransformExpr(E->getArg(1));
6914 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006915 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006916 }
Mike Stump1eb44332009-09-09 15:08:12 +00006917
Douglas Gregorb98b1992009-08-11 05:31:07 +00006918 if (!getDerived().AlwaysRebuild() &&
6919 Callee.get() == E->getCallee() &&
6920 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006921 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006922 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006923
Douglas Gregorb98b1992009-08-11 05:31:07 +00006924 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6925 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006926 Callee.get(),
6927 First.get(),
6928 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006929}
Mike Stump1eb44332009-09-09 15:08:12 +00006930
Douglas Gregorb98b1992009-08-11 05:31:07 +00006931template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006932ExprResult
John McCall454feb92009-12-08 09:21:05 +00006933TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6934 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006935}
Mike Stump1eb44332009-09-09 15:08:12 +00006936
Douglas Gregorb98b1992009-08-11 05:31:07 +00006937template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006938ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006939TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6940 // Transform the callee.
6941 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6942 if (Callee.isInvalid())
6943 return ExprError();
6944
6945 // Transform exec config.
6946 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6947 if (EC.isInvalid())
6948 return ExprError();
6949
6950 // Transform arguments.
6951 bool ArgChanged = false;
6952 ASTOwningVector<Expr*> Args(SemaRef);
6953 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6954 &ArgChanged))
6955 return ExprError();
6956
6957 if (!getDerived().AlwaysRebuild() &&
6958 Callee.get() == E->getCallee() &&
6959 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006960 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006961
6962 // FIXME: Wrong source location information for the '('.
6963 SourceLocation FakeLParenLoc
6964 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6965 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6966 move_arg(Args),
6967 E->getRParenLoc(), EC.get());
6968}
6969
6970template<typename Derived>
6971ExprResult
John McCall454feb92009-12-08 09:21:05 +00006972TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006973 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6974 if (!Type)
6975 return ExprError();
6976
John McCall60d7b3a2010-08-24 06:29:42 +00006977 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006978 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006979 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006980 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006981
Douglas Gregorb98b1992009-08-11 05:31:07 +00006982 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006983 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006984 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006985 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006986
Douglas Gregorb98b1992009-08-11 05:31:07 +00006987 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006988 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006989 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6990 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6991 SourceLocation FakeRParenLoc
6992 = SemaRef.PP.getLocForEndOfToken(
6993 E->getSubExpr()->getSourceRange().getEnd());
6994 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006995 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006996 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006997 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006998 FakeRAngleLoc,
6999 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007000 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007001 FakeRParenLoc);
7002}
Mike Stump1eb44332009-09-09 15:08:12 +00007003
Douglas Gregorb98b1992009-08-11 05:31:07 +00007004template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007005ExprResult
John McCall454feb92009-12-08 09:21:05 +00007006TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7007 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007008}
Mike Stump1eb44332009-09-09 15:08:12 +00007009
7010template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007011ExprResult
John McCall454feb92009-12-08 09:21:05 +00007012TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7013 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007014}
7015
Douglas Gregorb98b1992009-08-11 05:31:07 +00007016template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007017ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007018TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007019 CXXReinterpretCastExpr *E) {
7020 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007021}
Mike Stump1eb44332009-09-09 15:08:12 +00007022
Douglas Gregorb98b1992009-08-11 05:31:07 +00007023template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007024ExprResult
John McCall454feb92009-12-08 09:21:05 +00007025TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7026 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007027}
Mike Stump1eb44332009-09-09 15:08:12 +00007028
Douglas Gregorb98b1992009-08-11 05:31:07 +00007029template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007030ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007032 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007033 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7034 if (!Type)
7035 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007036
John McCall60d7b3a2010-08-24 06:29:42 +00007037 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007038 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007039 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007040 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007041
Douglas Gregorb98b1992009-08-11 05:31:07 +00007042 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007043 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007044 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007045 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007046
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007047 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007048 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007049 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007050 E->getRParenLoc());
7051}
Mike Stump1eb44332009-09-09 15:08:12 +00007052
Douglas Gregorb98b1992009-08-11 05:31:07 +00007053template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007054ExprResult
John McCall454feb92009-12-08 09:21:05 +00007055TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007056 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007057 TypeSourceInfo *TInfo
7058 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7059 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007060 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007061
Douglas Gregorb98b1992009-08-11 05:31:07 +00007062 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007063 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007064 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007065
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007066 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7067 E->getLocStart(),
7068 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007069 E->getLocEnd());
7070 }
Mike Stump1eb44332009-09-09 15:08:12 +00007071
Eli Friedmanef331b72012-01-20 01:26:23 +00007072 // We don't know whether the subexpression is potentially evaluated until
7073 // after we perform semantic analysis. We speculatively assume it is
7074 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007075 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00007076 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00007077
John McCall60d7b3a2010-08-24 06:29:42 +00007078 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007079 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007080 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007081
Douglas Gregorb98b1992009-08-11 05:31:07 +00007082 if (!getDerived().AlwaysRebuild() &&
7083 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007084 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007085
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007086 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7087 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007088 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007089 E->getLocEnd());
7090}
7091
7092template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007093ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007094TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7095 if (E->isTypeOperand()) {
7096 TypeSourceInfo *TInfo
7097 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7098 if (!TInfo)
7099 return ExprError();
7100
7101 if (!getDerived().AlwaysRebuild() &&
7102 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007103 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007104
Douglas Gregor3c52a212011-03-06 17:40:41 +00007105 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007106 E->getLocStart(),
7107 TInfo,
7108 E->getLocEnd());
7109 }
7110
Francois Pichet01b7c302010-09-08 12:20:18 +00007111 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7112
7113 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7114 if (SubExpr.isInvalid())
7115 return ExprError();
7116
7117 if (!getDerived().AlwaysRebuild() &&
7118 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007119 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007120
7121 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7122 E->getLocStart(),
7123 SubExpr.get(),
7124 E->getLocEnd());
7125}
7126
7127template<typename Derived>
7128ExprResult
John McCall454feb92009-12-08 09:21:05 +00007129TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007130 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007131}
Mike Stump1eb44332009-09-09 15:08:12 +00007132
Douglas Gregorb98b1992009-08-11 05:31:07 +00007133template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007134ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007135TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007136 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007137 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007138}
Mike Stump1eb44332009-09-09 15:08:12 +00007139
Douglas Gregorb98b1992009-08-11 05:31:07 +00007140template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007141ExprResult
John McCall454feb92009-12-08 09:21:05 +00007142TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007143 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007144 QualType T;
7145 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7146 T = MD->getThisType(getSema().Context);
7147 else
7148 T = getSema().Context.getPointerType(
7149 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007150
Douglas Gregorec79d872012-02-24 17:41:38 +00007151 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7152 // Make sure that we capture 'this'.
7153 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007154 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007155 }
7156
Douglas Gregor828a1972010-01-07 23:12:05 +00007157 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007158}
Mike Stump1eb44332009-09-09 15:08:12 +00007159
Douglas Gregorb98b1992009-08-11 05:31:07 +00007160template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007161ExprResult
John McCall454feb92009-12-08 09:21:05 +00007162TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007163 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007164 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007165 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007166
Douglas Gregorb98b1992009-08-11 05:31:07 +00007167 if (!getDerived().AlwaysRebuild() &&
7168 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007169 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007170
Douglas Gregorbca01b42011-07-06 22:04:06 +00007171 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7172 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007173}
Mike Stump1eb44332009-09-09 15:08:12 +00007174
Douglas Gregorb98b1992009-08-11 05:31:07 +00007175template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007176ExprResult
John McCall454feb92009-12-08 09:21:05 +00007177TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007178 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007179 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7180 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007181 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007182 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007183
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007184 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007185 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007186 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007187
Douglas Gregor036aed12009-12-23 23:03:06 +00007188 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007189}
Mike Stump1eb44332009-09-09 15:08:12 +00007190
Douglas Gregorb98b1992009-08-11 05:31:07 +00007191template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007192ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007193TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7194 CXXScalarValueInitExpr *E) {
7195 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7196 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007197 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00007198
Douglas Gregorb98b1992009-08-11 05:31:07 +00007199 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007200 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007201 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007202
Douglas Gregorab6677e2010-09-08 00:15:04 +00007203 return getDerived().RebuildCXXScalarValueInitExpr(T,
7204 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007205 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007206}
Mike Stump1eb44332009-09-09 15:08:12 +00007207
Douglas Gregorb98b1992009-08-11 05:31:07 +00007208template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007209ExprResult
John McCall454feb92009-12-08 09:21:05 +00007210TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007211 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007212 TypeSourceInfo *AllocTypeInfo
7213 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7214 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007215 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007216
Douglas Gregorb98b1992009-08-11 05:31:07 +00007217 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007218 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007219 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007220 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007221
Douglas Gregorb98b1992009-08-11 05:31:07 +00007222 // Transform the placement arguments (if any).
7223 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007224 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007225 if (getDerived().TransformExprs(E->getPlacementArgs(),
7226 E->getNumPlacementArgs(), true,
7227 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007228 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007229
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007230 // Transform the initializer (if any).
7231 Expr *OldInit = E->getInitializer();
7232 ExprResult NewInit;
7233 if (OldInit)
7234 NewInit = getDerived().TransformExpr(OldInit);
7235 if (NewInit.isInvalid())
7236 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007237
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007238 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007239 FunctionDecl *OperatorNew = 0;
7240 if (E->getOperatorNew()) {
7241 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007242 getDerived().TransformDecl(E->getLocStart(),
7243 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007244 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007245 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007246 }
7247
7248 FunctionDecl *OperatorDelete = 0;
7249 if (E->getOperatorDelete()) {
7250 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007251 getDerived().TransformDecl(E->getLocStart(),
7252 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007253 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007254 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007255 }
Sean Huntc3021132010-05-05 15:23:54 +00007256
Douglas Gregorb98b1992009-08-11 05:31:07 +00007257 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007258 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007259 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007260 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007261 OperatorNew == E->getOperatorNew() &&
7262 OperatorDelete == E->getOperatorDelete() &&
7263 !ArgumentChanged) {
7264 // Mark any declarations we need as referenced.
7265 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007266 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007267 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007268 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007269 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007270
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007271 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007272 QualType ElementType
7273 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7274 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7275 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7276 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007277 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007278 }
7279 }
7280 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007281
John McCall3fa5cae2010-10-26 07:05:15 +00007282 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007283 }
Mike Stump1eb44332009-09-09 15:08:12 +00007284
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007285 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007286 if (!ArraySize.get()) {
7287 // If no array size was specified, but the new expression was
7288 // instantiated with an array type (e.g., "new T" where T is
7289 // instantiated with "int[4]"), extract the outer bound from the
7290 // array type as our array size. We do this with constant and
7291 // dependently-sized array types.
7292 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7293 if (!ArrayT) {
7294 // Do nothing
7295 } else if (const ConstantArrayType *ConsArrayT
7296 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007297 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007298 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7299 ConsArrayT->getSize(),
7300 SemaRef.Context.getSizeType(),
7301 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007302 AllocType = ConsArrayT->getElementType();
7303 } else if (const DependentSizedArrayType *DepArrayT
7304 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7305 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007306 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007307 AllocType = DepArrayT->getElementType();
7308 }
7309 }
7310 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007311
Douglas Gregorb98b1992009-08-11 05:31:07 +00007312 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7313 E->isGlobalNew(),
7314 /*FIXME:*/E->getLocStart(),
7315 move_arg(PlacementArgs),
7316 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007317 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007318 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007319 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007320 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007321 E->getDirectInitRange(),
7322 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007323}
Mike Stump1eb44332009-09-09 15:08:12 +00007324
Douglas Gregorb98b1992009-08-11 05:31:07 +00007325template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007326ExprResult
John McCall454feb92009-12-08 09:21:05 +00007327TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007328 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007329 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007330 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007331
Douglas Gregor1af74512010-02-26 00:38:10 +00007332 // Transform the delete operator, if known.
7333 FunctionDecl *OperatorDelete = 0;
7334 if (E->getOperatorDelete()) {
7335 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007336 getDerived().TransformDecl(E->getLocStart(),
7337 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007338 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007339 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007340 }
Sean Huntc3021132010-05-05 15:23:54 +00007341
Douglas Gregorb98b1992009-08-11 05:31:07 +00007342 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007343 Operand.get() == E->getArgument() &&
7344 OperatorDelete == E->getOperatorDelete()) {
7345 // Mark any declarations we need as referenced.
7346 // FIXME: instantiation-specific.
7347 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007348 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007349
7350 if (!E->getArgument()->isTypeDependent()) {
7351 QualType Destroyed = SemaRef.Context.getBaseElementType(
7352 E->getDestroyedType());
7353 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7354 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Eli Friedman5f2987c2012-02-02 03:46:19 +00007355 SemaRef.MarkFunctionReferenced(E->getLocStart(),
7356 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007357 }
7358 }
7359
John McCall3fa5cae2010-10-26 07:05:15 +00007360 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007361 }
Mike Stump1eb44332009-09-09 15:08:12 +00007362
Douglas Gregorb98b1992009-08-11 05:31:07 +00007363 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7364 E->isGlobalDelete(),
7365 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007366 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007367}
Mike Stump1eb44332009-09-09 15:08:12 +00007368
Douglas Gregorb98b1992009-08-11 05:31:07 +00007369template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007370ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007371TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007372 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007373 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007374 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007375 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007376
John McCallb3d87482010-08-24 05:47:05 +00007377 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007378 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007379 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007380 E->getOperatorLoc(),
7381 E->isArrow()? tok::arrow : tok::period,
7382 ObjectTypePtr,
7383 MayBePseudoDestructor);
7384 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007385 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007386
John McCallb3d87482010-08-24 05:47:05 +00007387 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007388 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7389 if (QualifierLoc) {
7390 QualifierLoc
7391 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7392 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007393 return ExprError();
7394 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007395 CXXScopeSpec SS;
7396 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007397
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007398 PseudoDestructorTypeStorage Destroyed;
7399 if (E->getDestroyedTypeInfo()) {
7400 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007401 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007402 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007403 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007404 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007405 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007406 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007407 // We aren't likely to be able to resolve the identifier down to a type
7408 // now anyway, so just retain the identifier.
7409 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7410 E->getDestroyedTypeLoc());
7411 } else {
7412 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007413 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007414 *E->getDestroyedTypeIdentifier(),
7415 E->getDestroyedTypeLoc(),
7416 /*Scope=*/0,
7417 SS, ObjectTypePtr,
7418 false);
7419 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007420 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007421
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007422 Destroyed
7423 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7424 E->getDestroyedTypeLoc());
7425 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007426
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007427 TypeSourceInfo *ScopeTypeInfo = 0;
7428 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007429 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007430 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007431 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007432 }
Sean Huntc3021132010-05-05 15:23:54 +00007433
John McCall9ae2f072010-08-23 23:25:46 +00007434 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007435 E->getOperatorLoc(),
7436 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007437 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007438 ScopeTypeInfo,
7439 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007440 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007441 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007442}
Mike Stump1eb44332009-09-09 15:08:12 +00007443
Douglas Gregora71d8192009-09-04 17:36:40 +00007444template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007445ExprResult
John McCallba135432009-11-21 08:51:07 +00007446TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007447 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007448 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7449 Sema::LookupOrdinaryName);
7450
7451 // Transform all the decls.
7452 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7453 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007454 NamedDecl *InstD = static_cast<NamedDecl*>(
7455 getDerived().TransformDecl(Old->getNameLoc(),
7456 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007457 if (!InstD) {
7458 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7459 // This can happen because of dependent hiding.
7460 if (isa<UsingShadowDecl>(*I))
7461 continue;
7462 else
John McCallf312b1e2010-08-26 23:41:50 +00007463 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007464 }
John McCallf7a1a742009-11-24 19:00:30 +00007465
7466 // Expand using declarations.
7467 if (isa<UsingDecl>(InstD)) {
7468 UsingDecl *UD = cast<UsingDecl>(InstD);
7469 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7470 E = UD->shadow_end(); I != E; ++I)
7471 R.addDecl(*I);
7472 continue;
7473 }
7474
7475 R.addDecl(InstD);
7476 }
7477
7478 // Resolve a kind, but don't do any further analysis. If it's
7479 // ambiguous, the callee needs to deal with it.
7480 R.resolveKind();
7481
7482 // Rebuild the nested-name qualifier, if present.
7483 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007484 if (Old->getQualifierLoc()) {
7485 NestedNameSpecifierLoc QualifierLoc
7486 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7487 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007488 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007489
Douglas Gregor4c9be892011-02-28 20:01:57 +00007490 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007491 }
7492
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007493 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007494 CXXRecordDecl *NamingClass
7495 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7496 Old->getNameLoc(),
7497 Old->getNamingClass()));
7498 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007499 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007500
Douglas Gregor66c45152010-04-27 16:10:10 +00007501 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007502 }
7503
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007504 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7505
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007506 // If we have neither explicit template arguments, nor the template keyword,
7507 // it's a normal declaration name.
7508 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007509 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7510
7511 // If we have template arguments, rebuild them, then rebuild the
7512 // templateid expression.
7513 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007514 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7515 Old->getNumTemplateArgs(),
7516 TransArgs))
7517 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007518
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007519 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007520 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007521}
Mike Stump1eb44332009-09-09 15:08:12 +00007522
Douglas Gregorb98b1992009-08-11 05:31:07 +00007523template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007524ExprResult
John McCall454feb92009-12-08 09:21:05 +00007525TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007526 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7527 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007528 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007529
Douglas Gregorb98b1992009-08-11 05:31:07 +00007530 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007531 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007532 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007533
Mike Stump1eb44332009-09-09 15:08:12 +00007534 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007535 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007536 T,
7537 E->getLocEnd());
7538}
Mike Stump1eb44332009-09-09 15:08:12 +00007539
Douglas Gregorb98b1992009-08-11 05:31:07 +00007540template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007541ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007542TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7543 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7544 if (!LhsT)
7545 return ExprError();
7546
7547 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7548 if (!RhsT)
7549 return ExprError();
7550
7551 if (!getDerived().AlwaysRebuild() &&
7552 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7553 return SemaRef.Owned(E);
7554
7555 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7556 E->getLocStart(),
7557 LhsT, RhsT,
7558 E->getLocEnd());
7559}
7560
7561template<typename Derived>
7562ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007563TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7564 bool ArgChanged = false;
7565 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7566 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7567 TypeSourceInfo *From = E->getArg(I);
7568 TypeLoc FromTL = From->getTypeLoc();
7569 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7570 TypeLocBuilder TLB;
7571 TLB.reserve(FromTL.getFullDataSize());
7572 QualType To = getDerived().TransformType(TLB, FromTL);
7573 if (To.isNull())
7574 return ExprError();
7575
7576 if (To == From->getType())
7577 Args.push_back(From);
7578 else {
7579 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7580 ArgChanged = true;
7581 }
7582 continue;
7583 }
7584
7585 ArgChanged = true;
7586
7587 // We have a pack expansion. Instantiate it.
7588 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
7589 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7590 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7591 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
7592
7593 // Determine whether the set of unexpanded parameter packs can and should
7594 // be expanded.
7595 bool Expand = true;
7596 bool RetainExpansion = false;
7597 llvm::Optional<unsigned> OrigNumExpansions
7598 = ExpansionTL.getTypePtr()->getNumExpansions();
7599 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7600 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7601 PatternTL.getSourceRange(),
7602 Unexpanded,
7603 Expand, RetainExpansion,
7604 NumExpansions))
7605 return ExprError();
7606
7607 if (!Expand) {
7608 // The transform has determined that we should perform a simple
7609 // transformation on the pack expansion, producing another pack
7610 // expansion.
7611 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7612
7613 TypeLocBuilder TLB;
7614 TLB.reserve(From->getTypeLoc().getFullDataSize());
7615
7616 QualType To = getDerived().TransformType(TLB, PatternTL);
7617 if (To.isNull())
7618 return ExprError();
7619
7620 To = getDerived().RebuildPackExpansionType(To,
7621 PatternTL.getSourceRange(),
7622 ExpansionTL.getEllipsisLoc(),
7623 NumExpansions);
7624 if (To.isNull())
7625 return ExprError();
7626
7627 PackExpansionTypeLoc ToExpansionTL
7628 = TLB.push<PackExpansionTypeLoc>(To);
7629 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7630 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7631 continue;
7632 }
7633
7634 // Expand the pack expansion by substituting for each argument in the
7635 // pack(s).
7636 for (unsigned I = 0; I != *NumExpansions; ++I) {
7637 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7638 TypeLocBuilder TLB;
7639 TLB.reserve(PatternTL.getFullDataSize());
7640 QualType To = getDerived().TransformType(TLB, PatternTL);
7641 if (To.isNull())
7642 return ExprError();
7643
7644 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7645 }
7646
7647 if (!RetainExpansion)
7648 continue;
7649
7650 // If we're supposed to retain a pack expansion, do so by temporarily
7651 // forgetting the partially-substituted parameter pack.
7652 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7653
7654 TypeLocBuilder TLB;
7655 TLB.reserve(From->getTypeLoc().getFullDataSize());
7656
7657 QualType To = getDerived().TransformType(TLB, PatternTL);
7658 if (To.isNull())
7659 return ExprError();
7660
7661 To = getDerived().RebuildPackExpansionType(To,
7662 PatternTL.getSourceRange(),
7663 ExpansionTL.getEllipsisLoc(),
7664 NumExpansions);
7665 if (To.isNull())
7666 return ExprError();
7667
7668 PackExpansionTypeLoc ToExpansionTL
7669 = TLB.push<PackExpansionTypeLoc>(To);
7670 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7671 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7672 }
7673
7674 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7675 return SemaRef.Owned(E);
7676
7677 return getDerived().RebuildTypeTrait(E->getTrait(),
7678 E->getLocStart(),
7679 Args,
7680 E->getLocEnd());
7681}
7682
7683template<typename Derived>
7684ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007685TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7686 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7687 if (!T)
7688 return ExprError();
7689
7690 if (!getDerived().AlwaysRebuild() &&
7691 T == E->getQueriedTypeSourceInfo())
7692 return SemaRef.Owned(E);
7693
7694 ExprResult SubExpr;
7695 {
7696 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7697 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7698 if (SubExpr.isInvalid())
7699 return ExprError();
7700
7701 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7702 return SemaRef.Owned(E);
7703 }
7704
7705 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7706 E->getLocStart(),
7707 T,
7708 SubExpr.get(),
7709 E->getLocEnd());
7710}
7711
7712template<typename Derived>
7713ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007714TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7715 ExprResult SubExpr;
7716 {
7717 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7718 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7719 if (SubExpr.isInvalid())
7720 return ExprError();
7721
7722 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7723 return SemaRef.Owned(E);
7724 }
7725
7726 return getDerived().RebuildExpressionTrait(
7727 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7728}
7729
7730template<typename Derived>
7731ExprResult
John McCall865d4472009-11-19 22:55:06 +00007732TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007733 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007734 NestedNameSpecifierLoc QualifierLoc
7735 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7736 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007737 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007738 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007739
John McCall43fed0d2010-11-12 08:19:04 +00007740 // TODO: If this is a conversion-function-id, verify that the
7741 // destination type name (if present) resolves the same way after
7742 // instantiation as it did in the local scope.
7743
Abramo Bagnara25777432010-08-11 22:01:17 +00007744 DeclarationNameInfo NameInfo
7745 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7746 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007747 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007748
John McCallf7a1a742009-11-24 19:00:30 +00007749 if (!E->hasExplicitTemplateArgs()) {
7750 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007751 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007752 // Note: it is sufficient to compare the Name component of NameInfo:
7753 // if name has not changed, DNLoc has not changed either.
7754 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007755 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007756
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007757 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007758 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007759 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007760 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007761 }
John McCalld5532b62009-11-23 01:53:49 +00007762
7763 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007764 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7765 E->getNumTemplateArgs(),
7766 TransArgs))
7767 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007768
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007769 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007770 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007771 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007772 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007773}
7774
7775template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007776ExprResult
John McCall454feb92009-12-08 09:21:05 +00007777TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007778 // CXXConstructExprs are always implicit, so when we have a
7779 // 1-argument construction we just transform that argument.
7780 if (E->getNumArgs() == 1 ||
7781 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7782 return getDerived().TransformExpr(E->getArg(0));
7783
Douglas Gregorb98b1992009-08-11 05:31:07 +00007784 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7785
7786 QualType T = getDerived().TransformType(E->getType());
7787 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007788 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007789
7790 CXXConstructorDecl *Constructor
7791 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007792 getDerived().TransformDecl(E->getLocStart(),
7793 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007794 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007795 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007796
Douglas Gregorb98b1992009-08-11 05:31:07 +00007797 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007798 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007799 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7800 &ArgumentChanged))
7801 return ExprError();
7802
Douglas Gregorb98b1992009-08-11 05:31:07 +00007803 if (!getDerived().AlwaysRebuild() &&
7804 T == E->getType() &&
7805 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007806 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007807 // Mark the constructor as referenced.
7808 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007809 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007810 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007811 }
Mike Stump1eb44332009-09-09 15:08:12 +00007812
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007813 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7814 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007815 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007816 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007817 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007818 E->getConstructionKind(),
7819 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007820}
Mike Stump1eb44332009-09-09 15:08:12 +00007821
Douglas Gregorb98b1992009-08-11 05:31:07 +00007822/// \brief Transform a C++ temporary-binding expression.
7823///
Douglas Gregor51326552009-12-24 18:51:59 +00007824/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7825/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007826template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007827ExprResult
John McCall454feb92009-12-08 09:21:05 +00007828TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007829 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007830}
Mike Stump1eb44332009-09-09 15:08:12 +00007831
John McCall4765fa02010-12-06 08:20:24 +00007832/// \brief Transform a C++ expression that contains cleanups that should
7833/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007834///
John McCall4765fa02010-12-06 08:20:24 +00007835/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007836/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007837template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007838ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007839TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007840 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007841}
Mike Stump1eb44332009-09-09 15:08:12 +00007842
Douglas Gregorb98b1992009-08-11 05:31:07 +00007843template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007844ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007845TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007846 CXXTemporaryObjectExpr *E) {
7847 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7848 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007849 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007850
Douglas Gregorb98b1992009-08-11 05:31:07 +00007851 CXXConstructorDecl *Constructor
7852 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007853 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007854 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007855 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007856 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007857
Douglas Gregorb98b1992009-08-11 05:31:07 +00007858 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007859 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007860 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007861 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7862 &ArgumentChanged))
7863 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007864
Douglas Gregorb98b1992009-08-11 05:31:07 +00007865 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007866 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007867 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007868 !ArgumentChanged) {
7869 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007870 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007871 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007872 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007873
7874 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7875 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007876 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007877 E->getLocEnd());
7878}
Mike Stump1eb44332009-09-09 15:08:12 +00007879
Douglas Gregorb98b1992009-08-11 05:31:07 +00007880template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007881ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007882TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007883 // Create the local class that will describe the lambda.
7884 CXXRecordDecl *Class
Douglas Gregorf54486a2012-04-04 17:40:10 +00007885 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7886 /*KnownDependent=*/false);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007887 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7888
7889 // Transform the type of the lambda parameters and start the definition of
7890 // the lambda itself.
7891 TypeSourceInfo *MethodTy
7892 = TransformType(E->getCallOperator()->getTypeSourceInfo());
7893 if (!MethodTy)
7894 return ExprError();
7895
Douglas Gregorc6889e72012-02-14 22:28:59 +00007896 // Transform lambda parameters.
7897 bool Invalid = false;
7898 llvm::SmallVector<QualType, 4> ParamTypes;
7899 llvm::SmallVector<ParmVarDecl *, 4> Params;
7900 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7901 E->getCallOperator()->param_begin(),
7902 E->getCallOperator()->param_size(),
7903 0, ParamTypes, &Params))
7904 Invalid = true;
7905
Douglas Gregordfca6f52012-02-13 22:00:16 +00007906 // Build the call operator.
Douglas Gregorf54486a2012-04-04 17:40:10 +00007907 // Note: Once a lambda mangling number and context declaration have been
7908 // assigned, they never change.
7909 unsigned ManglingNumber = E->getLambdaClass()->getLambdaManglingNumber();
7910 Decl *ContextDecl = E->getLambdaClass()->getLambdaContextDecl();
Douglas Gregordfca6f52012-02-13 22:00:16 +00007911 CXXMethodDecl *CallOperator
7912 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
7913 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007914 E->getCallOperator()->getLocEnd(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00007915 Params, ManglingNumber, ContextDecl);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007916 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
7917
Douglas Gregord5387e82012-02-14 00:00:48 +00007918 // FIXME: Instantiation-specific.
7919 CallOperator->setInstantiationOfMemberFunction(E->getCallOperator(),
7920 TSK_ImplicitInstantiation);
7921
7922 // Introduce the context of the call operator.
7923 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7924
Douglas Gregordfca6f52012-02-13 22:00:16 +00007925 // Enter the scope of the lambda.
7926 sema::LambdaScopeInfo *LSI
7927 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7928 E->getCaptureDefault(),
7929 E->hasExplicitParameters(),
7930 E->hasExplicitResultType(),
7931 E->isMutable());
7932
7933 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00007934 bool FinishedExplicitCaptures = false;
7935 for (LambdaExpr::capture_iterator C = E->capture_begin(),
7936 CEnd = E->capture_end();
7937 C != CEnd; ++C) {
7938 // When we hit the first implicit capture, tell Sema that we've finished
7939 // the list of explicit captures.
7940 if (!FinishedExplicitCaptures && C->isImplicit()) {
7941 getSema().finishLambdaExplicitCaptures(LSI);
7942 FinishedExplicitCaptures = true;
7943 }
7944
7945 // Capturing 'this' is trivial.
7946 if (C->capturesThis()) {
7947 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7948 continue;
7949 }
7950
Douglas Gregora7365242012-02-14 19:27:52 +00007951 // Determine the capture kind for Sema.
7952 Sema::TryCaptureKind Kind
7953 = C->isImplicit()? Sema::TryCapture_Implicit
7954 : C->getCaptureKind() == LCK_ByCopy
7955 ? Sema::TryCapture_ExplicitByVal
7956 : Sema::TryCapture_ExplicitByRef;
7957 SourceLocation EllipsisLoc;
7958 if (C->isPackExpansion()) {
7959 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7960 bool ShouldExpand = false;
7961 bool RetainExpansion = false;
7962 llvm::Optional<unsigned> NumExpansions;
7963 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7964 C->getLocation(),
7965 Unexpanded,
7966 ShouldExpand, RetainExpansion,
7967 NumExpansions))
7968 return ExprError();
7969
7970 if (ShouldExpand) {
7971 // The transform has determined that we should perform an expansion;
7972 // transform and capture each of the arguments.
7973 // expansion of the pattern. Do so.
7974 VarDecl *Pack = C->getCapturedVar();
7975 for (unsigned I = 0; I != *NumExpansions; ++I) {
7976 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7977 VarDecl *CapturedVar
7978 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7979 Pack));
7980 if (!CapturedVar) {
7981 Invalid = true;
7982 continue;
7983 }
7984
7985 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007986 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregora7365242012-02-14 19:27:52 +00007987 }
7988 continue;
7989 }
7990
7991 EllipsisLoc = C->getEllipsisLoc();
7992 }
7993
Douglas Gregordfca6f52012-02-13 22:00:16 +00007994 // Transform the captured variable.
7995 VarDecl *CapturedVar
7996 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7997 C->getCapturedVar()));
7998 if (!CapturedVar) {
7999 Invalid = true;
8000 continue;
8001 }
Douglas Gregora7365242012-02-14 19:27:52 +00008002
Douglas Gregordfca6f52012-02-13 22:00:16 +00008003 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008004 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008005 }
8006 if (!FinishedExplicitCaptures)
8007 getSema().finishLambdaExplicitCaptures(LSI);
8008
Douglas Gregordfca6f52012-02-13 22:00:16 +00008009
8010 // Enter a new evaluation context to insulate the lambda from any
8011 // cleanups from the enclosing full-expression.
8012 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
8013
8014 if (Invalid) {
8015 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
8016 /*IsInstantiation=*/true);
8017 return ExprError();
8018 }
8019
8020 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008021 StmtResult Body = getDerived().TransformStmt(E->getBody());
8022 if (Body.isInvalid()) {
8023 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
8024 /*IsInstantiation=*/true);
8025 return ExprError();
8026 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008027
Douglas Gregordfca6f52012-02-13 22:00:16 +00008028 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008029 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008030}
8031
8032template<typename Derived>
8033ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008034TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008035 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008036 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8037 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008038 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008039
Douglas Gregorb98b1992009-08-11 05:31:07 +00008040 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008041 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008042 Args.reserve(E->arg_size());
8043 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
8044 &ArgumentChanged))
8045 return ExprError();
8046
Douglas Gregorb98b1992009-08-11 05:31:07 +00008047 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008048 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008049 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008050 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008051
Douglas Gregorb98b1992009-08-11 05:31:07 +00008052 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008053 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008054 E->getLParenLoc(),
8055 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00008056 E->getRParenLoc());
8057}
Mike Stump1eb44332009-09-09 15:08:12 +00008058
Douglas Gregorb98b1992009-08-11 05:31:07 +00008059template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008060ExprResult
John McCall865d4472009-11-19 22:55:06 +00008061TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008062 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008063 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008064 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008065 Expr *OldBase;
8066 QualType BaseType;
8067 QualType ObjectType;
8068 if (!E->isImplicitAccess()) {
8069 OldBase = E->getBase();
8070 Base = getDerived().TransformExpr(OldBase);
8071 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008072 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008073
John McCallaa81e162009-12-01 22:10:20 +00008074 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008075 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008076 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008077 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008078 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008079 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008080 ObjectTy,
8081 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008082 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008083 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008084
John McCallb3d87482010-08-24 05:47:05 +00008085 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008086 BaseType = ((Expr*) Base.get())->getType();
8087 } else {
8088 OldBase = 0;
8089 BaseType = getDerived().TransformType(E->getBaseType());
8090 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8091 }
Mike Stump1eb44332009-09-09 15:08:12 +00008092
Douglas Gregor6cd21982009-10-20 05:58:46 +00008093 // Transform the first part of the nested-name-specifier that qualifies
8094 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008095 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008096 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008097 E->getFirstQualifierFoundInScope(),
8098 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008099
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008100 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008101 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008102 QualifierLoc
8103 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8104 ObjectType,
8105 FirstQualifierInScope);
8106 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008107 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008108 }
Mike Stump1eb44332009-09-09 15:08:12 +00008109
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008110 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8111
John McCall43fed0d2010-11-12 08:19:04 +00008112 // TODO: If this is a conversion-function-id, verify that the
8113 // destination type name (if present) resolves the same way after
8114 // instantiation as it did in the local scope.
8115
Abramo Bagnara25777432010-08-11 22:01:17 +00008116 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008117 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008118 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008119 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008120
John McCallaa81e162009-12-01 22:10:20 +00008121 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008122 // This is a reference to a member without an explicitly-specified
8123 // template argument list. Optimize for this common case.
8124 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008125 Base.get() == OldBase &&
8126 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008127 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008128 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008129 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008130 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008131
John McCall9ae2f072010-08-23 23:25:46 +00008132 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008133 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008134 E->isArrow(),
8135 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008136 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008137 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008138 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008139 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008140 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008141 }
8142
John McCalld5532b62009-11-23 01:53:49 +00008143 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008144 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8145 E->getNumTemplateArgs(),
8146 TransArgs))
8147 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008148
John McCall9ae2f072010-08-23 23:25:46 +00008149 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008150 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008151 E->isArrow(),
8152 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008153 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008154 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008155 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008156 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008157 &TransArgs);
8158}
8159
8160template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008161ExprResult
John McCall454feb92009-12-08 09:21:05 +00008162TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008163 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008164 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008165 QualType BaseType;
8166 if (!Old->isImplicitAccess()) {
8167 Base = getDerived().TransformExpr(Old->getBase());
8168 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008169 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008170 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8171 Old->isArrow());
8172 if (Base.isInvalid())
8173 return ExprError();
8174 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008175 } else {
8176 BaseType = getDerived().TransformType(Old->getBaseType());
8177 }
John McCall129e2df2009-11-30 22:42:35 +00008178
Douglas Gregor4c9be892011-02-28 20:01:57 +00008179 NestedNameSpecifierLoc QualifierLoc;
8180 if (Old->getQualifierLoc()) {
8181 QualifierLoc
8182 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8183 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008184 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008185 }
8186
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008187 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8188
Abramo Bagnara25777432010-08-11 22:01:17 +00008189 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008190 Sema::LookupOrdinaryName);
8191
8192 // Transform all the decls.
8193 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8194 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008195 NamedDecl *InstD = static_cast<NamedDecl*>(
8196 getDerived().TransformDecl(Old->getMemberLoc(),
8197 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008198 if (!InstD) {
8199 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8200 // This can happen because of dependent hiding.
8201 if (isa<UsingShadowDecl>(*I))
8202 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008203 else {
8204 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008205 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008206 }
John McCall9f54ad42009-12-10 09:41:52 +00008207 }
John McCall129e2df2009-11-30 22:42:35 +00008208
8209 // Expand using declarations.
8210 if (isa<UsingDecl>(InstD)) {
8211 UsingDecl *UD = cast<UsingDecl>(InstD);
8212 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8213 E = UD->shadow_end(); I != E; ++I)
8214 R.addDecl(*I);
8215 continue;
8216 }
8217
8218 R.addDecl(InstD);
8219 }
8220
8221 R.resolveKind();
8222
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008223 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008224 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00008225 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008226 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008227 Old->getMemberLoc(),
8228 Old->getNamingClass()));
8229 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008230 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008231
Douglas Gregor66c45152010-04-27 16:10:10 +00008232 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008233 }
Sean Huntc3021132010-05-05 15:23:54 +00008234
John McCall129e2df2009-11-30 22:42:35 +00008235 TemplateArgumentListInfo TransArgs;
8236 if (Old->hasExplicitTemplateArgs()) {
8237 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8238 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008239 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8240 Old->getNumTemplateArgs(),
8241 TransArgs))
8242 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008243 }
John McCallc2233c52010-01-15 08:34:02 +00008244
8245 // FIXME: to do this check properly, we will need to preserve the
8246 // first-qualifier-in-scope here, just in case we had a dependent
8247 // base (and therefore couldn't do the check) and a
8248 // nested-name-qualifier (and therefore could do the lookup).
8249 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00008250
John McCall9ae2f072010-08-23 23:25:46 +00008251 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008252 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008253 Old->getOperatorLoc(),
8254 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008255 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008256 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008257 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008258 R,
8259 (Old->hasExplicitTemplateArgs()
8260 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008261}
8262
8263template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008264ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008265TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008266 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008267 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8268 if (SubExpr.isInvalid())
8269 return ExprError();
8270
8271 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008272 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008273
8274 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8275}
8276
8277template<typename Derived>
8278ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008279TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008280 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8281 if (Pattern.isInvalid())
8282 return ExprError();
8283
8284 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8285 return SemaRef.Owned(E);
8286
Douglas Gregor67fd1252011-01-14 21:20:45 +00008287 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8288 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008289}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008290
8291template<typename Derived>
8292ExprResult
8293TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8294 // If E is not value-dependent, then nothing will change when we transform it.
8295 // Note: This is an instantiation-centric view.
8296 if (!E->isValueDependent())
8297 return SemaRef.Owned(E);
8298
8299 // Note: None of the implementations of TryExpandParameterPacks can ever
8300 // produce a diagnostic when given only a single unexpanded parameter pack,
8301 // so
8302 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8303 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008304 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008305 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00008306 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008307 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008308 ShouldExpand, RetainExpansion,
8309 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008310 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00008311
Douglas Gregor089e8932011-10-10 18:59:29 +00008312 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008313 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00008314
8315 NamedDecl *Pack = E->getPack();
8316 if (!ShouldExpand) {
8317 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
8318 Pack));
8319 if (!Pack)
8320 return ExprError();
8321 }
8322
Douglas Gregoree8aff02011-01-04 17:33:58 +00008323
8324 // We now know the length of the parameter pack, so build a new expression
8325 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00008326 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00008327 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008328 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008329}
8330
Douglas Gregorbe230c32011-01-03 17:17:50 +00008331template<typename Derived>
8332ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008333TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8334 SubstNonTypeTemplateParmPackExpr *E) {
8335 // Default behavior is to do nothing with this transformation.
8336 return SemaRef.Owned(E);
8337}
8338
8339template<typename Derived>
8340ExprResult
John McCall91a57552011-07-15 05:09:51 +00008341TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8342 SubstNonTypeTemplateParmExpr *E) {
8343 // Default behavior is to do nothing with this transformation.
8344 return SemaRef.Owned(E);
8345}
8346
8347template<typename Derived>
8348ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008349TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8350 MaterializeTemporaryExpr *E) {
8351 return getDerived().TransformExpr(E->GetTemporaryExpr());
8352}
8353
8354template<typename Derived>
8355ExprResult
John McCall454feb92009-12-08 09:21:05 +00008356TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008357 return SemaRef.MaybeBindToTemporary(E);
8358}
8359
8360template<typename Derived>
8361ExprResult
8362TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008363 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008364}
8365
8366template<typename Derived>
8367ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008368TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8369 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8370 if (SubExpr.isInvalid())
8371 return ExprError();
8372
8373 if (!getDerived().AlwaysRebuild() &&
8374 SubExpr.get() == E->getSubExpr())
8375 return SemaRef.Owned(E);
8376
8377 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008378}
8379
8380template<typename Derived>
8381ExprResult
8382TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8383 // Transform each of the elements.
8384 llvm::SmallVector<Expr *, 8> Elements;
8385 bool ArgChanged = false;
8386 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
8387 /*IsCall=*/false, Elements, &ArgChanged))
8388 return ExprError();
8389
8390 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8391 return SemaRef.MaybeBindToTemporary(E);
8392
8393 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8394 Elements.data(),
8395 Elements.size());
8396}
8397
8398template<typename Derived>
8399ExprResult
8400TreeTransform<Derived>::TransformObjCDictionaryLiteral(
8401 ObjCDictionaryLiteral *E) {
8402 // Transform each of the elements.
8403 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8404 bool ArgChanged = false;
8405 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8406 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
8407
8408 if (OrigElement.isPackExpansion()) {
8409 // This key/value element is a pack expansion.
8410 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8411 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8412 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8413 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8414
8415 // Determine whether the set of unexpanded parameter packs can
8416 // and should be expanded.
8417 bool Expand = true;
8418 bool RetainExpansion = false;
8419 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8420 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8421 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8422 OrigElement.Value->getLocEnd());
8423 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8424 PatternRange,
8425 Unexpanded,
8426 Expand, RetainExpansion,
8427 NumExpansions))
8428 return ExprError();
8429
8430 if (!Expand) {
8431 // The transform has determined that we should perform a simple
8432 // transformation on the pack expansion, producing another pack
8433 // expansion.
8434 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8435 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8436 if (Key.isInvalid())
8437 return ExprError();
8438
8439 if (Key.get() != OrigElement.Key)
8440 ArgChanged = true;
8441
8442 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8443 if (Value.isInvalid())
8444 return ExprError();
8445
8446 if (Value.get() != OrigElement.Value)
8447 ArgChanged = true;
8448
8449 ObjCDictionaryElement Expansion = {
8450 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8451 };
8452 Elements.push_back(Expansion);
8453 continue;
8454 }
8455
8456 // Record right away that the argument was changed. This needs
8457 // to happen even if the array expands to nothing.
8458 ArgChanged = true;
8459
8460 // The transform has determined that we should perform an elementwise
8461 // expansion of the pattern. Do so.
8462 for (unsigned I = 0; I != *NumExpansions; ++I) {
8463 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8464 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8465 if (Key.isInvalid())
8466 return ExprError();
8467
8468 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8469 if (Value.isInvalid())
8470 return ExprError();
8471
8472 ObjCDictionaryElement Element = {
8473 Key.get(), Value.get(), SourceLocation(), NumExpansions
8474 };
8475
8476 // If any unexpanded parameter packs remain, we still have a
8477 // pack expansion.
8478 if (Key.get()->containsUnexpandedParameterPack() ||
8479 Value.get()->containsUnexpandedParameterPack())
8480 Element.EllipsisLoc = OrigElement.EllipsisLoc;
8481
8482 Elements.push_back(Element);
8483 }
8484
8485 // We've finished with this pack expansion.
8486 continue;
8487 }
8488
8489 // Transform and check key.
8490 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8491 if (Key.isInvalid())
8492 return ExprError();
8493
8494 if (Key.get() != OrigElement.Key)
8495 ArgChanged = true;
8496
8497 // Transform and check value.
8498 ExprResult Value
8499 = getDerived().TransformExpr(OrigElement.Value);
8500 if (Value.isInvalid())
8501 return ExprError();
8502
8503 if (Value.get() != OrigElement.Value)
8504 ArgChanged = true;
8505
8506 ObjCDictionaryElement Element = {
8507 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8508 };
8509 Elements.push_back(Element);
8510 }
8511
8512 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8513 return SemaRef.MaybeBindToTemporary(E);
8514
8515 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8516 Elements.data(),
8517 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008518}
8519
Mike Stump1eb44332009-09-09 15:08:12 +00008520template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008521ExprResult
John McCall454feb92009-12-08 09:21:05 +00008522TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008523 TypeSourceInfo *EncodedTypeInfo
8524 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8525 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008526 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008527
Douglas Gregorb98b1992009-08-11 05:31:07 +00008528 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008529 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008530 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008531
8532 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008533 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008534 E->getRParenLoc());
8535}
Mike Stump1eb44332009-09-09 15:08:12 +00008536
Douglas Gregorb98b1992009-08-11 05:31:07 +00008537template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008538ExprResult TreeTransform<Derived>::
8539TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8540 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8541 if (result.isInvalid()) return ExprError();
8542 Expr *subExpr = result.take();
8543
8544 if (!getDerived().AlwaysRebuild() &&
8545 subExpr == E->getSubExpr())
8546 return SemaRef.Owned(E);
8547
8548 return SemaRef.Owned(new(SemaRef.Context)
8549 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8550}
8551
8552template<typename Derived>
8553ExprResult TreeTransform<Derived>::
8554TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
8555 TypeSourceInfo *TSInfo
8556 = getDerived().TransformType(E->getTypeInfoAsWritten());
8557 if (!TSInfo)
8558 return ExprError();
8559
8560 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
8561 if (Result.isInvalid())
8562 return ExprError();
8563
8564 if (!getDerived().AlwaysRebuild() &&
8565 TSInfo == E->getTypeInfoAsWritten() &&
8566 Result.get() == E->getSubExpr())
8567 return SemaRef.Owned(E);
8568
8569 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
8570 E->getBridgeKeywordLoc(), TSInfo,
8571 Result.get());
8572}
8573
8574template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008575ExprResult
John McCall454feb92009-12-08 09:21:05 +00008576TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008577 // Transform arguments.
8578 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008579 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008580 Args.reserve(E->getNumArgs());
8581 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
8582 &ArgChanged))
8583 return ExprError();
8584
Douglas Gregor92e986e2010-04-22 16:44:27 +00008585 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8586 // Class message: transform the receiver type.
8587 TypeSourceInfo *ReceiverTypeInfo
8588 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8589 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008590 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008591
Douglas Gregor92e986e2010-04-22 16:44:27 +00008592 // If nothing changed, just retain the existing message send.
8593 if (!getDerived().AlwaysRebuild() &&
8594 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008595 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008596
8597 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008598 SmallVector<SourceLocation, 16> SelLocs;
8599 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008600 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8601 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008602 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008603 E->getMethodDecl(),
8604 E->getLeftLoc(),
8605 move_arg(Args),
8606 E->getRightLoc());
8607 }
8608
8609 // Instance message: transform the receiver
8610 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8611 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008612 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008613 = getDerived().TransformExpr(E->getInstanceReceiver());
8614 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008615 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008616
8617 // If nothing changed, just retain the existing message send.
8618 if (!getDerived().AlwaysRebuild() &&
8619 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008620 return SemaRef.MaybeBindToTemporary(E);
Sean Huntc3021132010-05-05 15:23:54 +00008621
Douglas Gregor92e986e2010-04-22 16:44:27 +00008622 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008623 SmallVector<SourceLocation, 16> SelLocs;
8624 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008625 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008626 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008627 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008628 E->getMethodDecl(),
8629 E->getLeftLoc(),
8630 move_arg(Args),
8631 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008632}
8633
Mike Stump1eb44332009-09-09 15:08:12 +00008634template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008635ExprResult
John McCall454feb92009-12-08 09:21:05 +00008636TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008637 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008638}
8639
Mike Stump1eb44332009-09-09 15:08:12 +00008640template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008641ExprResult
John McCall454feb92009-12-08 09:21:05 +00008642TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008643 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008644}
8645
Mike Stump1eb44332009-09-09 15:08:12 +00008646template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008647ExprResult
John McCall454feb92009-12-08 09:21:05 +00008648TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008649 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008650 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008651 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008652 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008653
8654 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008655
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008656 // If nothing changed, just retain the existing expression.
8657 if (!getDerived().AlwaysRebuild() &&
8658 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008659 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008660
John McCall9ae2f072010-08-23 23:25:46 +00008661 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008662 E->getLocation(),
8663 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008664}
8665
Mike Stump1eb44332009-09-09 15:08:12 +00008666template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008667ExprResult
John McCall454feb92009-12-08 09:21:05 +00008668TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008669 // 'super' and types never change. Property never changes. Just
8670 // retain the existing expression.
8671 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008672 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00008673
Douglas Gregore3303542010-04-26 20:47:02 +00008674 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008675 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008676 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008677 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008678
Douglas Gregore3303542010-04-26 20:47:02 +00008679 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008680
Douglas Gregore3303542010-04-26 20:47:02 +00008681 // If nothing changed, just retain the existing expression.
8682 if (!getDerived().AlwaysRebuild() &&
8683 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008684 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008685
John McCall12f78a62010-12-02 01:19:52 +00008686 if (E->isExplicitProperty())
8687 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8688 E->getExplicitProperty(),
8689 E->getLocation());
8690
8691 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008692 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008693 E->getImplicitPropertyGetter(),
8694 E->getImplicitPropertySetter(),
8695 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008696}
8697
Mike Stump1eb44332009-09-09 15:08:12 +00008698template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008699ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008700TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8701 // Transform the base expression.
8702 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8703 if (Base.isInvalid())
8704 return ExprError();
8705
8706 // Transform the key expression.
8707 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8708 if (Key.isInvalid())
8709 return ExprError();
8710
8711 // If nothing changed, just retain the existing expression.
8712 if (!getDerived().AlwaysRebuild() &&
8713 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8714 return SemaRef.Owned(E);
8715
8716 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
8717 Base.get(), Key.get(),
8718 E->getAtIndexMethodDecl(),
8719 E->setAtIndexMethodDecl());
8720}
8721
8722template<typename Derived>
8723ExprResult
John McCall454feb92009-12-08 09:21:05 +00008724TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008725 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008726 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008727 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008728 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008729
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008730 // If nothing changed, just retain the existing expression.
8731 if (!getDerived().AlwaysRebuild() &&
8732 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008733 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008734
John McCall9ae2f072010-08-23 23:25:46 +00008735 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008736 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008737}
8738
Mike Stump1eb44332009-09-09 15:08:12 +00008739template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008740ExprResult
John McCall454feb92009-12-08 09:21:05 +00008741TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008742 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008743 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008744 SubExprs.reserve(E->getNumSubExprs());
8745 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8746 SubExprs, &ArgumentChanged))
8747 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008748
Douglas Gregorb98b1992009-08-11 05:31:07 +00008749 if (!getDerived().AlwaysRebuild() &&
8750 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008751 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008752
Douglas Gregorb98b1992009-08-11 05:31:07 +00008753 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8754 move_arg(SubExprs),
8755 E->getRParenLoc());
8756}
8757
Mike Stump1eb44332009-09-09 15:08:12 +00008758template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008759ExprResult
John McCall454feb92009-12-08 09:21:05 +00008760TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008761 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008762
John McCallc6ac9c32011-02-04 18:33:18 +00008763 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8764 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8765
8766 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008767 blockScope->TheDecl->setBlockMissingReturnType(
8768 oldBlock->blockMissingReturnType());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008769
Chris Lattner686775d2011-07-20 06:58:45 +00008770 SmallVector<ParmVarDecl*, 4> params;
8771 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008772
8773 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008774 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8775 oldBlock->param_begin(),
8776 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008777 0, paramTypes, &params)) {
8778 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008779 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008780 }
John McCallc6ac9c32011-02-04 18:33:18 +00008781
8782 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008783 QualType exprResultType =
8784 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008785
8786 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008787 if (exprResultType->isObjCObjectType()) {
John McCallc6ac9c32011-02-04 18:33:18 +00008788 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008789 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008790 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008791 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008792 return ExprError();
8793 }
John McCall711c52b2011-01-05 12:14:39 +00008794
John McCallc6ac9c32011-02-04 18:33:18 +00008795 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008796 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008797 paramTypes.data(),
8798 paramTypes.size(),
8799 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008800 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008801 exprFunctionType->getExtInfo());
8802 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008803
8804 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008805 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008806 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008807
8808 if (!oldBlock->blockMissingReturnType()) {
8809 blockScope->HasImplicitReturnType = false;
8810 blockScope->ReturnType = exprResultType;
8811 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008812
John McCall711c52b2011-01-05 12:14:39 +00008813 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008814 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008815 if (body.isInvalid()) {
8816 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008817 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008818 }
John McCall711c52b2011-01-05 12:14:39 +00008819
John McCallc6ac9c32011-02-04 18:33:18 +00008820#ifndef NDEBUG
8821 // In builds with assertions, make sure that we captured everything we
8822 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008823 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8824 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8825 e = oldBlock->capture_end(); i != e; ++i) {
8826 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008827
Douglas Gregorfc921372011-05-20 15:32:55 +00008828 // Ignore parameter packs.
8829 if (isa<ParmVarDecl>(oldCapture) &&
8830 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8831 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008832
Douglas Gregorfc921372011-05-20 15:32:55 +00008833 VarDecl *newCapture =
8834 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8835 oldCapture));
8836 assert(blockScope->CaptureMap.count(newCapture));
8837 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008838 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008839 }
8840#endif
8841
8842 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8843 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008844}
8845
Mike Stump1eb44332009-09-09 15:08:12 +00008846template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008847ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008848TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008849 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008850}
Eli Friedman276b0612011-10-11 02:20:01 +00008851
8852template<typename Derived>
8853ExprResult
8854TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008855 QualType RetTy = getDerived().TransformType(E->getType());
8856 bool ArgumentChanged = false;
8857 ASTOwningVector<Expr*> SubExprs(SemaRef);
8858 SubExprs.reserve(E->getNumSubExprs());
8859 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8860 SubExprs, &ArgumentChanged))
8861 return ExprError();
8862
8863 if (!getDerived().AlwaysRebuild() &&
8864 !ArgumentChanged)
8865 return SemaRef.Owned(E);
8866
8867 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8868 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008869}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008870
Douglas Gregorb98b1992009-08-11 05:31:07 +00008871//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008872// Type reconstruction
8873//===----------------------------------------------------------------------===//
8874
Mike Stump1eb44332009-09-09 15:08:12 +00008875template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008876QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8877 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008878 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008879 getDerived().getBaseEntity());
8880}
8881
Mike Stump1eb44332009-09-09 15:08:12 +00008882template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008883QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8884 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008885 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008886 getDerived().getBaseEntity());
8887}
8888
Mike Stump1eb44332009-09-09 15:08:12 +00008889template<typename Derived>
8890QualType
John McCall85737a72009-10-30 00:06:24 +00008891TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8892 bool WrittenAsLValue,
8893 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008894 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008895 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008896}
8897
8898template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008899QualType
John McCall85737a72009-10-30 00:06:24 +00008900TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8901 QualType ClassType,
8902 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008903 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008904 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008905}
8906
8907template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008908QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008909TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8910 ArrayType::ArraySizeModifier SizeMod,
8911 const llvm::APInt *Size,
8912 Expr *SizeExpr,
8913 unsigned IndexTypeQuals,
8914 SourceRange BracketsRange) {
8915 if (SizeExpr || !Size)
8916 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8917 IndexTypeQuals, BracketsRange,
8918 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008919
8920 QualType Types[] = {
8921 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8922 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8923 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008924 };
8925 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8926 QualType SizeType;
8927 for (unsigned I = 0; I != NumTypes; ++I)
8928 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8929 SizeType = Types[I];
8930 break;
8931 }
Mike Stump1eb44332009-09-09 15:08:12 +00008932
Eli Friedman01f276d2012-01-25 23:20:27 +00008933 // Note that we can return a VariableArrayType here in the case where
8934 // the element type was a dependent VariableArrayType.
8935 IntegerLiteral *ArraySize
8936 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8937 /*FIXME*/BracketsRange.getBegin());
8938 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008939 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008940 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008941}
Mike Stump1eb44332009-09-09 15:08:12 +00008942
Douglas Gregor577f75a2009-08-04 16:50:30 +00008943template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008944QualType
8945TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008946 ArrayType::ArraySizeModifier SizeMod,
8947 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008948 unsigned IndexTypeQuals,
8949 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008950 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008951 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008952}
8953
8954template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008955QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008956TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008957 ArrayType::ArraySizeModifier SizeMod,
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, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008961 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008962}
Mike Stump1eb44332009-09-09 15:08:12 +00008963
Douglas Gregor577f75a2009-08-04 16:50:30 +00008964template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008965QualType
8966TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008967 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008968 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008969 unsigned IndexTypeQuals,
8970 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008971 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008972 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008973 IndexTypeQuals, BracketsRange);
8974}
8975
8976template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008977QualType
8978TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008979 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008980 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008981 unsigned IndexTypeQuals,
8982 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008983 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008984 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008985 IndexTypeQuals, BracketsRange);
8986}
8987
8988template<typename Derived>
8989QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008990 unsigned NumElements,
8991 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008992 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008993 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008994}
Mike Stump1eb44332009-09-09 15:08:12 +00008995
Douglas Gregor577f75a2009-08-04 16:50:30 +00008996template<typename Derived>
8997QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8998 unsigned NumElements,
8999 SourceLocation AttributeLoc) {
9000 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9001 NumElements, true);
9002 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009003 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9004 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009005 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009006}
Mike Stump1eb44332009-09-09 15:08:12 +00009007
Douglas Gregor577f75a2009-08-04 16:50:30 +00009008template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009009QualType
9010TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009011 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009012 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009013 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009014}
Mike Stump1eb44332009-09-09 15:08:12 +00009015
Douglas Gregor577f75a2009-08-04 16:50:30 +00009016template<typename Derived>
9017QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00009018 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009019 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00009020 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009021 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00009022 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00009023 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00009024 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00009025 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009026 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009027 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009028 getDerived().getBaseEntity(),
9029 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009030}
Mike Stump1eb44332009-09-09 15:08:12 +00009031
Douglas Gregor577f75a2009-08-04 16:50:30 +00009032template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009033QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9034 return SemaRef.Context.getFunctionNoProtoType(T);
9035}
9036
9037template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009038QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9039 assert(D && "no decl found");
9040 if (D->isInvalidDecl()) return QualType();
9041
Douglas Gregor92e986e2010-04-22 16:44:27 +00009042 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009043 TypeDecl *Ty;
9044 if (isa<UsingDecl>(D)) {
9045 UsingDecl *Using = cast<UsingDecl>(D);
9046 assert(Using->isTypeName() &&
9047 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9048
9049 // A valid resolved using typename decl points to exactly one type decl.
9050 assert(++Using->shadow_begin() == Using->shadow_end());
9051 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00009052
John McCalled976492009-12-04 22:46:56 +00009053 } else {
9054 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9055 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9056 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9057 }
9058
9059 return SemaRef.Context.getTypeDeclType(Ty);
9060}
9061
9062template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009063QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9064 SourceLocation Loc) {
9065 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009066}
9067
9068template<typename Derived>
9069QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9070 return SemaRef.Context.getTypeOfType(Underlying);
9071}
9072
9073template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009074QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9075 SourceLocation Loc) {
9076 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009077}
9078
9079template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009080QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9081 UnaryTransformType::UTTKind UKind,
9082 SourceLocation Loc) {
9083 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9084}
9085
9086template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009087QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009088 TemplateName Template,
9089 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009090 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009091 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009092}
Mike Stump1eb44332009-09-09 15:08:12 +00009093
Douglas Gregordcee1a12009-08-06 05:28:30 +00009094template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009095QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9096 SourceLocation KWLoc) {
9097 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9098}
9099
9100template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009101TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009102TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009103 bool TemplateKW,
9104 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009105 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009106 Template);
9107}
9108
9109template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009110TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009111TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9112 const IdentifierInfo &Name,
9113 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009114 QualType ObjectType,
9115 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009116 UnqualifiedId TemplateName;
9117 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009118 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009119 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009120 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009121 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009122 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009123 /*EnteringContext=*/false,
9124 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009125 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009126}
Mike Stump1eb44332009-09-09 15:08:12 +00009127
Douglas Gregorb98b1992009-08-11 05:31:07 +00009128template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009129TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009130TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009131 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009132 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009133 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009134 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009135 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009136 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009137 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009138 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009139 Sema::TemplateTy Template;
9140 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009141 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009142 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009143 /*EnteringContext=*/false,
9144 Template);
9145 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009146}
Sean Huntc3021132010-05-05 15:23:54 +00009147
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009148template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009149ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009150TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9151 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009152 Expr *OrigCallee,
9153 Expr *First,
9154 Expr *Second) {
9155 Expr *Callee = OrigCallee->IgnoreParenCasts();
9156 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009157
Douglas Gregorb98b1992009-08-11 05:31:07 +00009158 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009159 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009160 if (!First->getType()->isOverloadableType() &&
9161 !Second->getType()->isOverloadableType())
9162 return getSema().CreateBuiltinArraySubscriptExpr(First,
9163 Callee->getLocStart(),
9164 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009165 } else if (Op == OO_Arrow) {
9166 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009167 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9168 } else if (Second == 0 || isPostIncDec) {
9169 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009170 // The argument is not of overloadable type, so try to create a
9171 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009172 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009173 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009174
John McCall9ae2f072010-08-23 23:25:46 +00009175 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009176 }
9177 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009178 if (!First->getType()->isOverloadableType() &&
9179 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009180 // Neither of the arguments is an overloadable type, so try to
9181 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009182 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009183 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009184 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009185 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009186 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009187
Douglas Gregorb98b1992009-08-11 05:31:07 +00009188 return move(Result);
9189 }
9190 }
Mike Stump1eb44332009-09-09 15:08:12 +00009191
9192 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009193 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009194 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009195
John McCall9ae2f072010-08-23 23:25:46 +00009196 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009197 assert(ULE->requiresADL());
9198
9199 // FIXME: Do we have to check
9200 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009201 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009202 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009203 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00009204 }
Mike Stump1eb44332009-09-09 15:08:12 +00009205
Douglas Gregorb98b1992009-08-11 05:31:07 +00009206 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009207 Expr *Args[2] = { First, Second };
9208 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009209
Douglas Gregorb98b1992009-08-11 05:31:07 +00009210 // Create the overloaded operator invocation for unary operators.
9211 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009212 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009213 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009214 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009215 }
Mike Stump1eb44332009-09-09 15:08:12 +00009216
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009217 if (Op == OO_Subscript) {
9218 SourceLocation LBrace;
9219 SourceLocation RBrace;
9220
9221 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9222 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9223 LBrace = SourceLocation::getFromRawEncoding(
9224 NameLoc.CXXOperatorName.BeginOpNameLoc);
9225 RBrace = SourceLocation::getFromRawEncoding(
9226 NameLoc.CXXOperatorName.EndOpNameLoc);
9227 } else {
9228 LBrace = Callee->getLocStart();
9229 RBrace = OpLoc;
9230 }
9231
9232 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9233 First, Second);
9234 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009235
Douglas Gregorb98b1992009-08-11 05:31:07 +00009236 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009237 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009238 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009239 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9240 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009241 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009242
Mike Stump1eb44332009-09-09 15:08:12 +00009243 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009244}
Mike Stump1eb44332009-09-09 15:08:12 +00009245
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009246template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009247ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009248TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009249 SourceLocation OperatorLoc,
9250 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009251 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009252 TypeSourceInfo *ScopeType,
9253 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009254 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009255 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009256 QualType BaseType = Base->getType();
9257 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009258 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00009259 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009260 !BaseType->getAs<PointerType>()->getPointeeType()
9261 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009262 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009263 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009264 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009265 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009266 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009267 /*FIXME?*/true);
9268 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009269
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009270 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009271 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9272 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9273 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9274 NameInfo.setNamedTypeInfo(DestroyedType);
9275
Richard Smith6314db92012-05-15 06:15:11 +00009276 // The scope type is now known to be a valid nested name specifier
9277 // component. Tack it on to the end of the nested name specifier.
9278 if (ScopeType)
9279 SS.Extend(SemaRef.Context, SourceLocation(),
9280 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009281
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009282 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009283 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009284 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009285 SS, TemplateKWLoc,
9286 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009287 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009288 /*TemplateArgs*/ 0);
9289}
9290
Douglas Gregor577f75a2009-08-04 16:50:30 +00009291} // end namespace clang
9292
9293#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H