blob: 3b41f758d9d6a56ea8d17ecc88ad19549990c2e3 [file] [log] [blame]
Chris Lattner57ad3782011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner57ad3782011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattner57ad3782011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregor577f75a2009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall2d887082010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor8491ffe2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Richard Smith3e4c6c42011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall19510852010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000034#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000035#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000036#include "TypeLocBuilder.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCall781472f2010-08-25 08:40:02 +000040using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000041
Douglas Gregor577f75a2009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump1eb44332009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump1eb44332009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
101
102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
106
107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
111
Douglas Gregor577f75a2009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000114
Douglas Gregordfca6f52012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
119
Mike Stump1eb44332009-09-09 15:08:12 +0000120public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000123
Douglas Gregor577f75a2009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000130 }
131
John McCall60d7b3a2010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000134
Douglas Gregor577f75a2009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000138
Douglas Gregor577f75a2009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
144 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000145
Douglas Gregor577f75a2009-08-04 16:50:30 +0000146 /// \brief Returns the location of the entity being transformed, if that
147 /// information was not available elsewhere in the AST.
148 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000149 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000150 /// provide an alternative implementation that provides better location
151 /// information.
152 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000153
Douglas Gregor577f75a2009-08-04 16:50:30 +0000154 /// \brief Returns the name of the entity being transformed, if that
155 /// information was not available elsewhere in the AST.
156 ///
157 /// By default, returns an empty name. Subclasses can provide an alternative
158 /// implementation with a more precise name.
159 DeclarationName getBaseEntity() { return DeclarationName(); }
160
Douglas Gregorb98b1992009-08-11 05:31:07 +0000161 /// \brief Sets the "base" location and entity when that
162 /// information is known based on another transformation.
163 ///
164 /// By default, the source location and entity are ignored. Subclasses can
165 /// override this function to provide a customized implementation.
166 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000167
Douglas Gregorb98b1992009-08-11 05:31:07 +0000168 /// \brief RAII object that temporarily sets the base location and entity
169 /// used for reporting diagnostics in types.
170 class TemporaryBase {
171 TreeTransform &Self;
172 SourceLocation OldLocation;
173 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000174
Douglas Gregorb98b1992009-08-11 05:31:07 +0000175 public:
176 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000177 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000178 OldLocation = Self.getDerived().getBaseLocation();
179 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregorae201f72011-01-25 17:51:48 +0000180
181 if (Location.isValid())
182 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000183 }
Mike Stump1eb44332009-09-09 15:08:12 +0000184
Douglas Gregorb98b1992009-08-11 05:31:07 +0000185 ~TemporaryBase() {
186 Self.getDerived().setBase(OldLocation, OldEntity);
187 }
188 };
Mike Stump1eb44332009-09-09 15:08:12 +0000189
190 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000191 /// transformed.
192 ///
193 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000194 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000195 /// not change. For example, template instantiation need not traverse
196 /// non-dependent types.
197 bool AlreadyTransformed(QualType T) {
198 return T.isNull();
199 }
200
Douglas Gregor6eef5192009-12-14 19:27:10 +0000201 /// \brief Determine whether the given call argument should be dropped, e.g.,
202 /// because it is a default argument.
203 ///
204 /// Subclasses can provide an alternative implementation of this routine to
205 /// determine which kinds of call arguments get dropped. By default,
206 /// CXXDefaultArgument nodes are dropped (prior to transformation).
207 bool DropCallArgument(Expr *E) {
208 return E->isDefaultArgument();
209 }
Sean Huntc3021132010-05-05 15:23:54 +0000210
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000211 /// \brief Determine whether we should expand a pack expansion with the
212 /// given set of parameter packs into separate arguments by repeatedly
213 /// transforming the pattern.
214 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000215 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000216 /// Subclasses can override this routine to provide different behavior.
217 ///
218 /// \param EllipsisLoc The location of the ellipsis that identifies the
219 /// pack expansion.
220 ///
221 /// \param PatternRange The source range that covers the entire pattern of
222 /// the pack expansion.
223 ///
224 /// \param Unexpanded The set of unexpanded parameter packs within the
225 /// pattern.
226 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000227 /// \param ShouldExpand Will be set to \c true if the transformer should
228 /// expand the corresponding pack expansions into separate arguments. When
229 /// set, \c NumExpansions must also be set.
230 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000231 /// \param RetainExpansion Whether the caller should add an unexpanded
232 /// pack expansion after all of the expanded arguments. This is used
233 /// when extending explicitly-specified template argument packs per
234 /// C++0x [temp.arg.explicit]p9.
235 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000236 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000237 /// the expanded form of the corresponding pack expansion. This is both an
238 /// input and an output parameter, which can be set by the caller if the
239 /// number of expansions is known a priori (e.g., due to a prior substitution)
240 /// and will be set by the callee when the number of expansions is known.
241 /// The callee must set this value when \c ShouldExpand is \c true; it may
242 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000243 ///
244 /// \returns true if an error occurred (e.g., because the parameter packs
245 /// are to be instantiated with arguments of different lengths), false
246 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
247 /// must be set.
248 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
249 SourceRange PatternRange,
David Blaikiea71f9d02011-09-22 02:34:54 +0000250 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000251 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000252 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000253 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000254 ShouldExpand = false;
255 return false;
256 }
257
Douglas Gregord3731192011-01-10 07:32:04 +0000258 /// \brief "Forget" about the partially-substituted pack template argument,
259 /// when performing an instantiation that must preserve the parameter pack
260 /// use.
261 ///
262 /// This routine is meant to be overridden by the template instantiator.
263 TemplateArgument ForgetPartiallySubstitutedPack() {
264 return TemplateArgument();
265 }
266
267 /// \brief "Remember" the partially-substituted pack template argument
268 /// after performing an instantiation that must preserve the parameter pack
269 /// use.
270 ///
271 /// This routine is meant to be overridden by the template instantiator.
272 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
273
Douglas Gregor12c9c002011-01-07 16:43:16 +0000274 /// \brief Note to the derived class when a function parameter pack is
275 /// being expanded.
276 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
277
Douglas Gregor577f75a2009-08-04 16:50:30 +0000278 /// \brief Transforms the given type into another type.
279 ///
John McCalla2becad2009-10-21 00:40:46 +0000280 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000281 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000282 /// function. This is expensive, but we don't mind, because
283 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000284 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000285 ///
286 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000287 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000288
John McCalla2becad2009-10-21 00:40:46 +0000289 /// \brief Transforms the given type-with-location into a new
290 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000291 ///
John McCalla2becad2009-10-21 00:40:46 +0000292 /// By default, this routine transforms a type by delegating to the
293 /// appropriate TransformXXXType to build a new type. Subclasses
294 /// may override this function (to take over all type
295 /// transformations) or some set of the TransformXXXType functions
296 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000297 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000298
299 /// \brief Transform the given type-with-location into a new
300 /// type, collecting location information in the given builder
301 /// as necessary.
302 ///
John McCall43fed0d2010-11-12 08:19:04 +0000303 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000304
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000305 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000306 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000307 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000308 /// appropriate TransformXXXStmt function to transform a specific kind of
309 /// statement or the TransformExpr() function to transform an expression.
310 /// Subclasses may override this function to transform statements using some
311 /// other mechanism.
312 ///
313 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000314 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000315
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000316 /// \brief Transform the given expression.
317 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000318 /// By default, this routine transforms an expression by delegating to the
319 /// appropriate TransformXXXExpr function to build a new expression.
320 /// Subclasses may override this function to transform expressions using some
321 /// other mechanism.
322 ///
323 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000324 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000325
Douglas Gregoraa165f82011-01-03 19:04:46 +0000326 /// \brief Transform the given list of expressions.
327 ///
328 /// This routine transforms a list of expressions by invoking
329 /// \c TransformExpr() for each subexpression. However, it also provides
330 /// support for variadic templates by expanding any pack expansions (if the
331 /// derived class permits such expansion) along the way. When pack expansions
332 /// are present, the number of outputs may not equal the number of inputs.
333 ///
334 /// \param Inputs The set of expressions to be transformed.
335 ///
336 /// \param NumInputs The number of expressions in \c Inputs.
337 ///
338 /// \param IsCall If \c true, then this transform is being performed on
339 /// function-call arguments, and any arguments that should be dropped, will
340 /// be.
341 ///
342 /// \param Outputs The transformed input expressions will be added to this
343 /// vector.
344 ///
345 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
346 /// due to transformation.
347 ///
348 /// \returns true if an error occurred, false otherwise.
349 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000350 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000351 bool *ArgChanged = 0);
352
Douglas Gregor577f75a2009-08-04 16:50:30 +0000353 /// \brief Transform the given declaration, which is referenced from a type
354 /// or expression.
355 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000356 /// By default, acts as the identity function on declarations, unless the
357 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000358 /// may override this function to provide alternate behavior.
Douglas Gregordfca6f52012-02-13 22:00:16 +0000359 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
360 llvm::DenseMap<Decl *, Decl *>::iterator Known
361 = TransformedLocalDecls.find(D);
362 if (Known != TransformedLocalDecls.end())
363 return Known->second;
364
365 return D;
366 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000367
Douglas Gregordfca6f52012-02-13 22:00:16 +0000368 /// \brief Transform the attributes associated with the given declaration and
369 /// place them on the new declaration.
370 ///
371 /// By default, this operation does nothing. Subclasses may override this
372 /// behavior to transform attributes.
373 void transformAttrs(Decl *Old, Decl *New) { }
374
375 /// \brief Note that a local declaration has been transformed by this
376 /// transformer.
377 ///
378 /// Local declarations are typically transformed via a call to
379 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
380 /// the transformer itself has to transform the declarations. This routine
381 /// can be overridden by a subclass that keeps track of such mappings.
382 void transformedLocalDecl(Decl *Old, Decl *New) {
383 TransformedLocalDecls[Old] = New;
384 }
385
Douglas Gregor43959a92009-08-20 07:17:43 +0000386 /// \brief Transform the definition of the given declaration.
387 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000388 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000389 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000390 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
391 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000392 }
Mike Stump1eb44332009-09-09 15:08:12 +0000393
Douglas Gregor6cd21982009-10-20 05:58:46 +0000394 /// \brief Transform the given declaration, which was the first part of a
395 /// nested-name-specifier in a member access expression.
396 ///
Sean Huntc3021132010-05-05 15:23:54 +0000397 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000398 /// identifier in a nested-name-specifier of a member access expression, e.g.,
399 /// the \c T in \c x->T::member
400 ///
401 /// By default, invokes TransformDecl() to transform the declaration.
402 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000403 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
404 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000405 }
Sean Huntc3021132010-05-05 15:23:54 +0000406
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000407 /// \brief Transform the given nested-name-specifier with source-location
408 /// information.
409 ///
410 /// By default, transforms all of the types and declarations within the
411 /// nested-name-specifier. Subclasses may override this function to provide
412 /// alternate behavior.
413 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
414 NestedNameSpecifierLoc NNS,
415 QualType ObjectType = QualType(),
416 NamedDecl *FirstQualifierInScope = 0);
417
Douglas Gregor81499bb2009-09-03 22:13:48 +0000418 /// \brief Transform the given declaration name.
419 ///
420 /// By default, transforms the types of conversion function, constructor,
421 /// and destructor names and then (if needed) rebuilds the declaration name.
422 /// Identifiers and selectors are returned unmodified. Sublcasses may
423 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000424 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000425 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000426
Douglas Gregor577f75a2009-08-04 16:50:30 +0000427 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000428 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000429 /// \param SS The nested-name-specifier that qualifies the template
430 /// name. This nested-name-specifier must already have been transformed.
431 ///
432 /// \param Name The template name to transform.
433 ///
434 /// \param NameLoc The source location of the template name.
435 ///
436 /// \param ObjectType If we're translating a template name within a member
437 /// access expression, this is the type of the object whose member template
438 /// is being referenced.
439 ///
440 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
441 /// also refers to a name within the current (lexical) scope, this is the
442 /// declaration it refers to.
443 ///
444 /// By default, transforms the template name by transforming the declarations
445 /// and nested-name-specifiers that occur within the template name.
446 /// Subclasses may override this function to provide alternate behavior.
447 TemplateName TransformTemplateName(CXXScopeSpec &SS,
448 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000449 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000450 QualType ObjectType = QualType(),
451 NamedDecl *FirstQualifierInScope = 0);
452
Douglas Gregor577f75a2009-08-04 16:50:30 +0000453 /// \brief Transform the given template argument.
454 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000455 /// By default, this operation transforms the type, expression, or
456 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000457 /// new template argument from the transformed result. Subclasses may
458 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000459 ///
460 /// Returns true if there was an error.
461 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
462 TemplateArgumentLoc &Output);
463
Douglas Gregorfcc12532010-12-20 17:31:10 +0000464 /// \brief Transform the given set of template arguments.
465 ///
466 /// By default, this operation transforms all of the template arguments
467 /// in the input set using \c TransformTemplateArgument(), and appends
468 /// the transformed arguments to the output list.
469 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000470 /// Note that this overload of \c TransformTemplateArguments() is merely
471 /// a convenience function. Subclasses that wish to override this behavior
472 /// should override the iterator-based member template version.
473 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000474 /// \param Inputs The set of template arguments to be transformed.
475 ///
476 /// \param NumInputs The number of template arguments in \p Inputs.
477 ///
478 /// \param Outputs The set of transformed template arguments output by this
479 /// routine.
480 ///
481 /// Returns true if an error occurred.
482 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
483 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000484 TemplateArgumentListInfo &Outputs) {
485 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
486 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000487
488 /// \brief Transform the given set of template arguments.
489 ///
490 /// By default, this operation transforms all of the template arguments
491 /// in the input set using \c TransformTemplateArgument(), and appends
492 /// the transformed arguments to the output list.
493 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000494 /// \param First An iterator to the first template argument.
495 ///
496 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000497 ///
498 /// \param Outputs The set of transformed template arguments output by this
499 /// routine.
500 ///
501 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000502 template<typename InputIterator>
503 bool TransformTemplateArguments(InputIterator First,
504 InputIterator Last,
505 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000506
John McCall833ca992009-10-29 08:12:44 +0000507 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
508 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
509 TemplateArgumentLoc &ArgLoc);
510
John McCalla93c9342009-12-07 02:54:59 +0000511 /// \brief Fakes up a TypeSourceInfo for a type.
512 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
513 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000514 getDerived().getBaseLocation());
515 }
Mike Stump1eb44332009-09-09 15:08:12 +0000516
John McCalla2becad2009-10-21 00:40:46 +0000517#define ABSTRACT_TYPELOC(CLASS, PARENT)
518#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000519 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000520#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000521
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000522 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
523 FunctionProtoTypeLoc TL,
524 CXXRecordDecl *ThisContext,
525 unsigned ThisTypeQuals);
526
John Wiegley28bbe4b2011-04-28 01:08:34 +0000527 StmtResult
528 TransformSEHHandler(Stmt *Handler);
529
John McCall43fed0d2010-11-12 08:19:04 +0000530 QualType
531 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
532 TemplateSpecializationTypeLoc TL,
533 TemplateName Template);
534
535 QualType
536 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
537 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000538 TemplateName Template,
539 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000540
541 QualType
542 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000543 DependentTemplateSpecializationTypeLoc TL,
544 NestedNameSpecifierLoc QualifierLoc);
545
John McCall21ef0fa2010-03-11 09:03:00 +0000546 /// \brief Transforms the parameters of a function type into the
547 /// given vectors.
548 ///
549 /// The result vectors should be kept in sync; null entries in the
550 /// variables vector are acceptable.
551 ///
552 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000553 bool TransformFunctionTypeParams(SourceLocation Loc,
554 ParmVarDecl **Params, unsigned NumParams,
555 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000556 SmallVectorImpl<QualType> &PTypes,
557 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000558
559 /// \brief Transforms a single function-type parameter. Return null
560 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000561 ///
562 /// \param indexAdjustment - A number to add to the parameter's
563 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000564 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000565 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000566 llvm::Optional<unsigned> NumExpansions,
567 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000568
John McCall43fed0d2010-11-12 08:19:04 +0000569 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000570
John McCall60d7b3a2010-08-24 06:29:42 +0000571 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
572 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000573
Douglas Gregor43959a92009-08-20 07:17:43 +0000574#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000575 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000576#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000577 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000578#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000579#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000580
Douglas Gregor577f75a2009-08-04 16:50:30 +0000581 /// \brief Build a new pointer type given its pointee type.
582 ///
583 /// By default, performs semantic analysis when building the pointer type.
584 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000585 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000586
587 /// \brief Build a new block pointer type given its pointee type.
588 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000589 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000590 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000591 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000592
John McCall85737a72009-10-30 00:06:24 +0000593 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000594 ///
John McCall85737a72009-10-30 00:06:24 +0000595 /// By default, performs semantic analysis when building the
596 /// reference type. Subclasses may override this routine to provide
597 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000598 ///
John McCall85737a72009-10-30 00:06:24 +0000599 /// \param LValue whether the type was written with an lvalue sigil
600 /// or an rvalue sigil.
601 QualType RebuildReferenceType(QualType ReferentType,
602 bool LValue,
603 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000604
Douglas Gregor577f75a2009-08-04 16:50:30 +0000605 /// \brief Build a new member pointer type given the pointee type and the
606 /// class type it refers into.
607 ///
608 /// By default, performs semantic analysis when building the member pointer
609 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000610 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
611 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000612
Douglas Gregor577f75a2009-08-04 16:50:30 +0000613 /// \brief Build a new array type given the element type, size
614 /// modifier, size of the array (if known), size expression, and index type
615 /// qualifiers.
616 ///
617 /// By default, performs semantic analysis when building the array type.
618 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000619 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000620 QualType RebuildArrayType(QualType ElementType,
621 ArrayType::ArraySizeModifier SizeMod,
622 const llvm::APInt *Size,
623 Expr *SizeExpr,
624 unsigned IndexTypeQuals,
625 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000626
Douglas Gregor577f75a2009-08-04 16:50:30 +0000627 /// \brief Build a new constant array type given the element type, size
628 /// modifier, (known) size of the array, and index type qualifiers.
629 ///
630 /// By default, performs semantic analysis when building the array type.
631 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000632 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000633 ArrayType::ArraySizeModifier SizeMod,
634 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000635 unsigned IndexTypeQuals,
636 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000637
Douglas Gregor577f75a2009-08-04 16:50:30 +0000638 /// \brief Build a new incomplete array type given the element type, size
639 /// modifier, and index type qualifiers.
640 ///
641 /// By default, performs semantic analysis when building the array type.
642 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000643 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000644 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000645 unsigned IndexTypeQuals,
646 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000647
Mike Stump1eb44332009-09-09 15:08:12 +0000648 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000649 /// size modifier, size expression, and index type qualifiers.
650 ///
651 /// By default, performs semantic analysis when building the array type.
652 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000653 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000654 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000655 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000656 unsigned IndexTypeQuals,
657 SourceRange BracketsRange);
658
Mike Stump1eb44332009-09-09 15:08:12 +0000659 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000660 /// size modifier, size expression, and index type qualifiers.
661 ///
662 /// By default, performs semantic analysis when building the array type.
663 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000664 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000665 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000666 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000667 unsigned IndexTypeQuals,
668 SourceRange BracketsRange);
669
670 /// \brief Build a new vector type given the element type and
671 /// number of elements.
672 ///
673 /// By default, performs semantic analysis when building the vector type.
674 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000675 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000676 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000677
Douglas Gregor577f75a2009-08-04 16:50:30 +0000678 /// \brief Build a new extended vector type given the element type and
679 /// number of elements.
680 ///
681 /// By default, performs semantic analysis when building the vector type.
682 /// Subclasses may override this routine to provide different behavior.
683 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
684 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000685
686 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000687 /// given the element type and number of elements.
688 ///
689 /// By default, performs semantic analysis when building the vector type.
690 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000691 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000692 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000693 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000694
Douglas Gregor577f75a2009-08-04 16:50:30 +0000695 /// \brief Build a new function type.
696 ///
697 /// By default, performs semantic analysis when building the function type.
698 /// Subclasses may override this routine to provide different behavior.
699 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000700 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000701 unsigned NumParamTypes,
Richard Smitheefb3d52012-02-10 09:58:53 +0000702 bool Variadic, bool HasTrailingReturn,
703 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000704 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000705 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000706
John McCalla2becad2009-10-21 00:40:46 +0000707 /// \brief Build a new unprototyped function type.
708 QualType RebuildFunctionNoProtoType(QualType ResultType);
709
John McCalled976492009-12-04 22:46:56 +0000710 /// \brief Rebuild an unresolved typename type, given the decl that
711 /// the UnresolvedUsingTypenameDecl was transformed to.
712 QualType RebuildUnresolvedUsingType(Decl *D);
713
Douglas Gregor577f75a2009-08-04 16:50:30 +0000714 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000715 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000716 return SemaRef.Context.getTypeDeclType(Typedef);
717 }
718
719 /// \brief Build a new class/struct/union type.
720 QualType RebuildRecordType(RecordDecl *Record) {
721 return SemaRef.Context.getTypeDeclType(Record);
722 }
723
724 /// \brief Build a new Enum type.
725 QualType RebuildEnumType(EnumDecl *Enum) {
726 return SemaRef.Context.getTypeDeclType(Enum);
727 }
John McCall7da24312009-09-05 00:15:47 +0000728
Mike Stump1eb44332009-09-09 15:08:12 +0000729 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000730 ///
731 /// By default, performs semantic analysis when building the typeof type.
732 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000733 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000734
Mike Stump1eb44332009-09-09 15:08:12 +0000735 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000736 ///
737 /// By default, builds a new TypeOfType with the given underlying type.
738 QualType RebuildTypeOfType(QualType Underlying);
739
Sean Huntca63c202011-05-24 22:41:36 +0000740 /// \brief Build a new unary transform type.
741 QualType RebuildUnaryTransformType(QualType BaseType,
742 UnaryTransformType::UTTKind UKind,
743 SourceLocation Loc);
744
Mike Stump1eb44332009-09-09 15:08:12 +0000745 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000746 ///
747 /// By default, performs semantic analysis when building the decltype type.
748 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000749 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000750
Richard Smith34b41d92011-02-20 03:19:35 +0000751 /// \brief Build a new C++0x auto type.
752 ///
753 /// By default, builds a new AutoType with the given deduced type.
754 QualType RebuildAutoType(QualType Deduced) {
755 return SemaRef.Context.getAutoType(Deduced);
756 }
757
Douglas Gregor577f75a2009-08-04 16:50:30 +0000758 /// \brief Build a new template specialization type.
759 ///
760 /// By default, performs semantic analysis when building the template
761 /// specialization type. Subclasses may override this routine to provide
762 /// different behavior.
763 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000764 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000765 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000766
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000767 /// \brief Build a new parenthesized type.
768 ///
769 /// By default, builds a new ParenType type from the inner type.
770 /// Subclasses may override this routine to provide different behavior.
771 QualType RebuildParenType(QualType InnerType) {
772 return SemaRef.Context.getParenType(InnerType);
773 }
774
Douglas Gregor577f75a2009-08-04 16:50:30 +0000775 /// \brief Build a new qualified name type.
776 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000777 /// By default, builds a new ElaboratedType type from the keyword,
778 /// the nested-name-specifier and the named type.
779 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000780 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
781 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000782 NestedNameSpecifierLoc QualifierLoc,
783 QualType Named) {
784 return SemaRef.Context.getElaboratedType(Keyword,
785 QualifierLoc.getNestedNameSpecifier(),
786 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000787 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000788
789 /// \brief Build a new typename type that refers to a template-id.
790 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000791 /// By default, builds a new DependentNameType type from the
792 /// nested-name-specifier and the given type. Subclasses may override
793 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000794 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000795 ElaboratedTypeKeyword Keyword,
796 NestedNameSpecifierLoc QualifierLoc,
797 const IdentifierInfo *Name,
798 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000799 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000800 // Rebuild the template name.
801 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000802 CXXScopeSpec SS;
803 SS.Adopt(QualifierLoc);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000804 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000805 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000806
807 if (InstName.isNull())
808 return QualType();
809
810 // If it's still dependent, make a dependent specialization.
811 if (InstName.getAsDependentTemplateName())
812 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
813 QualifierLoc.getNestedNameSpecifier(),
814 Name,
815 Args);
816
817 // Otherwise, make an elaborated type wrapping a non-dependent
818 // specialization.
819 QualType T =
820 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
821 if (T.isNull()) return QualType();
822
823 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
824 return T;
825
826 return SemaRef.Context.getElaboratedType(Keyword,
827 QualifierLoc.getNestedNameSpecifier(),
828 T);
829 }
830
Douglas Gregor577f75a2009-08-04 16:50:30 +0000831 /// \brief Build a new typename type that refers to an identifier.
832 ///
833 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000834 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000835 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000836 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000837 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000838 NestedNameSpecifierLoc QualifierLoc,
839 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000840 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000841 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000842 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000843
Douglas Gregor2494dd02011-03-01 01:34:45 +0000844 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000845 // If the name is still dependent, just build a new dependent name type.
846 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor2494dd02011-03-01 01:34:45 +0000847 return SemaRef.Context.getDependentNameType(Keyword,
848 QualifierLoc.getNestedNameSpecifier(),
849 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000850 }
851
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000852 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000853 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000854 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000855
856 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
857
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000858 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000859 // into a non-dependent elaborated-type-specifier. Find the tag we're
860 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000861 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000862 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
863 if (!DC)
864 return QualType();
865
John McCall56138762010-05-27 06:40:31 +0000866 if (SemaRef.RequireCompleteDeclContext(SS, DC))
867 return QualType();
868
Douglas Gregor40336422010-03-31 22:19:08 +0000869 TagDecl *Tag = 0;
870 SemaRef.LookupQualifiedName(Result, DC);
871 switch (Result.getResultKind()) {
872 case LookupResult::NotFound:
873 case LookupResult::NotFoundInCurrentInstantiation:
874 break;
Sean Huntc3021132010-05-05 15:23:54 +0000875
Douglas Gregor40336422010-03-31 22:19:08 +0000876 case LookupResult::Found:
877 Tag = Result.getAsSingle<TagDecl>();
878 break;
Sean Huntc3021132010-05-05 15:23:54 +0000879
Douglas Gregor40336422010-03-31 22:19:08 +0000880 case LookupResult::FoundOverloaded:
881 case LookupResult::FoundUnresolvedValue:
882 llvm_unreachable("Tag lookup cannot find non-tags");
Sean Huntc3021132010-05-05 15:23:54 +0000883
Douglas Gregor40336422010-03-31 22:19:08 +0000884 case LookupResult::Ambiguous:
885 // Let the LookupResult structure handle ambiguities.
886 return QualType();
887 }
888
889 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000890 // Check where the name exists but isn't a tag type and use that to emit
891 // better diagnostics.
892 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
893 SemaRef.LookupQualifiedName(Result, DC);
894 switch (Result.getResultKind()) {
895 case LookupResult::Found:
896 case LookupResult::FoundOverloaded:
897 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000898 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000899 unsigned Kind = 0;
900 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000901 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
902 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000903 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
904 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
905 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000906 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000907 default:
908 // FIXME: Would be nice to highlight just the source range.
909 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
910 << Kind << Id << DC;
911 break;
912 }
Douglas Gregor40336422010-03-31 22:19:08 +0000913 return QualType();
914 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000915
Richard Trieubbf34c02011-06-10 03:11:26 +0000916 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
917 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000918 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000919 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
920 return QualType();
921 }
922
923 // Build the elaborated-type-specifier type.
924 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor2494dd02011-03-01 01:34:45 +0000925 return SemaRef.Context.getElaboratedType(Keyword,
926 QualifierLoc.getNestedNameSpecifier(),
927 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000928 }
Mike Stump1eb44332009-09-09 15:08:12 +0000929
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000930 /// \brief Build a new pack expansion type.
931 ///
932 /// By default, builds a new PackExpansionType type from the given pattern.
933 /// Subclasses may override this routine to provide different behavior.
934 QualType RebuildPackExpansionType(QualType Pattern,
935 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000936 SourceLocation EllipsisLoc,
937 llvm::Optional<unsigned> NumExpansions) {
938 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
939 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000940 }
941
Eli Friedmanb001de72011-10-06 23:00:33 +0000942 /// \brief Build a new atomic type given its value type.
943 ///
944 /// By default, performs semantic analysis when building the atomic type.
945 /// Subclasses may override this routine to provide different behavior.
946 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
947
Douglas Gregord1067e52009-08-06 06:41:21 +0000948 /// \brief Build a new template name given a nested name specifier, a flag
949 /// indicating whether the "template" keyword was provided, and the template
950 /// that the template name refers to.
951 ///
952 /// By default, builds the new template name directly. Subclasses may override
953 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000954 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000955 bool TemplateKW,
956 TemplateDecl *Template);
957
Douglas Gregord1067e52009-08-06 06:41:21 +0000958 /// \brief Build a new template name given a nested name specifier and the
959 /// name that is referred to as a template.
960 ///
961 /// By default, performs semantic analysis to determine whether the name can
962 /// be resolved to a specific template, then builds the appropriate kind of
963 /// template name. Subclasses may override this routine to provide different
964 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000965 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
966 const IdentifierInfo &Name,
967 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000968 QualType ObjectType,
969 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000970
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000971 /// \brief Build a new template name given a nested name specifier and the
972 /// overloaded operator name that is referred to as a template.
973 ///
974 /// By default, performs semantic analysis to determine whether the name can
975 /// be resolved to a specific template, then builds the appropriate kind of
976 /// template name. Subclasses may override this routine to provide different
977 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000978 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000979 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000980 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000981 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000982
983 /// \brief Build a new template name given a template template parameter pack
984 /// and the
985 ///
986 /// By default, performs semantic analysis to determine whether the name can
987 /// be resolved to a specific template, then builds the appropriate kind of
988 /// template name. Subclasses may override this routine to provide different
989 /// behavior.
990 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
991 const TemplateArgument &ArgPack) {
992 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
993 }
994
Douglas Gregor43959a92009-08-20 07:17:43 +0000995 /// \brief Build a new compound statement.
996 ///
997 /// By default, performs semantic analysis to build the new statement.
998 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000999 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001000 MultiStmtArg Statements,
1001 SourceLocation RBraceLoc,
1002 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001003 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001004 IsStmtExpr);
1005 }
1006
1007 /// \brief Build a new case statement.
1008 ///
1009 /// By default, performs semantic analysis to build the new statement.
1010 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001011 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001012 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001013 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001014 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001015 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001016 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001017 ColonLoc);
1018 }
Mike Stump1eb44332009-09-09 15:08:12 +00001019
Douglas Gregor43959a92009-08-20 07:17:43 +00001020 /// \brief Attach the body to a new case statement.
1021 ///
1022 /// By default, performs semantic analysis to build the new statement.
1023 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001024 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001025 getSema().ActOnCaseStmtBody(S, Body);
1026 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001027 }
Mike Stump1eb44332009-09-09 15:08:12 +00001028
Douglas Gregor43959a92009-08-20 07:17:43 +00001029 /// \brief Build a new default statement.
1030 ///
1031 /// By default, performs semantic analysis to build the new statement.
1032 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001033 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001034 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001035 Stmt *SubStmt) {
1036 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001037 /*CurScope=*/0);
1038 }
Mike Stump1eb44332009-09-09 15:08:12 +00001039
Douglas Gregor43959a92009-08-20 07:17:43 +00001040 /// \brief Build a new label statement.
1041 ///
1042 /// By default, performs semantic analysis to build the new statement.
1043 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001044 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1045 SourceLocation ColonLoc, Stmt *SubStmt) {
1046 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001047 }
Mike Stump1eb44332009-09-09 15:08:12 +00001048
Richard Smith534986f2012-04-14 00:33:13 +00001049 /// \brief Build a new label statement.
1050 ///
1051 /// By default, performs semantic analysis to build the new statement.
1052 /// Subclasses may override this routine to provide different behavior.
1053 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, const AttrVec &Attrs,
1054 Stmt *SubStmt) {
1055 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1056 }
1057
Douglas Gregor43959a92009-08-20 07:17:43 +00001058 /// \brief Build a new "if" statement.
1059 ///
1060 /// By default, performs semantic analysis to build the new statement.
1061 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001062 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001063 VarDecl *CondVar, Stmt *Then,
1064 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001065 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001066 }
Mike Stump1eb44332009-09-09 15:08:12 +00001067
Douglas Gregor43959a92009-08-20 07:17:43 +00001068 /// \brief Start building a new switch statement.
1069 ///
1070 /// By default, performs semantic analysis to build the new statement.
1071 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001072 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001073 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001074 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001075 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001076 }
Mike Stump1eb44332009-09-09 15:08:12 +00001077
Douglas Gregor43959a92009-08-20 07:17:43 +00001078 /// \brief Attach the body to the switch statement.
1079 ///
1080 /// By default, performs semantic analysis to build the new statement.
1081 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001082 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001083 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001084 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001085 }
1086
1087 /// \brief Build a new while statement.
1088 ///
1089 /// By default, performs semantic analysis to build the new statement.
1090 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001091 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1092 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001093 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001094 }
Mike Stump1eb44332009-09-09 15:08:12 +00001095
Douglas Gregor43959a92009-08-20 07:17:43 +00001096 /// \brief Build a new do-while statement.
1097 ///
1098 /// By default, performs semantic analysis to build the new statement.
1099 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001100 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001101 SourceLocation WhileLoc, SourceLocation LParenLoc,
1102 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001103 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1104 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001105 }
1106
1107 /// \brief Build a new for statement.
1108 ///
1109 /// By default, performs semantic analysis to build the new statement.
1110 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001111 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1112 Stmt *Init, Sema::FullExprArg Cond,
1113 VarDecl *CondVar, Sema::FullExprArg Inc,
1114 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001115 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001116 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001117 }
Mike Stump1eb44332009-09-09 15:08:12 +00001118
Douglas Gregor43959a92009-08-20 07:17:43 +00001119 /// \brief Build a new goto statement.
1120 ///
1121 /// By default, performs semantic analysis to build the new statement.
1122 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001123 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1124 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001125 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001126 }
1127
1128 /// \brief Build a new indirect goto statement.
1129 ///
1130 /// By default, performs semantic analysis to build the new statement.
1131 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001132 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001133 SourceLocation StarLoc,
1134 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001135 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001136 }
Mike Stump1eb44332009-09-09 15:08:12 +00001137
Douglas Gregor43959a92009-08-20 07:17:43 +00001138 /// \brief Build a new return statement.
1139 ///
1140 /// By default, performs semantic analysis to build the new statement.
1141 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001142 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001143 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001144 }
Mike Stump1eb44332009-09-09 15:08:12 +00001145
Douglas Gregor43959a92009-08-20 07:17:43 +00001146 /// \brief Build a new declaration statement.
1147 ///
1148 /// By default, performs semantic analysis to build the new statement.
1149 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001150 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001151 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001152 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001153 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1154 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001155 }
Mike Stump1eb44332009-09-09 15:08:12 +00001156
Anders Carlsson703e3942010-01-24 05:50:09 +00001157 /// \brief Build a new inline asm statement.
1158 ///
1159 /// By default, performs semantic analysis to build the new statement.
1160 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001161 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001162 bool IsSimple,
1163 bool IsVolatile,
1164 unsigned NumOutputs,
1165 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001166 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001167 MultiExprArg Constraints,
1168 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001169 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001170 MultiExprArg Clobbers,
1171 SourceLocation RParenLoc,
1172 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001173 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001174 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001175 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001176 RParenLoc, MSAsm);
1177 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001178
Chad Rosier8cd64b42012-06-11 20:47:18 +00001179 /// \brief Build a new MS style inline asm statement.
1180 ///
1181 /// By default, performs semantic analysis to build the new statement.
1182 /// Subclasses may override this routine to provide different behavior.
1183 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc,
1184 std::string &AsmString,
1185 SourceLocation EndLoc) {
1186 return getSema().ActOnMSAsmStmt(AsmLoc, AsmString, EndLoc);
1187 }
1188
James Dennett699c9042012-06-15 07:13:21 +00001189 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001190 ///
1191 /// By default, performs semantic analysis to build the new statement.
1192 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001193 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001194 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001195 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001196 Stmt *Finally) {
1197 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1198 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001199 }
1200
Douglas Gregorbe270a02010-04-26 17:57:08 +00001201 /// \brief Rebuild an Objective-C exception declaration.
1202 ///
1203 /// By default, performs semantic analysis to build the new declaration.
1204 /// Subclasses may override this routine to provide different behavior.
1205 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1206 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001207 return getSema().BuildObjCExceptionDecl(TInfo, T,
1208 ExceptionDecl->getInnerLocStart(),
1209 ExceptionDecl->getLocation(),
1210 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001211 }
Sean Huntc3021132010-05-05 15:23:54 +00001212
James Dennett699c9042012-06-15 07:13:21 +00001213 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001214 ///
1215 /// By default, performs semantic analysis to build the new statement.
1216 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001217 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001218 SourceLocation RParenLoc,
1219 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001220 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001221 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001222 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001223 }
Sean Huntc3021132010-05-05 15:23:54 +00001224
James Dennett699c9042012-06-15 07:13:21 +00001225 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001226 ///
1227 /// By default, performs semantic analysis to build the new statement.
1228 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001229 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001230 Stmt *Body) {
1231 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001232 }
Sean Huntc3021132010-05-05 15:23:54 +00001233
James Dennett699c9042012-06-15 07:13:21 +00001234 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001235 ///
1236 /// By default, performs semantic analysis to build the new statement.
1237 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001238 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001239 Expr *Operand) {
1240 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001241 }
Sean Huntc3021132010-05-05 15:23:54 +00001242
James Dennett699c9042012-06-15 07:13:21 +00001243 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001244 ///
1245 /// By default, performs semantic analysis to build the new statement.
1246 /// Subclasses may override this routine to provide different behavior.
1247 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1248 Expr *object) {
1249 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1250 }
1251
James Dennett699c9042012-06-15 07:13:21 +00001252 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001253 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001254 /// By default, performs semantic analysis to build the new statement.
1255 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001256 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001257 Expr *Object, Stmt *Body) {
1258 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001259 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001260
James Dennett699c9042012-06-15 07:13:21 +00001261 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001262 ///
1263 /// By default, performs semantic analysis to build the new statement.
1264 /// Subclasses may override this routine to provide different behavior.
1265 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1266 Stmt *Body) {
1267 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1268 }
John McCall990567c2011-07-27 01:07:15 +00001269
Douglas Gregorc3203e72010-04-22 23:10:45 +00001270 /// \brief Build a new Objective-C fast enumeration statement.
1271 ///
1272 /// By default, performs semantic analysis to build the new statement.
1273 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001274 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001275 SourceLocation LParenLoc,
1276 Stmt *Element,
1277 Expr *Collection,
1278 SourceLocation RParenLoc,
1279 Stmt *Body) {
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001280 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
1281 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001282 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001283 RParenLoc);
1284 if (ForEachStmt.isInvalid())
1285 return StmtError();
1286
1287 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001288 }
Sean Huntc3021132010-05-05 15:23:54 +00001289
Douglas Gregor43959a92009-08-20 07:17:43 +00001290 /// \brief Build a new C++ exception declaration.
1291 ///
1292 /// By default, performs semantic analysis to build the new decaration.
1293 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001294 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001295 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001296 SourceLocation StartLoc,
1297 SourceLocation IdLoc,
1298 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001299 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1300 StartLoc, IdLoc, Id);
1301 if (Var)
1302 getSema().CurContext->addDecl(Var);
1303 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001304 }
1305
1306 /// \brief Build a new C++ catch statement.
1307 ///
1308 /// By default, performs semantic analysis to build the new statement.
1309 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001310 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001311 VarDecl *ExceptionDecl,
1312 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001313 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1314 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001315 }
Mike Stump1eb44332009-09-09 15:08:12 +00001316
Douglas Gregor43959a92009-08-20 07:17:43 +00001317 /// \brief Build a new C++ try statement.
1318 ///
1319 /// By default, performs semantic analysis to build the new statement.
1320 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001321 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001322 Stmt *TryBlock,
1323 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001324 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001325 }
Mike Stump1eb44332009-09-09 15:08:12 +00001326
Richard Smithad762fc2011-04-14 22:09:26 +00001327 /// \brief Build a new C++0x range-based for statement.
1328 ///
1329 /// By default, performs semantic analysis to build the new statement.
1330 /// Subclasses may override this routine to provide different behavior.
1331 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1332 SourceLocation ColonLoc,
1333 Stmt *Range, Stmt *BeginEnd,
1334 Expr *Cond, Expr *Inc,
1335 Stmt *LoopVar,
1336 SourceLocation RParenLoc) {
1337 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1338 Cond, Inc, LoopVar, RParenLoc);
1339 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001340
1341 /// \brief Build a new C++0x range-based for statement.
1342 ///
1343 /// By default, performs semantic analysis to build the new statement.
1344 /// Subclasses may override this routine to provide different behavior.
1345 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1346 bool IsIfExists,
1347 NestedNameSpecifierLoc QualifierLoc,
1348 DeclarationNameInfo NameInfo,
1349 Stmt *Nested) {
1350 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1351 QualifierLoc, NameInfo, Nested);
1352 }
1353
Richard Smithad762fc2011-04-14 22:09:26 +00001354 /// \brief Attach body to a C++0x range-based for statement.
1355 ///
1356 /// By default, performs semantic analysis to finish the new statement.
1357 /// Subclasses may override this routine to provide different behavior.
1358 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1359 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1360 }
1361
John Wiegley28bbe4b2011-04-28 01:08:34 +00001362 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1363 SourceLocation TryLoc,
1364 Stmt *TryBlock,
1365 Stmt *Handler) {
1366 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1367 }
1368
1369 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1370 Expr *FilterExpr,
1371 Stmt *Block) {
1372 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1373 }
1374
1375 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1376 Stmt *Block) {
1377 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1378 }
1379
Douglas Gregorb98b1992009-08-11 05:31:07 +00001380 /// \brief Build a new expression that references a declaration.
1381 ///
1382 /// By default, performs semantic analysis to build the new expression.
1383 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001384 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001385 LookupResult &R,
1386 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001387 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1388 }
1389
1390
1391 /// \brief Build a new expression that references a declaration.
1392 ///
1393 /// By default, performs semantic analysis to build the new expression.
1394 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001395 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001396 ValueDecl *VD,
1397 const DeclarationNameInfo &NameInfo,
1398 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001399 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001400 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001401
1402 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001403
1404 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001405 }
Mike Stump1eb44332009-09-09 15:08:12 +00001406
Douglas Gregorb98b1992009-08-11 05:31:07 +00001407 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001408 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 /// By default, performs semantic analysis to build the new expression.
1410 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001411 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001412 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001413 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001414 }
1415
Douglas Gregora71d8192009-09-04 17:36:40 +00001416 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001417 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001418 /// By default, performs semantic analysis to build the new expression.
1419 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001420 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001421 SourceLocation OperatorLoc,
1422 bool isArrow,
1423 CXXScopeSpec &SS,
1424 TypeSourceInfo *ScopeType,
1425 SourceLocation CCLoc,
1426 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001427 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001428
Douglas Gregorb98b1992009-08-11 05:31:07 +00001429 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001430 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001431 /// By default, performs semantic analysis to build the new expression.
1432 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001433 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001434 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001435 Expr *SubExpr) {
1436 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001437 }
Mike Stump1eb44332009-09-09 15:08:12 +00001438
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001439 /// \brief Build a new builtin offsetof expression.
1440 ///
1441 /// By default, performs semantic analysis to build the new expression.
1442 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001443 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001444 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001445 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001446 unsigned NumComponents,
1447 SourceLocation RParenLoc) {
1448 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1449 NumComponents, RParenLoc);
1450 }
Sean Huntc3021132010-05-05 15:23:54 +00001451
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001452 /// \brief Build a new sizeof, alignof or vec_step expression with a
1453 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001454 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001455 /// By default, performs semantic analysis to build the new expression.
1456 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001457 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1458 SourceLocation OpLoc,
1459 UnaryExprOrTypeTrait ExprKind,
1460 SourceRange R) {
1461 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001462 }
1463
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001464 /// \brief Build a new sizeof, alignof or vec step expression with an
1465 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001466 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001467 /// By default, performs semantic analysis to build the new expression.
1468 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001469 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1470 UnaryExprOrTypeTrait ExprKind,
1471 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001472 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001473 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001474 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001475 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001476
Douglas Gregorb98b1992009-08-11 05:31:07 +00001477 return move(Result);
1478 }
Mike Stump1eb44332009-09-09 15:08:12 +00001479
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001481 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001482 /// By default, performs semantic analysis to build the new expression.
1483 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001484 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001485 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001486 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001487 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001488 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1489 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 RBracketLoc);
1491 }
1492
1493 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001494 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 /// By default, performs semantic analysis to build the new expression.
1496 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001497 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001499 SourceLocation RParenLoc,
1500 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001501 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001502 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001503 }
1504
1505 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001506 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 /// By default, performs semantic analysis to build the new expression.
1508 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001509 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001510 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001511 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001512 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001513 const DeclarationNameInfo &MemberNameInfo,
1514 ValueDecl *Member,
1515 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001516 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001517 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001518 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1519 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001520 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001521 // We have a reference to an unnamed field. This is always the
1522 // base of an anonymous struct/union member access, i.e. the
1523 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001524 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001525 assert(Member->getType()->isRecordType() &&
1526 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001527
Richard Smith9138b4e2011-10-26 19:06:56 +00001528 BaseResult =
1529 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001530 QualifierLoc.getNestedNameSpecifier(),
1531 FoundDecl, Member);
1532 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001533 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001534 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001535 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001536 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001537 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001538 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001539 cast<FieldDecl>(Member)->getType(),
1540 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001541 return getSema().Owned(ME);
1542 }
Mike Stump1eb44332009-09-09 15:08:12 +00001543
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001544 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001545 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001546
John Wiegley429bb272011-04-08 18:41:53 +00001547 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001548 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001549
John McCall6bb80172010-03-30 21:47:33 +00001550 // FIXME: this involves duplicating earlier analysis in a lot of
1551 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001552 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001553 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001554 R.resolveKind();
1555
John McCall9ae2f072010-08-23 23:25:46 +00001556 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001557 SS, TemplateKWLoc,
1558 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001559 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001560 }
Mike Stump1eb44332009-09-09 15:08:12 +00001561
Douglas Gregorb98b1992009-08-11 05:31:07 +00001562 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001563 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001564 /// By default, performs semantic analysis to build the new expression.
1565 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001566 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001567 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001568 Expr *LHS, Expr *RHS) {
1569 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001570 }
1571
1572 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001573 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001574 /// By default, performs semantic analysis to build the new expression.
1575 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001576 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001577 SourceLocation QuestionLoc,
1578 Expr *LHS,
1579 SourceLocation ColonLoc,
1580 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001581 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1582 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001583 }
1584
Douglas Gregorb98b1992009-08-11 05:31:07 +00001585 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001586 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001587 /// By default, performs semantic analysis to build the new expression.
1588 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001589 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001590 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001591 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001592 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001593 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001594 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 }
Mike Stump1eb44332009-09-09 15:08:12 +00001596
Douglas Gregorb98b1992009-08-11 05:31:07 +00001597 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001598 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 /// By default, performs semantic analysis to build the new expression.
1600 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001601 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001602 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001604 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001605 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001606 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001607 }
Mike Stump1eb44332009-09-09 15:08:12 +00001608
Douglas Gregorb98b1992009-08-11 05:31:07 +00001609 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001610 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001611 /// By default, performs semantic analysis to build the new expression.
1612 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001613 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 SourceLocation OpLoc,
1615 SourceLocation AccessorLoc,
1616 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001617
John McCall129e2df2009-11-30 22:42:35 +00001618 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001619 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001620 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001621 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001622 SS, SourceLocation(),
1623 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001624 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001625 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001626 }
Mike Stump1eb44332009-09-09 15:08:12 +00001627
Douglas Gregorb98b1992009-08-11 05:31:07 +00001628 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001629 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001630 /// By default, performs semantic analysis to build the new expression.
1631 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001632 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001633 MultiExprArg Inits,
1634 SourceLocation RBraceLoc,
1635 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001636 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001637 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1638 if (Result.isInvalid() || ResultTy->isDependentType())
1639 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001640
Douglas Gregore48319a2009-11-09 17:16:50 +00001641 // Patch in the result type we were given, which may have been computed
1642 // when the initial InitListExpr was built.
1643 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1644 ILE->setType(ResultTy);
1645 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 }
Mike Stump1eb44332009-09-09 15:08:12 +00001647
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001649 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001650 /// By default, performs semantic analysis to build the new expression.
1651 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001652 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 MultiExprArg ArrayExprs,
1654 SourceLocation EqualOrColonLoc,
1655 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001656 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001657 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001659 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001660 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001661 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001662
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 ArrayExprs.release();
1664 return move(Result);
1665 }
Mike Stump1eb44332009-09-09 15:08:12 +00001666
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001668 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 /// By default, builds the implicit value initialization without performing
1670 /// any semantic analysis. Subclasses may override this routine to provide
1671 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001672 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1674 }
Mike Stump1eb44332009-09-09 15:08:12 +00001675
Douglas Gregorb98b1992009-08-11 05:31:07 +00001676 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001677 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001678 /// By default, performs semantic analysis to build the new expression.
1679 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001680 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001681 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001682 SourceLocation RParenLoc) {
1683 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001684 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001685 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001686 }
1687
1688 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001689 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001690 /// By default, performs semantic analysis to build the new expression.
1691 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001692 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001693 MultiExprArg SubExprs,
1694 SourceLocation RParenLoc) {
1695 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 }
Mike Stump1eb44332009-09-09 15:08:12 +00001697
Douglas Gregorb98b1992009-08-11 05:31:07 +00001698 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001699 ///
1700 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001701 /// rather than attempting to map the label statement itself.
1702 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001703 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001704 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001705 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001706 }
Mike Stump1eb44332009-09-09 15:08:12 +00001707
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001709 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 /// By default, performs semantic analysis to build the new expression.
1711 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001712 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001713 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001714 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001715 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001716 }
Mike Stump1eb44332009-09-09 15:08:12 +00001717
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 /// \brief Build a new __builtin_choose_expr expression.
1719 ///
1720 /// By default, performs semantic analysis to build the new expression.
1721 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001722 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001723 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001724 SourceLocation RParenLoc) {
1725 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001726 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001727 RParenLoc);
1728 }
Mike Stump1eb44332009-09-09 15:08:12 +00001729
Peter Collingbournef111d932011-04-15 00:35:48 +00001730 /// \brief Build a new generic selection expression.
1731 ///
1732 /// By default, performs semantic analysis to build the new expression.
1733 /// Subclasses may override this routine to provide different behavior.
1734 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1735 SourceLocation DefaultLoc,
1736 SourceLocation RParenLoc,
1737 Expr *ControllingExpr,
1738 TypeSourceInfo **Types,
1739 Expr **Exprs,
1740 unsigned NumAssocs) {
1741 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1742 ControllingExpr, Types, Exprs,
1743 NumAssocs);
1744 }
1745
Douglas Gregorb98b1992009-08-11 05:31:07 +00001746 /// \brief Build a new overloaded operator call expression.
1747 ///
1748 /// By default, performs semantic analysis to build the new expression.
1749 /// The semantic analysis provides the behavior of template instantiation,
1750 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001751 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001752 /// argument-dependent lookup, etc. Subclasses may override this routine to
1753 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001754 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001756 Expr *Callee,
1757 Expr *First,
1758 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001759
1760 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001761 /// reinterpret_cast.
1762 ///
1763 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001764 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001766 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001767 Stmt::StmtClass Class,
1768 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001769 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001770 SourceLocation RAngleLoc,
1771 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001772 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001773 SourceLocation RParenLoc) {
1774 switch (Class) {
1775 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001776 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001777 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001778 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001779
1780 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001781 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001782 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001783 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001784
Douglas Gregorb98b1992009-08-11 05:31:07 +00001785 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001786 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001787 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001788 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001790
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001792 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001793 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001794 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001795
Douglas Gregorb98b1992009-08-11 05:31:07 +00001796 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001797 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001798 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 }
Mike Stump1eb44332009-09-09 15:08:12 +00001800
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 /// \brief Build a new C++ static_cast expression.
1802 ///
1803 /// By default, performs semantic analysis to build the new expression.
1804 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001805 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001807 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001808 SourceLocation RAngleLoc,
1809 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001810 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001812 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001813 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001814 SourceRange(LAngleLoc, RAngleLoc),
1815 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001816 }
1817
1818 /// \brief Build a new C++ dynamic_cast expression.
1819 ///
1820 /// By default, performs semantic analysis to build the new expression.
1821 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001822 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001823 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001824 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001825 SourceLocation RAngleLoc,
1826 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001827 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001828 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001829 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001830 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001831 SourceRange(LAngleLoc, RAngleLoc),
1832 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001833 }
1834
1835 /// \brief Build a new C++ reinterpret_cast expression.
1836 ///
1837 /// By default, performs semantic analysis to build the new expression.
1838 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001839 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001840 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001841 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001842 SourceLocation RAngleLoc,
1843 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001844 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001845 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001846 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001847 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001848 SourceRange(LAngleLoc, RAngleLoc),
1849 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001850 }
1851
1852 /// \brief Build a new C++ const_cast expression.
1853 ///
1854 /// By default, performs semantic analysis to build the new expression.
1855 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001856 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001857 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001858 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001859 SourceLocation RAngleLoc,
1860 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001861 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001862 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001863 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001864 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001865 SourceRange(LAngleLoc, RAngleLoc),
1866 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001867 }
Mike Stump1eb44332009-09-09 15:08:12 +00001868
Douglas Gregorb98b1992009-08-11 05:31:07 +00001869 /// \brief Build a new C++ functional-style cast expression.
1870 ///
1871 /// By default, performs semantic analysis to build the new expression.
1872 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001873 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1874 SourceLocation LParenLoc,
1875 Expr *Sub,
1876 SourceLocation RParenLoc) {
1877 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001878 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001879 RParenLoc);
1880 }
Mike Stump1eb44332009-09-09 15:08:12 +00001881
Douglas Gregorb98b1992009-08-11 05:31:07 +00001882 /// \brief Build a new C++ typeid(type) expression.
1883 ///
1884 /// By default, performs semantic analysis to build the new expression.
1885 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001886 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001887 SourceLocation TypeidLoc,
1888 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001890 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001891 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001892 }
Mike Stump1eb44332009-09-09 15:08:12 +00001893
Francois Pichet01b7c302010-09-08 12:20:18 +00001894
Douglas Gregorb98b1992009-08-11 05:31:07 +00001895 /// \brief Build a new C++ typeid(expr) expression.
1896 ///
1897 /// By default, performs semantic analysis to build the new expression.
1898 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001899 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001900 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001901 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001902 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001903 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001904 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001905 }
1906
Francois Pichet01b7c302010-09-08 12:20:18 +00001907 /// \brief Build a new C++ __uuidof(type) expression.
1908 ///
1909 /// By default, performs semantic analysis to build the new expression.
1910 /// Subclasses may override this routine to provide different behavior.
1911 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1912 SourceLocation TypeidLoc,
1913 TypeSourceInfo *Operand,
1914 SourceLocation RParenLoc) {
1915 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1916 RParenLoc);
1917 }
1918
1919 /// \brief Build a new C++ __uuidof(expr) expression.
1920 ///
1921 /// By default, performs semantic analysis to build the new expression.
1922 /// Subclasses may override this routine to provide different behavior.
1923 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1924 SourceLocation TypeidLoc,
1925 Expr *Operand,
1926 SourceLocation RParenLoc) {
1927 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1928 RParenLoc);
1929 }
1930
Douglas Gregorb98b1992009-08-11 05:31:07 +00001931 /// \brief Build a new C++ "this" expression.
1932 ///
1933 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001934 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001936 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001937 QualType ThisType,
1938 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001939 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001940 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001941 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1942 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001943 }
1944
1945 /// \brief Build a new C++ throw expression.
1946 ///
1947 /// By default, performs semantic analysis to build the new expression.
1948 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001949 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1950 bool IsThrownVariableInScope) {
1951 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952 }
1953
1954 /// \brief Build a new C++ default-argument expression.
1955 ///
1956 /// By default, builds a new default-argument expression, which does not
1957 /// require any semantic analysis. Subclasses may override this routine to
1958 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001959 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001960 ParmVarDecl *Param) {
1961 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1962 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001963 }
1964
1965 /// \brief Build a new C++ zero-initialization expression.
1966 ///
1967 /// By default, performs semantic analysis to build the new expression.
1968 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001969 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1970 SourceLocation LParenLoc,
1971 SourceLocation RParenLoc) {
1972 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001973 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001974 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001975 }
Mike Stump1eb44332009-09-09 15:08:12 +00001976
Douglas Gregorb98b1992009-08-11 05:31:07 +00001977 /// \brief Build a new C++ "new" expression.
1978 ///
1979 /// By default, performs semantic analysis to build the new expression.
1980 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001981 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001982 bool UseGlobal,
1983 SourceLocation PlacementLParen,
1984 MultiExprArg PlacementArgs,
1985 SourceLocation PlacementRParen,
1986 SourceRange TypeIdParens,
1987 QualType AllocatedType,
1988 TypeSourceInfo *AllocatedTypeInfo,
1989 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001990 SourceRange DirectInitRange,
1991 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001992 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001993 PlacementLParen,
1994 move(PlacementArgs),
1995 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001996 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001997 AllocatedType,
1998 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001999 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002000 DirectInitRange,
2001 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002002 }
Mike Stump1eb44332009-09-09 15:08:12 +00002003
Douglas Gregorb98b1992009-08-11 05:31:07 +00002004 /// \brief Build a new C++ "delete" expression.
2005 ///
2006 /// By default, performs semantic analysis to build the new expression.
2007 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002008 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002009 bool IsGlobalDelete,
2010 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002011 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002012 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002013 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002014 }
Mike Stump1eb44332009-09-09 15:08:12 +00002015
Douglas Gregorb98b1992009-08-11 05:31:07 +00002016 /// \brief Build a new unary type trait expression.
2017 ///
2018 /// By default, performs semantic analysis to build the new expression.
2019 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002020 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002021 SourceLocation StartLoc,
2022 TypeSourceInfo *T,
2023 SourceLocation RParenLoc) {
2024 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002025 }
2026
Francois Pichet6ad6f282010-12-07 00:08:36 +00002027 /// \brief Build a new binary type trait expression.
2028 ///
2029 /// By default, performs semantic analysis to build the new expression.
2030 /// Subclasses may override this routine to provide different behavior.
2031 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2032 SourceLocation StartLoc,
2033 TypeSourceInfo *LhsT,
2034 TypeSourceInfo *RhsT,
2035 SourceLocation RParenLoc) {
2036 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2037 }
2038
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002039 /// \brief Build a new type trait expression.
2040 ///
2041 /// By default, performs semantic analysis to build the new expression.
2042 /// Subclasses may override this routine to provide different behavior.
2043 ExprResult RebuildTypeTrait(TypeTrait Trait,
2044 SourceLocation StartLoc,
2045 ArrayRef<TypeSourceInfo *> Args,
2046 SourceLocation RParenLoc) {
2047 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2048 }
2049
John Wiegley21ff2e52011-04-28 00:16:57 +00002050 /// \brief Build a new array type trait expression.
2051 ///
2052 /// By default, performs semantic analysis to build the new expression.
2053 /// Subclasses may override this routine to provide different behavior.
2054 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2055 SourceLocation StartLoc,
2056 TypeSourceInfo *TSInfo,
2057 Expr *DimExpr,
2058 SourceLocation RParenLoc) {
2059 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2060 }
2061
John Wiegley55262202011-04-25 06:54:41 +00002062 /// \brief Build a new expression trait expression.
2063 ///
2064 /// By default, performs semantic analysis to build the new expression.
2065 /// Subclasses may override this routine to provide different behavior.
2066 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2067 SourceLocation StartLoc,
2068 Expr *Queried,
2069 SourceLocation RParenLoc) {
2070 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2071 }
2072
Mike Stump1eb44332009-09-09 15:08:12 +00002073 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002074 /// expression.
2075 ///
2076 /// By default, performs semantic analysis to build the new expression.
2077 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002078 ExprResult RebuildDependentScopeDeclRefExpr(
2079 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002080 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002081 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002082 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002083 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002084 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002085
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002086 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002087 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002088 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002089
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002090 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002091 }
2092
2093 /// \brief Build a new template-id expression.
2094 ///
2095 /// By default, performs semantic analysis to build the new expression.
2096 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002097 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002098 SourceLocation TemplateKWLoc,
2099 LookupResult &R,
2100 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002101 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002102 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2103 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002104 }
2105
2106 /// \brief Build a new object-construction expression.
2107 ///
2108 /// By default, performs semantic analysis to build the new expression.
2109 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002110 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002111 SourceLocation Loc,
2112 CXXConstructorDecl *Constructor,
2113 bool IsElidable,
2114 MultiExprArg Args,
2115 bool HadMultipleCandidates,
2116 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002117 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002118 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002119 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002120 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002121 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002122 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002123
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002124 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002125 move_arg(ConvertedArgs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002126 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002127 RequiresZeroInit, ConstructKind,
2128 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002129 }
2130
2131 /// \brief Build a new object-construction expression.
2132 ///
2133 /// By default, performs semantic analysis to build the new expression.
2134 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002135 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2136 SourceLocation LParenLoc,
2137 MultiExprArg Args,
2138 SourceLocation RParenLoc) {
2139 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002140 LParenLoc,
2141 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002142 RParenLoc);
2143 }
2144
2145 /// \brief Build a new object-construction expression.
2146 ///
2147 /// By default, performs semantic analysis to build the new expression.
2148 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002149 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2150 SourceLocation LParenLoc,
2151 MultiExprArg Args,
2152 SourceLocation RParenLoc) {
2153 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002154 LParenLoc,
2155 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002156 RParenLoc);
2157 }
Mike Stump1eb44332009-09-09 15:08:12 +00002158
Douglas Gregorb98b1992009-08-11 05:31:07 +00002159 /// \brief Build a new member reference expression.
2160 ///
2161 /// By default, performs semantic analysis to build the new expression.
2162 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002163 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002164 QualType BaseType,
2165 bool IsArrow,
2166 SourceLocation OperatorLoc,
2167 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002168 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002169 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002170 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002171 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002172 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002173 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002174
John McCall9ae2f072010-08-23 23:25:46 +00002175 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002176 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002177 SS, TemplateKWLoc,
2178 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002179 MemberNameInfo,
2180 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002181 }
2182
John McCall129e2df2009-11-30 22:42:35 +00002183 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002184 ///
2185 /// By default, performs semantic analysis to build the new expression.
2186 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002187 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2188 SourceLocation OperatorLoc,
2189 bool IsArrow,
2190 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002191 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002192 NamedDecl *FirstQualifierInScope,
2193 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002194 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002195 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002196 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002197
John McCall9ae2f072010-08-23 23:25:46 +00002198 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002199 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002200 SS, TemplateKWLoc,
2201 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002202 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002203 }
Mike Stump1eb44332009-09-09 15:08:12 +00002204
Sebastian Redl2e156222010-09-10 20:55:43 +00002205 /// \brief Build a new noexcept expression.
2206 ///
2207 /// By default, performs semantic analysis to build the new expression.
2208 /// Subclasses may override this routine to provide different behavior.
2209 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2210 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2211 }
2212
Douglas Gregoree8aff02011-01-04 17:33:58 +00002213 /// \brief Build a new expression to compute the length of a parameter pack.
2214 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2215 SourceLocation PackLoc,
2216 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002217 llvm::Optional<unsigned> Length) {
2218 if (Length)
2219 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2220 OperatorLoc, Pack, PackLoc,
2221 RParenLoc, *Length);
2222
Douglas Gregoree8aff02011-01-04 17:33:58 +00002223 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2224 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002225 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002226 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002227
Patrick Beardeb382ec2012-04-19 00:25:12 +00002228 /// \brief Build a new Objective-C boxed expression.
2229 ///
2230 /// By default, performs semantic analysis to build the new expression.
2231 /// Subclasses may override this routine to provide different behavior.
2232 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2233 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2234 }
2235
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002236 /// \brief Build a new Objective-C array literal.
2237 ///
2238 /// By default, performs semantic analysis to build the new expression.
2239 /// Subclasses may override this routine to provide different behavior.
2240 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2241 Expr **Elements, unsigned NumElements) {
2242 return getSema().BuildObjCArrayLiteral(Range,
2243 MultiExprArg(Elements, NumElements));
2244 }
2245
2246 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
2247 Expr *Base, Expr *Key,
2248 ObjCMethodDecl *getterMethod,
2249 ObjCMethodDecl *setterMethod) {
2250 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2251 getterMethod, setterMethod);
2252 }
2253
2254 /// \brief Build a new Objective-C dictionary literal.
2255 ///
2256 /// By default, performs semantic analysis to build the new expression.
2257 /// Subclasses may override this routine to provide different behavior.
2258 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2259 ObjCDictionaryElement *Elements,
2260 unsigned NumElements) {
2261 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2262 }
2263
James Dennett699c9042012-06-15 07:13:21 +00002264 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002265 ///
2266 /// By default, performs semantic analysis to build the new expression.
2267 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002268 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002269 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002270 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002271 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002272 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002273 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002274
Douglas Gregor92e986e2010-04-22 16:44:27 +00002275 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002276 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002277 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002278 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002279 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002280 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002281 MultiExprArg Args,
2282 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002283 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2284 ReceiverTypeInfo->getType(),
2285 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002286 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002287 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002288 }
2289
2290 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002291 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002292 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002293 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002294 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002295 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002296 MultiExprArg Args,
2297 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002298 return SemaRef.BuildInstanceMessage(Receiver,
2299 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002300 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002301 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002302 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002303 }
2304
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002305 /// \brief Build a new Objective-C ivar reference expression.
2306 ///
2307 /// By default, performs semantic analysis to build the new expression.
2308 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002309 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002310 SourceLocation IvarLoc,
2311 bool IsArrow, bool IsFreeIvar) {
2312 // FIXME: We lose track of the IsFreeIvar bit.
2313 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002314 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002315 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2316 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002317 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002318 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002319 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002320 false);
John Wiegley429bb272011-04-08 18:41:53 +00002321 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002322 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002323
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002324 if (Result.get())
2325 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002326
John Wiegley429bb272011-04-08 18:41:53 +00002327 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002328 /*FIXME:*/IvarLoc, IsArrow,
2329 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002330 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002331 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002332 /*TemplateArgs=*/0);
2333 }
Douglas Gregore3303542010-04-26 20:47:02 +00002334
2335 /// \brief Build a new Objective-C property reference expression.
2336 ///
2337 /// By default, performs semantic analysis to build the new expression.
2338 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002339 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002340 ObjCPropertyDecl *Property,
2341 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002342 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002343 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002344 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2345 Sema::LookupMemberName);
2346 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002347 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002348 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002349 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002350 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002351 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002352
Douglas Gregore3303542010-04-26 20:47:02 +00002353 if (Result.get())
2354 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002355
John Wiegley429bb272011-04-08 18:41:53 +00002356 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002357 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002358 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002359 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002360 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002361 /*TemplateArgs=*/0);
2362 }
Sean Huntc3021132010-05-05 15:23:54 +00002363
John McCall12f78a62010-12-02 01:19:52 +00002364 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002365 ///
2366 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002367 /// Subclasses may override this routine to provide different behavior.
2368 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2369 ObjCMethodDecl *Getter,
2370 ObjCMethodDecl *Setter,
2371 SourceLocation PropertyLoc) {
2372 // Since these expressions can only be value-dependent, we do not
2373 // need to perform semantic analysis again.
2374 return Owned(
2375 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2376 VK_LValue, OK_ObjCProperty,
2377 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002378 }
2379
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002380 /// \brief Build a new Objective-C "isa" expression.
2381 ///
2382 /// By default, performs semantic analysis to build the new expression.
2383 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002384 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002385 bool IsArrow) {
2386 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002387 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002388 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2389 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002390 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002391 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002392 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002393 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002394 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002395
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002396 if (Result.get())
2397 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002398
John Wiegley429bb272011-04-08 18:41:53 +00002399 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002400 /*FIXME:*/IsaLoc, IsArrow,
2401 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002402 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002403 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002404 /*TemplateArgs=*/0);
2405 }
Sean Huntc3021132010-05-05 15:23:54 +00002406
Douglas Gregorb98b1992009-08-11 05:31:07 +00002407 /// \brief Build a new shuffle vector expression.
2408 ///
2409 /// By default, performs semantic analysis to build the new expression.
2410 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002411 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002412 MultiExprArg SubExprs,
2413 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002414 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002415 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002416 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2417 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2418 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2419 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002420
Douglas Gregorb98b1992009-08-11 05:31:07 +00002421 // Build a reference to the __builtin_shufflevector builtin
2422 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002423 ExprResult Callee
John McCallf4b88a42012-03-10 09:33:50 +00002424 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false,
2425 Builtin->getType(),
John Wiegley429bb272011-04-08 18:41:53 +00002426 VK_LValue, BuiltinLoc));
2427 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2428 if (Callee.isInvalid())
2429 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002430
2431 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002432 unsigned NumSubExprs = SubExprs.size();
2433 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002434 ExprResult TheCall = SemaRef.Owned(
2435 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002436 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002437 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002438 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002439 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002440
Douglas Gregorb98b1992009-08-11 05:31:07 +00002441 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002442 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002443 }
John McCall43fed0d2010-11-12 08:19:04 +00002444
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002445 /// \brief Build a new template argument pack expansion.
2446 ///
2447 /// By default, performs semantic analysis to build a new pack expansion
2448 /// for a template argument. Subclasses may override this routine to provide
2449 /// different behavior.
2450 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002451 SourceLocation EllipsisLoc,
2452 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002453 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002454 case TemplateArgument::Expression: {
2455 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002456 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2457 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002458 if (Result.isInvalid())
2459 return TemplateArgumentLoc();
2460
2461 return TemplateArgumentLoc(Result.get(), Result.get());
2462 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002463
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002464 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002465 return TemplateArgumentLoc(TemplateArgument(
2466 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002467 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002468 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002469 Pattern.getTemplateNameLoc(),
2470 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002471
2472 case TemplateArgument::Null:
2473 case TemplateArgument::Integral:
2474 case TemplateArgument::Declaration:
2475 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002476 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002477 llvm_unreachable("Pack expansion pattern has no parameter packs");
2478
2479 case TemplateArgument::Type:
2480 if (TypeSourceInfo *Expansion
2481 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002482 EllipsisLoc,
2483 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002484 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2485 Expansion);
2486 break;
2487 }
2488
2489 return TemplateArgumentLoc();
2490 }
2491
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002492 /// \brief Build a new expression pack expansion.
2493 ///
2494 /// By default, performs semantic analysis to build a new pack expansion
2495 /// for an expression. Subclasses may override this routine to provide
2496 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002497 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2498 llvm::Optional<unsigned> NumExpansions) {
2499 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002500 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002501
2502 /// \brief Build a new atomic operation expression.
2503 ///
2504 /// By default, performs semantic analysis to build the new expression.
2505 /// Subclasses may override this routine to provide different behavior.
2506 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2507 MultiExprArg SubExprs,
2508 QualType RetTy,
2509 AtomicExpr::AtomicOp Op,
2510 SourceLocation RParenLoc) {
2511 // Just create the expression; there is not any interesting semantic
2512 // analysis here because we can't actually build an AtomicExpr until
2513 // we are sure it is semantically sound.
2514 unsigned NumSubExprs = SubExprs.size();
2515 Expr **Subs = (Expr **)SubExprs.release();
2516 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2517 NumSubExprs, RetTy, Op,
2518 RParenLoc);
2519 }
2520
John McCall43fed0d2010-11-12 08:19:04 +00002521private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002522 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2523 QualType ObjectType,
2524 NamedDecl *FirstQualifierInScope,
2525 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002526
2527 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2528 QualType ObjectType,
2529 NamedDecl *FirstQualifierInScope,
2530 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002531};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002532
Douglas Gregor43959a92009-08-20 07:17:43 +00002533template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002534StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002535 if (!S)
2536 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002537
Douglas Gregor43959a92009-08-20 07:17:43 +00002538 switch (S->getStmtClass()) {
2539 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002540
Douglas Gregor43959a92009-08-20 07:17:43 +00002541 // Transform individual statement nodes
2542#define STMT(Node, Parent) \
2543 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002544#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002545#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002546#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002547
Douglas Gregor43959a92009-08-20 07:17:43 +00002548 // Transform expressions by calling TransformExpr.
2549#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002550#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002551#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002552#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002553 {
John McCall60d7b3a2010-08-24 06:29:42 +00002554 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002555 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002556 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002557
John McCall9ae2f072010-08-23 23:25:46 +00002558 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002559 }
Mike Stump1eb44332009-09-09 15:08:12 +00002560 }
2561
John McCall3fa5cae2010-10-26 07:05:15 +00002562 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002563}
Mike Stump1eb44332009-09-09 15:08:12 +00002564
2565
Douglas Gregor670444e2009-08-04 22:27:00 +00002566template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002567ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002568 if (!E)
2569 return SemaRef.Owned(E);
2570
2571 switch (E->getStmtClass()) {
2572 case Stmt::NoStmtClass: break;
2573#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002574#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002575#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002576 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002577#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002578 }
2579
John McCall3fa5cae2010-10-26 07:05:15 +00002580 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002581}
2582
2583template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002584bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2585 unsigned NumInputs,
2586 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002587 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002588 bool *ArgChanged) {
2589 for (unsigned I = 0; I != NumInputs; ++I) {
2590 // If requested, drop call arguments that need to be dropped.
2591 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2592 if (ArgChanged)
2593 *ArgChanged = true;
2594
2595 break;
2596 }
2597
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002598 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2599 Expr *Pattern = Expansion->getPattern();
2600
Chris Lattner686775d2011-07-20 06:58:45 +00002601 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002602 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2603 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2604
2605 // Determine whether the set of unexpanded parameter packs can and should
2606 // be expanded.
2607 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002608 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002609 llvm::Optional<unsigned> OrigNumExpansions
2610 = Expansion->getNumExpansions();
2611 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002612 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2613 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002614 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002615 Expand, RetainExpansion,
2616 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002617 return true;
2618
2619 if (!Expand) {
2620 // The transform has determined that we should perform a simple
2621 // transformation on the pack expansion, producing another pack
2622 // expansion.
2623 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2624 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2625 if (OutPattern.isInvalid())
2626 return true;
2627
2628 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002629 Expansion->getEllipsisLoc(),
2630 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002631 if (Out.isInvalid())
2632 return true;
2633
2634 if (ArgChanged)
2635 *ArgChanged = true;
2636 Outputs.push_back(Out.get());
2637 continue;
2638 }
John McCallc8fc90a2011-07-06 07:30:07 +00002639
2640 // Record right away that the argument was changed. This needs
2641 // to happen even if the array expands to nothing.
2642 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002643
2644 // The transform has determined that we should perform an elementwise
2645 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002646 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002647 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2648 ExprResult Out = getDerived().TransformExpr(Pattern);
2649 if (Out.isInvalid())
2650 return true;
2651
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002652 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002653 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2654 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002655 if (Out.isInvalid())
2656 return true;
2657 }
2658
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002659 Outputs.push_back(Out.get());
2660 }
2661
2662 continue;
2663 }
2664
Douglas Gregoraa165f82011-01-03 19:04:46 +00002665 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2666 if (Result.isInvalid())
2667 return true;
2668
2669 if (Result.get() != Inputs[I] && ArgChanged)
2670 *ArgChanged = true;
2671
2672 Outputs.push_back(Result.get());
2673 }
2674
2675 return false;
2676}
2677
2678template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002679NestedNameSpecifierLoc
2680TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2681 NestedNameSpecifierLoc NNS,
2682 QualType ObjectType,
2683 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002684 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002685 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2686 Qualifier = Qualifier.getPrefix())
2687 Qualifiers.push_back(Qualifier);
2688
2689 CXXScopeSpec SS;
2690 while (!Qualifiers.empty()) {
2691 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2692 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2693
2694 switch (QNNS->getKind()) {
2695 case NestedNameSpecifier::Identifier:
2696 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2697 *QNNS->getAsIdentifier(),
2698 Q.getLocalBeginLoc(),
2699 Q.getLocalEndLoc(),
2700 ObjectType, false, SS,
2701 FirstQualifierInScope, false))
2702 return NestedNameSpecifierLoc();
2703
2704 break;
2705
2706 case NestedNameSpecifier::Namespace: {
2707 NamespaceDecl *NS
2708 = cast_or_null<NamespaceDecl>(
2709 getDerived().TransformDecl(
2710 Q.getLocalBeginLoc(),
2711 QNNS->getAsNamespace()));
2712 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2713 break;
2714 }
2715
2716 case NestedNameSpecifier::NamespaceAlias: {
2717 NamespaceAliasDecl *Alias
2718 = cast_or_null<NamespaceAliasDecl>(
2719 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2720 QNNS->getAsNamespaceAlias()));
2721 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2722 Q.getLocalEndLoc());
2723 break;
2724 }
2725
2726 case NestedNameSpecifier::Global:
2727 // There is no meaningful transformation that one could perform on the
2728 // global scope.
2729 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2730 break;
2731
2732 case NestedNameSpecifier::TypeSpecWithTemplate:
2733 case NestedNameSpecifier::TypeSpec: {
2734 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2735 FirstQualifierInScope, SS);
2736
2737 if (!TL)
2738 return NestedNameSpecifierLoc();
2739
2740 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
David Blaikie4e4d0842012-03-11 07:00:24 +00002741 (SemaRef.getLangOpts().CPlusPlus0x &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002742 TL.getType()->isEnumeralType())) {
2743 assert(!TL.getType().hasLocalQualifiers() &&
2744 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002745 if (TL.getType()->isEnumeralType())
2746 SemaRef.Diag(TL.getBeginLoc(),
2747 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002748 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2749 Q.getLocalEndLoc());
2750 break;
2751 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002752 // If the nested-name-specifier is an invalid type def, don't emit an
2753 // error because a previous error should have already been emitted.
2754 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2755 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2756 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2757 << TL.getType() << SS.getRange();
2758 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002759 return NestedNameSpecifierLoc();
2760 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002761 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002762
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002763 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002764 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002765 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002766 }
2767
2768 // Don't rebuild the nested-name-specifier if we don't have to.
2769 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2770 !getDerived().AlwaysRebuild())
2771 return NNS;
2772
2773 // If we can re-use the source-location data from the original
2774 // nested-name-specifier, do so.
2775 if (SS.location_size() == NNS.getDataLength() &&
2776 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2777 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2778
2779 // Allocate new nested-name-specifier location information.
2780 return SS.getWithLocInContext(SemaRef.Context);
2781}
2782
2783template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002784DeclarationNameInfo
2785TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002786::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002787 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002788 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002789 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002790
2791 switch (Name.getNameKind()) {
2792 case DeclarationName::Identifier:
2793 case DeclarationName::ObjCZeroArgSelector:
2794 case DeclarationName::ObjCOneArgSelector:
2795 case DeclarationName::ObjCMultiArgSelector:
2796 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002797 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002798 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002799 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002800
Douglas Gregor81499bb2009-09-03 22:13:48 +00002801 case DeclarationName::CXXConstructorName:
2802 case DeclarationName::CXXDestructorName:
2803 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002804 TypeSourceInfo *NewTInfo;
2805 CanQualType NewCanTy;
2806 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002807 NewTInfo = getDerived().TransformType(OldTInfo);
2808 if (!NewTInfo)
2809 return DeclarationNameInfo();
2810 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002811 }
2812 else {
2813 NewTInfo = 0;
2814 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002815 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002816 if (NewT.isNull())
2817 return DeclarationNameInfo();
2818 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2819 }
Mike Stump1eb44332009-09-09 15:08:12 +00002820
Abramo Bagnara25777432010-08-11 22:01:17 +00002821 DeclarationName NewName
2822 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2823 NewCanTy);
2824 DeclarationNameInfo NewNameInfo(NameInfo);
2825 NewNameInfo.setName(NewName);
2826 NewNameInfo.setNamedTypeInfo(NewTInfo);
2827 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002828 }
Mike Stump1eb44332009-09-09 15:08:12 +00002829 }
2830
David Blaikieb219cfc2011-09-23 05:06:16 +00002831 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002832}
2833
2834template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002835TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002836TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2837 TemplateName Name,
2838 SourceLocation NameLoc,
2839 QualType ObjectType,
2840 NamedDecl *FirstQualifierInScope) {
2841 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2842 TemplateDecl *Template = QTN->getTemplateDecl();
2843 assert(Template && "qualified template name must refer to a template");
2844
2845 TemplateDecl *TransTemplate
2846 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2847 Template));
2848 if (!TransTemplate)
2849 return TemplateName();
2850
2851 if (!getDerived().AlwaysRebuild() &&
2852 SS.getScopeRep() == QTN->getQualifier() &&
2853 TransTemplate == Template)
2854 return Name;
2855
2856 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2857 TransTemplate);
2858 }
2859
2860 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2861 if (SS.getScopeRep()) {
2862 // These apply to the scope specifier, not the template.
2863 ObjectType = QualType();
2864 FirstQualifierInScope = 0;
2865 }
2866
2867 if (!getDerived().AlwaysRebuild() &&
2868 SS.getScopeRep() == DTN->getQualifier() &&
2869 ObjectType.isNull())
2870 return Name;
2871
2872 if (DTN->isIdentifier()) {
2873 return getDerived().RebuildTemplateName(SS,
2874 *DTN->getIdentifier(),
2875 NameLoc,
2876 ObjectType,
2877 FirstQualifierInScope);
2878 }
2879
2880 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2881 ObjectType);
2882 }
2883
2884 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2885 TemplateDecl *TransTemplate
2886 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2887 Template));
2888 if (!TransTemplate)
2889 return TemplateName();
2890
2891 if (!getDerived().AlwaysRebuild() &&
2892 TransTemplate == Template)
2893 return Name;
2894
2895 return TemplateName(TransTemplate);
2896 }
2897
2898 if (SubstTemplateTemplateParmPackStorage *SubstPack
2899 = Name.getAsSubstTemplateTemplateParmPack()) {
2900 TemplateTemplateParmDecl *TransParam
2901 = cast_or_null<TemplateTemplateParmDecl>(
2902 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2903 if (!TransParam)
2904 return TemplateName();
2905
2906 if (!getDerived().AlwaysRebuild() &&
2907 TransParam == SubstPack->getParameterPack())
2908 return Name;
2909
2910 return getDerived().RebuildTemplateName(TransParam,
2911 SubstPack->getArgumentPack());
2912 }
2913
2914 // These should be getting filtered out before they reach the AST.
2915 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002916}
2917
2918template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002919void TreeTransform<Derived>::InventTemplateArgumentLoc(
2920 const TemplateArgument &Arg,
2921 TemplateArgumentLoc &Output) {
2922 SourceLocation Loc = getDerived().getBaseLocation();
2923 switch (Arg.getKind()) {
2924 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002925 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002926 break;
2927
2928 case TemplateArgument::Type:
2929 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002930 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002931
John McCall833ca992009-10-29 08:12:44 +00002932 break;
2933
Douglas Gregor788cd062009-11-11 01:00:40 +00002934 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002935 case TemplateArgument::TemplateExpansion: {
2936 NestedNameSpecifierLocBuilder Builder;
2937 TemplateName Template = Arg.getAsTemplate();
2938 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2939 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2940 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2941 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2942
2943 if (Arg.getKind() == TemplateArgument::Template)
2944 Output = TemplateArgumentLoc(Arg,
2945 Builder.getWithLocInContext(SemaRef.Context),
2946 Loc);
2947 else
2948 Output = TemplateArgumentLoc(Arg,
2949 Builder.getWithLocInContext(SemaRef.Context),
2950 Loc, Loc);
2951
Douglas Gregor788cd062009-11-11 01:00:40 +00002952 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002953 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002954
John McCall833ca992009-10-29 08:12:44 +00002955 case TemplateArgument::Expression:
2956 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2957 break;
2958
2959 case TemplateArgument::Declaration:
2960 case TemplateArgument::Integral:
2961 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002962 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002963 break;
2964 }
2965}
2966
2967template<typename Derived>
2968bool TreeTransform<Derived>::TransformTemplateArgument(
2969 const TemplateArgumentLoc &Input,
2970 TemplateArgumentLoc &Output) {
2971 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002972 switch (Arg.getKind()) {
2973 case TemplateArgument::Null:
2974 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002975 Output = Input;
2976 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002977
Douglas Gregor670444e2009-08-04 22:27:00 +00002978 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002979 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002980 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002981 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002982
2983 DI = getDerived().TransformType(DI);
2984 if (!DI) return true;
2985
2986 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2987 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002988 }
Mike Stump1eb44332009-09-09 15:08:12 +00002989
Douglas Gregor670444e2009-08-04 22:27:00 +00002990 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002991 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002992 DeclarationName Name;
2993 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2994 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002995 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002996 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002997 if (!D) return true;
2998
John McCall828bff22009-10-29 18:45:58 +00002999 Expr *SourceExpr = Input.getSourceDeclExpression();
3000 if (SourceExpr) {
3001 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003002 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00003003 ExprResult E = getDerived().TransformExpr(SourceExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003004 E = SemaRef.ActOnConstantExpression(E);
John McCall9ae2f072010-08-23 23:25:46 +00003005 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00003006 }
3007
3008 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00003009 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003010 }
Mike Stump1eb44332009-09-09 15:08:12 +00003011
Douglas Gregor788cd062009-11-11 01:00:40 +00003012 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003013 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3014 if (QualifierLoc) {
3015 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3016 if (!QualifierLoc)
3017 return true;
3018 }
3019
Douglas Gregor1d752d72011-03-02 18:46:51 +00003020 CXXScopeSpec SS;
3021 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003022 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003023 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3024 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003025 if (Template.isNull())
3026 return true;
Sean Huntc3021132010-05-05 15:23:54 +00003027
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003028 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003029 Input.getTemplateNameLoc());
3030 return false;
3031 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003032
3033 case TemplateArgument::TemplateExpansion:
3034 llvm_unreachable("Caller should expand pack expansions");
3035
Douglas Gregor670444e2009-08-04 22:27:00 +00003036 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003037 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003038 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003039 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003040
John McCall833ca992009-10-29 08:12:44 +00003041 Expr *InputExpr = Input.getSourceExpression();
3042 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3043
Chris Lattner223de242011-04-25 20:37:58 +00003044 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003045 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003046 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003047 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003048 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003049 }
Mike Stump1eb44332009-09-09 15:08:12 +00003050
Douglas Gregor670444e2009-08-04 22:27:00 +00003051 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00003052 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00003053 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00003054 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00003055 AEnd = Arg.pack_end();
3056 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00003057
John McCall833ca992009-10-29 08:12:44 +00003058 // FIXME: preserve source information here when we start
3059 // caring about parameter packs.
3060
John McCall828bff22009-10-29 18:45:58 +00003061 TemplateArgumentLoc InputArg;
3062 TemplateArgumentLoc OutputArg;
3063 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3064 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00003065 return true;
3066
John McCall828bff22009-10-29 18:45:58 +00003067 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00003068 }
Douglas Gregor910f8002010-11-07 23:05:16 +00003069
3070 TemplateArgument *TransformedArgsPtr
3071 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3072 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3073 TransformedArgsPtr);
3074 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3075 TransformedArgs.size()),
3076 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003077 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003078 }
3079 }
Mike Stump1eb44332009-09-09 15:08:12 +00003080
Douglas Gregor670444e2009-08-04 22:27:00 +00003081 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003082 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003083}
3084
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003085/// \brief Iterator adaptor that invents template argument location information
3086/// for each of the template arguments in its underlying iterator.
3087template<typename Derived, typename InputIterator>
3088class TemplateArgumentLocInventIterator {
3089 TreeTransform<Derived> &Self;
3090 InputIterator Iter;
3091
3092public:
3093 typedef TemplateArgumentLoc value_type;
3094 typedef TemplateArgumentLoc reference;
3095 typedef typename std::iterator_traits<InputIterator>::difference_type
3096 difference_type;
3097 typedef std::input_iterator_tag iterator_category;
3098
3099 class pointer {
3100 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003101
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003102 public:
3103 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3104
3105 const TemplateArgumentLoc *operator->() const { return &Arg; }
3106 };
3107
3108 TemplateArgumentLocInventIterator() { }
3109
3110 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3111 InputIterator Iter)
3112 : Self(Self), Iter(Iter) { }
3113
3114 TemplateArgumentLocInventIterator &operator++() {
3115 ++Iter;
3116 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003117 }
3118
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003119 TemplateArgumentLocInventIterator operator++(int) {
3120 TemplateArgumentLocInventIterator Old(*this);
3121 ++(*this);
3122 return Old;
3123 }
3124
3125 reference operator*() const {
3126 TemplateArgumentLoc Result;
3127 Self.InventTemplateArgumentLoc(*Iter, Result);
3128 return Result;
3129 }
3130
3131 pointer operator->() const { return pointer(**this); }
3132
3133 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3134 const TemplateArgumentLocInventIterator &Y) {
3135 return X.Iter == Y.Iter;
3136 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003137
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003138 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3139 const TemplateArgumentLocInventIterator &Y) {
3140 return X.Iter != Y.Iter;
3141 }
3142};
3143
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003144template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003145template<typename InputIterator>
3146bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3147 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003148 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003149 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003150 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003151 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003152
3153 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3154 // Unpack argument packs, which we translate them into separate
3155 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003156 // FIXME: We could do much better if we could guarantee that the
3157 // TemplateArgumentLocInfo for the pack expansion would be usable for
3158 // all of the template arguments in the argument pack.
3159 typedef TemplateArgumentLocInventIterator<Derived,
3160 TemplateArgument::pack_iterator>
3161 PackLocIterator;
3162 if (TransformTemplateArguments(PackLocIterator(*this,
3163 In.getArgument().pack_begin()),
3164 PackLocIterator(*this,
3165 In.getArgument().pack_end()),
3166 Outputs))
3167 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003168
3169 continue;
3170 }
3171
3172 if (In.getArgument().isPackExpansion()) {
3173 // We have a pack expansion, for which we will be substituting into
3174 // the pattern.
3175 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003176 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003177 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003178 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3179 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003180
Chris Lattner686775d2011-07-20 06:58:45 +00003181 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003182 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3183 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3184
3185 // Determine whether the set of unexpanded parameter packs can and should
3186 // be expanded.
3187 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003188 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003189 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003190 if (getDerived().TryExpandParameterPacks(Ellipsis,
3191 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003192 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003193 Expand,
3194 RetainExpansion,
3195 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003196 return true;
3197
3198 if (!Expand) {
3199 // The transform has determined that we should perform a simple
3200 // transformation on the pack expansion, producing another pack
3201 // expansion.
3202 TemplateArgumentLoc OutPattern;
3203 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3204 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3205 return true;
3206
Douglas Gregorcded4f62011-01-14 17:04:44 +00003207 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3208 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003209 if (Out.getArgument().isNull())
3210 return true;
3211
3212 Outputs.addArgument(Out);
3213 continue;
3214 }
3215
3216 // The transform has determined that we should perform an elementwise
3217 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003218 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003219 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3220
3221 if (getDerived().TransformTemplateArgument(Pattern, Out))
3222 return true;
3223
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003224 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003225 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3226 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003227 if (Out.getArgument().isNull())
3228 return true;
3229 }
3230
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003231 Outputs.addArgument(Out);
3232 }
3233
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003234 // If we're supposed to retain a pack expansion, do so by temporarily
3235 // forgetting the partially-substituted parameter pack.
3236 if (RetainExpansion) {
3237 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3238
3239 if (getDerived().TransformTemplateArgument(Pattern, Out))
3240 return true;
3241
Douglas Gregorcded4f62011-01-14 17:04:44 +00003242 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3243 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003244 if (Out.getArgument().isNull())
3245 return true;
3246
3247 Outputs.addArgument(Out);
3248 }
Douglas Gregord3731192011-01-10 07:32:04 +00003249
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003250 continue;
3251 }
3252
3253 // The simple case:
3254 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003255 return true;
3256
3257 Outputs.addArgument(Out);
3258 }
3259
3260 return false;
3261
3262}
3263
Douglas Gregor577f75a2009-08-04 16:50:30 +00003264//===----------------------------------------------------------------------===//
3265// Type transformation
3266//===----------------------------------------------------------------------===//
3267
3268template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003269QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003270 if (getDerived().AlreadyTransformed(T))
3271 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003272
John McCalla2becad2009-10-21 00:40:46 +00003273 // Temporary workaround. All of these transformations should
3274 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003275 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3276 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003277
John McCall43fed0d2010-11-12 08:19:04 +00003278 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003279
John McCalla2becad2009-10-21 00:40:46 +00003280 if (!NewDI)
3281 return QualType();
3282
3283 return NewDI->getType();
3284}
3285
3286template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003287TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003288 // Refine the base location to the type's location.
3289 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3290 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003291 if (getDerived().AlreadyTransformed(DI->getType()))
3292 return DI;
3293
3294 TypeLocBuilder TLB;
3295
3296 TypeLoc TL = DI->getTypeLoc();
3297 TLB.reserve(TL.getFullDataSize());
3298
John McCall43fed0d2010-11-12 08:19:04 +00003299 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003300 if (Result.isNull())
3301 return 0;
3302
John McCalla93c9342009-12-07 02:54:59 +00003303 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003304}
3305
3306template<typename Derived>
3307QualType
John McCall43fed0d2010-11-12 08:19:04 +00003308TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003309 switch (T.getTypeLocClass()) {
3310#define ABSTRACT_TYPELOC(CLASS, PARENT)
3311#define TYPELOC(CLASS, PARENT) \
3312 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003313 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003314#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003315 }
Mike Stump1eb44332009-09-09 15:08:12 +00003316
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003317 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003318}
3319
3320/// FIXME: By default, this routine adds type qualifiers only to types
3321/// that can have qualifiers, and silently suppresses those qualifiers
3322/// that are not permitted (e.g., qualifiers on reference or function
3323/// types). This is the right thing for template instantiation, but
3324/// probably not for other clients.
3325template<typename Derived>
3326QualType
3327TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003328 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003329 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003330
John McCall43fed0d2010-11-12 08:19:04 +00003331 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003332 if (Result.isNull())
3333 return QualType();
3334
3335 // Silently suppress qualifiers if the result type can't be qualified.
3336 // FIXME: this is the right thing for template instantiation, but
3337 // probably not for other clients.
3338 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003339 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003340
John McCallf85e1932011-06-15 23:02:42 +00003341 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003342 // resulting type.
3343 if (Quals.hasObjCLifetime()) {
3344 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3345 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003346 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003347 // Objective-C ARC:
3348 // A lifetime qualifier applied to a substituted template parameter
3349 // overrides the lifetime qualifier from the template argument.
3350 if (const SubstTemplateTypeParmType *SubstTypeParam
3351 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3352 QualType Replacement = SubstTypeParam->getReplacementType();
3353 Qualifiers Qs = Replacement.getQualifiers();
3354 Qs.removeObjCLifetime();
3355 Replacement
3356 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3357 Qs);
3358 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3359 SubstTypeParam->getReplacedParameter(),
3360 Replacement);
3361 TLB.TypeWasModifiedSafely(Result);
3362 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003363 // Otherwise, complain about the addition of a qualifier to an
3364 // already-qualified type.
3365 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003366 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003367 << Result << R;
3368
Douglas Gregore559ca12011-06-17 22:11:49 +00003369 Quals.removeObjCLifetime();
3370 }
3371 }
3372 }
John McCall28654742010-06-05 06:41:15 +00003373 if (!Quals.empty()) {
3374 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3375 TLB.push<QualifiedTypeLoc>(Result);
3376 // No location information to preserve.
3377 }
John McCalla2becad2009-10-21 00:40:46 +00003378
3379 return Result;
3380}
3381
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003382template<typename Derived>
3383TypeLoc
3384TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3385 QualType ObjectType,
3386 NamedDecl *UnqualLookup,
3387 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003388 QualType T = TL.getType();
3389 if (getDerived().AlreadyTransformed(T))
3390 return TL;
3391
3392 TypeLocBuilder TLB;
3393 QualType Result;
3394
3395 if (isa<TemplateSpecializationType>(T)) {
3396 TemplateSpecializationTypeLoc SpecTL
3397 = cast<TemplateSpecializationTypeLoc>(TL);
3398
3399 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003400 getDerived().TransformTemplateName(SS,
3401 SpecTL.getTypePtr()->getTemplateName(),
3402 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003403 ObjectType, UnqualLookup);
3404 if (Template.isNull())
3405 return TypeLoc();
3406
3407 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3408 Template);
3409 } else if (isa<DependentTemplateSpecializationType>(T)) {
3410 DependentTemplateSpecializationTypeLoc SpecTL
3411 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3412
Douglas Gregora88f09f2011-02-28 17:23:35 +00003413 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003414 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003415 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003416 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003417 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003418 if (Template.isNull())
3419 return TypeLoc();
3420
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003421 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003422 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003423 Template,
3424 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003425 } else {
3426 // Nothing special needs to be done for these.
3427 Result = getDerived().TransformType(TLB, TL);
3428 }
3429
3430 if (Result.isNull())
3431 return TypeLoc();
3432
3433 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3434}
3435
Douglas Gregorb71d8212011-03-02 18:32:08 +00003436template<typename Derived>
3437TypeSourceInfo *
3438TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3439 QualType ObjectType,
3440 NamedDecl *UnqualLookup,
3441 CXXScopeSpec &SS) {
3442 // FIXME: Painfully copy-paste from the above!
3443
3444 QualType T = TSInfo->getType();
3445 if (getDerived().AlreadyTransformed(T))
3446 return TSInfo;
3447
3448 TypeLocBuilder TLB;
3449 QualType Result;
3450
3451 TypeLoc TL = TSInfo->getTypeLoc();
3452 if (isa<TemplateSpecializationType>(T)) {
3453 TemplateSpecializationTypeLoc SpecTL
3454 = cast<TemplateSpecializationTypeLoc>(TL);
3455
3456 TemplateName Template
3457 = getDerived().TransformTemplateName(SS,
3458 SpecTL.getTypePtr()->getTemplateName(),
3459 SpecTL.getTemplateNameLoc(),
3460 ObjectType, UnqualLookup);
3461 if (Template.isNull())
3462 return 0;
3463
3464 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3465 Template);
3466 } else if (isa<DependentTemplateSpecializationType>(T)) {
3467 DependentTemplateSpecializationTypeLoc SpecTL
3468 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3469
3470 TemplateName Template
3471 = getDerived().RebuildTemplateName(SS,
3472 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003473 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003474 ObjectType, UnqualLookup);
3475 if (Template.isNull())
3476 return 0;
3477
3478 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3479 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003480 Template,
3481 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003482 } else {
3483 // Nothing special needs to be done for these.
3484 Result = getDerived().TransformType(TLB, TL);
3485 }
3486
3487 if (Result.isNull())
3488 return 0;
3489
3490 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3491}
3492
John McCalla2becad2009-10-21 00:40:46 +00003493template <class TyLoc> static inline
3494QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3495 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3496 NewT.setNameLoc(T.getNameLoc());
3497 return T.getType();
3498}
3499
John McCalla2becad2009-10-21 00:40:46 +00003500template<typename Derived>
3501QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003502 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003503 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3504 NewT.setBuiltinLoc(T.getBuiltinLoc());
3505 if (T.needsExtraLocalData())
3506 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3507 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003508}
Mike Stump1eb44332009-09-09 15:08:12 +00003509
Douglas Gregor577f75a2009-08-04 16:50:30 +00003510template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003511QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003512 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003513 // FIXME: recurse?
3514 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003515}
Mike Stump1eb44332009-09-09 15:08:12 +00003516
Douglas Gregor577f75a2009-08-04 16:50:30 +00003517template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003518QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003519 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003520 QualType PointeeType
3521 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003522 if (PointeeType.isNull())
3523 return QualType();
3524
3525 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003526 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003527 // A dependent pointer type 'T *' has is being transformed such
3528 // that an Objective-C class type is being replaced for 'T'. The
3529 // resulting pointer type is an ObjCObjectPointerType, not a
3530 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003531 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003532
John McCallc12c5bb2010-05-15 11:32:37 +00003533 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3534 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003535 return Result;
3536 }
John McCall43fed0d2010-11-12 08:19:04 +00003537
Douglas Gregor92e986e2010-04-22 16:44:27 +00003538 if (getDerived().AlwaysRebuild() ||
3539 PointeeType != TL.getPointeeLoc().getType()) {
3540 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3541 if (Result.isNull())
3542 return QualType();
3543 }
John McCallf85e1932011-06-15 23:02:42 +00003544
3545 // Objective-C ARC can add lifetime qualifiers to the type that we're
3546 // pointing to.
3547 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3548
Douglas Gregor92e986e2010-04-22 16:44:27 +00003549 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3550 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003551 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003552}
Mike Stump1eb44332009-09-09 15:08:12 +00003553
3554template<typename Derived>
3555QualType
John McCalla2becad2009-10-21 00:40:46 +00003556TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003557 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003558 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003559 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3560 if (PointeeType.isNull())
3561 return QualType();
3562
3563 QualType Result = TL.getType();
3564 if (getDerived().AlwaysRebuild() ||
3565 PointeeType != TL.getPointeeLoc().getType()) {
3566 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003567 TL.getSigilLoc());
3568 if (Result.isNull())
3569 return QualType();
3570 }
3571
Douglas Gregor39968ad2010-04-22 16:50:51 +00003572 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003573 NewT.setSigilLoc(TL.getSigilLoc());
3574 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003575}
3576
John McCall85737a72009-10-30 00:06:24 +00003577/// Transforms a reference type. Note that somewhat paradoxically we
3578/// don't care whether the type itself is an l-value type or an r-value
3579/// type; we only care if the type was *written* as an l-value type
3580/// or an r-value type.
3581template<typename Derived>
3582QualType
3583TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003584 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003585 const ReferenceType *T = TL.getTypePtr();
3586
3587 // Note that this works with the pointee-as-written.
3588 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3589 if (PointeeType.isNull())
3590 return QualType();
3591
3592 QualType Result = TL.getType();
3593 if (getDerived().AlwaysRebuild() ||
3594 PointeeType != T->getPointeeTypeAsWritten()) {
3595 Result = getDerived().RebuildReferenceType(PointeeType,
3596 T->isSpelledAsLValue(),
3597 TL.getSigilLoc());
3598 if (Result.isNull())
3599 return QualType();
3600 }
3601
John McCallf85e1932011-06-15 23:02:42 +00003602 // Objective-C ARC can add lifetime qualifiers to the type that we're
3603 // referring to.
3604 TLB.TypeWasModifiedSafely(
3605 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3606
John McCall85737a72009-10-30 00:06:24 +00003607 // r-value references can be rebuilt as l-value references.
3608 ReferenceTypeLoc NewTL;
3609 if (isa<LValueReferenceType>(Result))
3610 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3611 else
3612 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3613 NewTL.setSigilLoc(TL.getSigilLoc());
3614
3615 return Result;
3616}
3617
Mike Stump1eb44332009-09-09 15:08:12 +00003618template<typename Derived>
3619QualType
John McCalla2becad2009-10-21 00:40:46 +00003620TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003621 LValueReferenceTypeLoc TL) {
3622 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003623}
3624
Mike Stump1eb44332009-09-09 15:08:12 +00003625template<typename Derived>
3626QualType
John McCalla2becad2009-10-21 00:40:46 +00003627TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003628 RValueReferenceTypeLoc TL) {
3629 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003630}
Mike Stump1eb44332009-09-09 15:08:12 +00003631
Douglas Gregor577f75a2009-08-04 16:50:30 +00003632template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003633QualType
John McCalla2becad2009-10-21 00:40:46 +00003634TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003635 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003636 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003637 if (PointeeType.isNull())
3638 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003639
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003640 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3641 TypeSourceInfo* NewClsTInfo = 0;
3642 if (OldClsTInfo) {
3643 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3644 if (!NewClsTInfo)
3645 return QualType();
3646 }
3647
3648 const MemberPointerType *T = TL.getTypePtr();
3649 QualType OldClsType = QualType(T->getClass(), 0);
3650 QualType NewClsType;
3651 if (NewClsTInfo)
3652 NewClsType = NewClsTInfo->getType();
3653 else {
3654 NewClsType = getDerived().TransformType(OldClsType);
3655 if (NewClsType.isNull())
3656 return QualType();
3657 }
Mike Stump1eb44332009-09-09 15:08:12 +00003658
John McCalla2becad2009-10-21 00:40:46 +00003659 QualType Result = TL.getType();
3660 if (getDerived().AlwaysRebuild() ||
3661 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003662 NewClsType != OldClsType) {
3663 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003664 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003665 if (Result.isNull())
3666 return QualType();
3667 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003668
John McCalla2becad2009-10-21 00:40:46 +00003669 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3670 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003671 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003672
3673 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003674}
3675
Mike Stump1eb44332009-09-09 15:08:12 +00003676template<typename Derived>
3677QualType
John McCalla2becad2009-10-21 00:40:46 +00003678TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003679 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003680 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003681 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003682 if (ElementType.isNull())
3683 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003684
John McCalla2becad2009-10-21 00:40:46 +00003685 QualType Result = TL.getType();
3686 if (getDerived().AlwaysRebuild() ||
3687 ElementType != T->getElementType()) {
3688 Result = getDerived().RebuildConstantArrayType(ElementType,
3689 T->getSizeModifier(),
3690 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003691 T->getIndexTypeCVRQualifiers(),
3692 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003693 if (Result.isNull())
3694 return QualType();
3695 }
Eli Friedman457a3772012-01-25 22:19:07 +00003696
3697 // We might have either a ConstantArrayType or a VariableArrayType now:
3698 // a ConstantArrayType is allowed to have an element type which is a
3699 // VariableArrayType if the type is dependent. Fortunately, all array
3700 // types have the same location layout.
3701 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003702 NewTL.setLBracketLoc(TL.getLBracketLoc());
3703 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003704
John McCalla2becad2009-10-21 00:40:46 +00003705 Expr *Size = TL.getSizeExpr();
3706 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003707 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3708 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003709 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003710 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003711 }
3712 NewTL.setSizeExpr(Size);
3713
3714 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003715}
Mike Stump1eb44332009-09-09 15:08:12 +00003716
Douglas Gregor577f75a2009-08-04 16:50:30 +00003717template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003718QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003719 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003720 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003721 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003722 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003723 if (ElementType.isNull())
3724 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003725
John McCalla2becad2009-10-21 00:40:46 +00003726 QualType Result = TL.getType();
3727 if (getDerived().AlwaysRebuild() ||
3728 ElementType != T->getElementType()) {
3729 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003730 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003731 T->getIndexTypeCVRQualifiers(),
3732 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003733 if (Result.isNull())
3734 return QualType();
3735 }
Sean Huntc3021132010-05-05 15:23:54 +00003736
John McCalla2becad2009-10-21 00:40:46 +00003737 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3738 NewTL.setLBracketLoc(TL.getLBracketLoc());
3739 NewTL.setRBracketLoc(TL.getRBracketLoc());
3740 NewTL.setSizeExpr(0);
3741
3742 return Result;
3743}
3744
3745template<typename Derived>
3746QualType
3747TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003748 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003749 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003750 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3751 if (ElementType.isNull())
3752 return QualType();
3753
John McCall60d7b3a2010-08-24 06:29:42 +00003754 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003755 = getDerived().TransformExpr(T->getSizeExpr());
3756 if (SizeResult.isInvalid())
3757 return QualType();
3758
John McCall9ae2f072010-08-23 23:25:46 +00003759 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003760
3761 QualType Result = TL.getType();
3762 if (getDerived().AlwaysRebuild() ||
3763 ElementType != T->getElementType() ||
3764 Size != T->getSizeExpr()) {
3765 Result = getDerived().RebuildVariableArrayType(ElementType,
3766 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003767 Size,
John McCalla2becad2009-10-21 00:40:46 +00003768 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003769 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003770 if (Result.isNull())
3771 return QualType();
3772 }
Sean Huntc3021132010-05-05 15:23:54 +00003773
John McCalla2becad2009-10-21 00:40:46 +00003774 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3775 NewTL.setLBracketLoc(TL.getLBracketLoc());
3776 NewTL.setRBracketLoc(TL.getRBracketLoc());
3777 NewTL.setSizeExpr(Size);
3778
3779 return Result;
3780}
3781
3782template<typename Derived>
3783QualType
3784TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003785 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003786 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003787 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3788 if (ElementType.isNull())
3789 return QualType();
3790
Richard Smithf6702a32011-12-20 02:08:33 +00003791 // Array bounds are constant expressions.
3792 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3793 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003794
John McCall3b657512011-01-19 10:06:00 +00003795 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3796 Expr *origSize = TL.getSizeExpr();
3797 if (!origSize) origSize = T->getSizeExpr();
3798
3799 ExprResult sizeResult
3800 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003801 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003802 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003803 return QualType();
3804
John McCall3b657512011-01-19 10:06:00 +00003805 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003806
3807 QualType Result = TL.getType();
3808 if (getDerived().AlwaysRebuild() ||
3809 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003810 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003811 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3812 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003813 size,
John McCalla2becad2009-10-21 00:40:46 +00003814 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003815 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003816 if (Result.isNull())
3817 return QualType();
3818 }
John McCalla2becad2009-10-21 00:40:46 +00003819
3820 // We might have any sort of array type now, but fortunately they
3821 // all have the same location layout.
3822 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3823 NewTL.setLBracketLoc(TL.getLBracketLoc());
3824 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003825 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003826
3827 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003828}
Mike Stump1eb44332009-09-09 15:08:12 +00003829
3830template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003831QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003832 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003833 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003834 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003835
3836 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003837 QualType ElementType = getDerived().TransformType(T->getElementType());
3838 if (ElementType.isNull())
3839 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003840
Richard Smithf6702a32011-12-20 02:08:33 +00003841 // Vector sizes are constant expressions.
3842 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3843 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003844
John McCall60d7b3a2010-08-24 06:29:42 +00003845 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003846 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003847 if (Size.isInvalid())
3848 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003849
John McCalla2becad2009-10-21 00:40:46 +00003850 QualType Result = TL.getType();
3851 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003852 ElementType != T->getElementType() ||
3853 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003854 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003855 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003856 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003857 if (Result.isNull())
3858 return QualType();
3859 }
John McCalla2becad2009-10-21 00:40:46 +00003860
3861 // Result might be dependent or not.
3862 if (isa<DependentSizedExtVectorType>(Result)) {
3863 DependentSizedExtVectorTypeLoc NewTL
3864 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3865 NewTL.setNameLoc(TL.getNameLoc());
3866 } else {
3867 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3868 NewTL.setNameLoc(TL.getNameLoc());
3869 }
3870
3871 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003872}
Mike Stump1eb44332009-09-09 15:08:12 +00003873
3874template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003875QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003876 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003877 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003878 QualType ElementType = getDerived().TransformType(T->getElementType());
3879 if (ElementType.isNull())
3880 return QualType();
3881
John McCalla2becad2009-10-21 00:40:46 +00003882 QualType Result = TL.getType();
3883 if (getDerived().AlwaysRebuild() ||
3884 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003885 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003886 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003887 if (Result.isNull())
3888 return QualType();
3889 }
Sean Huntc3021132010-05-05 15:23:54 +00003890
John McCalla2becad2009-10-21 00:40:46 +00003891 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3892 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003893
John McCalla2becad2009-10-21 00:40:46 +00003894 return Result;
3895}
3896
3897template<typename Derived>
3898QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003899 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003900 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003901 QualType ElementType = getDerived().TransformType(T->getElementType());
3902 if (ElementType.isNull())
3903 return QualType();
3904
3905 QualType Result = TL.getType();
3906 if (getDerived().AlwaysRebuild() ||
3907 ElementType != T->getElementType()) {
3908 Result = getDerived().RebuildExtVectorType(ElementType,
3909 T->getNumElements(),
3910 /*FIXME*/ SourceLocation());
3911 if (Result.isNull())
3912 return QualType();
3913 }
Sean Huntc3021132010-05-05 15:23:54 +00003914
John McCalla2becad2009-10-21 00:40:46 +00003915 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3916 NewTL.setNameLoc(TL.getNameLoc());
3917
3918 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003919}
Mike Stump1eb44332009-09-09 15:08:12 +00003920
3921template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003922ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003923TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003924 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003925 llvm::Optional<unsigned> NumExpansions,
3926 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003927 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003928 TypeSourceInfo *NewDI = 0;
3929
3930 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3931 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003932 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003933 TypeLoc OldTL = OldDI->getTypeLoc();
3934 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3935
3936 TypeLocBuilder TLB;
3937 TypeLoc NewTL = OldDI->getTypeLoc();
3938 TLB.reserve(NewTL.getFullDataSize());
3939
3940 QualType Result = getDerived().TransformType(TLB,
3941 OldExpansionTL.getPatternLoc());
3942 if (Result.isNull())
3943 return 0;
3944
3945 Result = RebuildPackExpansionType(Result,
3946 OldExpansionTL.getPatternLoc().getSourceRange(),
3947 OldExpansionTL.getEllipsisLoc(),
3948 NumExpansions);
3949 if (Result.isNull())
3950 return 0;
3951
3952 PackExpansionTypeLoc NewExpansionTL
3953 = TLB.push<PackExpansionTypeLoc>(Result);
3954 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3955 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3956 } else
3957 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003958 if (!NewDI)
3959 return 0;
3960
John McCallfb44de92011-05-01 22:35:37 +00003961 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003962 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003963
3964 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3965 OldParm->getDeclContext(),
3966 OldParm->getInnerLocStart(),
3967 OldParm->getLocation(),
3968 OldParm->getIdentifier(),
3969 NewDI->getType(),
3970 NewDI,
3971 OldParm->getStorageClass(),
3972 OldParm->getStorageClassAsWritten(),
3973 /* DefArg */ NULL);
3974 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3975 OldParm->getFunctionScopeIndex() + indexAdjustment);
3976 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003977}
3978
3979template<typename Derived>
3980bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003981 TransformFunctionTypeParams(SourceLocation Loc,
3982 ParmVarDecl **Params, unsigned NumParams,
3983 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003984 SmallVectorImpl<QualType> &OutParamTypes,
3985 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003986 int indexAdjustment = 0;
3987
Douglas Gregora009b592011-01-07 00:20:55 +00003988 for (unsigned i = 0; i != NumParams; ++i) {
3989 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003990 assert(OldParm->getFunctionScopeIndex() == i);
3991
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003992 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003993 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003994 if (OldParm->isParameterPack()) {
3995 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003996 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003997
Douglas Gregor603cfb42011-01-05 23:12:31 +00003998 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003999 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4000 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
4001 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4002 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004003 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4004
Douglas Gregor603cfb42011-01-05 23:12:31 +00004005 // Determine whether we should expand the parameter packs.
4006 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004007 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004008 llvm::Optional<unsigned> OrigNumExpansions
4009 = ExpansionTL.getTypePtr()->getNumExpansions();
4010 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004011 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4012 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004013 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004014 ShouldExpand,
4015 RetainExpansion,
4016 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004017 return true;
4018 }
4019
4020 if (ShouldExpand) {
4021 // Expand the function parameter pack into multiple, separate
4022 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004023 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004024 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004025 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4026 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004027 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004028 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004029 OrigNumExpansions,
4030 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004031 if (!NewParm)
4032 return true;
4033
Douglas Gregora009b592011-01-07 00:20:55 +00004034 OutParamTypes.push_back(NewParm->getType());
4035 if (PVars)
4036 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004037 }
Douglas Gregord3731192011-01-10 07:32:04 +00004038
4039 // If we're supposed to retain a pack expansion, do so by temporarily
4040 // forgetting the partially-substituted parameter pack.
4041 if (RetainExpansion) {
4042 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4043 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004044 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004045 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004046 OrigNumExpansions,
4047 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004048 if (!NewParm)
4049 return true;
4050
4051 OutParamTypes.push_back(NewParm->getType());
4052 if (PVars)
4053 PVars->push_back(NewParm);
4054 }
4055
John McCallfb44de92011-05-01 22:35:37 +00004056 // The next parameter should have the same adjustment as the
4057 // last thing we pushed, but we post-incremented indexAdjustment
4058 // on every push. Also, if we push nothing, the adjustment should
4059 // go down by one.
4060 indexAdjustment--;
4061
Douglas Gregor603cfb42011-01-05 23:12:31 +00004062 // We're done with the pack expansion.
4063 continue;
4064 }
4065
4066 // We'll substitute the parameter now without expanding the pack
4067 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004068 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4069 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004070 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004071 NumExpansions,
4072 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004073 } else {
4074 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004075 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004076 llvm::Optional<unsigned>(),
4077 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004078 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004079
John McCall21ef0fa2010-03-11 09:03:00 +00004080 if (!NewParm)
4081 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004082
Douglas Gregora009b592011-01-07 00:20:55 +00004083 OutParamTypes.push_back(NewParm->getType());
4084 if (PVars)
4085 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004086 continue;
4087 }
John McCall21ef0fa2010-03-11 09:03:00 +00004088
4089 // Deal with the possibility that we don't have a parameter
4090 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004091 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004092 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004093 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004094 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004095 if (const PackExpansionType *Expansion
4096 = dyn_cast<PackExpansionType>(OldType)) {
4097 // We have a function parameter pack that may need to be expanded.
4098 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004099 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004100 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4101
4102 // Determine whether we should expand the parameter packs.
4103 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004104 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004105 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004106 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004107 ShouldExpand,
4108 RetainExpansion,
4109 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004110 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004111 }
4112
4113 if (ShouldExpand) {
4114 // Expand the function parameter pack into multiple, separate
4115 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004116 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004117 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4118 QualType NewType = getDerived().TransformType(Pattern);
4119 if (NewType.isNull())
4120 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004121
Douglas Gregora009b592011-01-07 00:20:55 +00004122 OutParamTypes.push_back(NewType);
4123 if (PVars)
4124 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004125 }
4126
4127 // We're done with the pack expansion.
4128 continue;
4129 }
4130
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004131 // If we're supposed to retain a pack expansion, do so by temporarily
4132 // forgetting the partially-substituted parameter pack.
4133 if (RetainExpansion) {
4134 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4135 QualType NewType = getDerived().TransformType(Pattern);
4136 if (NewType.isNull())
4137 return true;
4138
4139 OutParamTypes.push_back(NewType);
4140 if (PVars)
4141 PVars->push_back(0);
4142 }
Douglas Gregord3731192011-01-10 07:32:04 +00004143
Douglas Gregor603cfb42011-01-05 23:12:31 +00004144 // We'll substitute the parameter now without expanding the pack
4145 // expansion.
4146 OldType = Expansion->getPattern();
4147 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004148 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4149 NewType = getDerived().TransformType(OldType);
4150 } else {
4151 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004152 }
4153
Douglas Gregor603cfb42011-01-05 23:12:31 +00004154 if (NewType.isNull())
4155 return true;
4156
4157 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004158 NewType = getSema().Context.getPackExpansionType(NewType,
4159 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004160
Douglas Gregora009b592011-01-07 00:20:55 +00004161 OutParamTypes.push_back(NewType);
4162 if (PVars)
4163 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004164 }
4165
John McCallfb44de92011-05-01 22:35:37 +00004166#ifndef NDEBUG
4167 if (PVars) {
4168 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4169 if (ParmVarDecl *parm = (*PVars)[i])
4170 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004171 }
John McCallfb44de92011-05-01 22:35:37 +00004172#endif
4173
4174 return false;
4175}
John McCall21ef0fa2010-03-11 09:03:00 +00004176
4177template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004178QualType
John McCalla2becad2009-10-21 00:40:46 +00004179TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004180 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004181 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4182}
4183
4184template<typename Derived>
4185QualType
4186TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4187 FunctionProtoTypeLoc TL,
4188 CXXRecordDecl *ThisContext,
4189 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004190 // Transform the parameters and return type.
4191 //
Richard Smithe6975e92012-04-17 00:58:00 +00004192 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004193 // When the function has a trailing return type, we instantiate the
4194 // parameters before the return type, since the return type can then refer
4195 // to the parameters themselves (via decltype, sizeof, etc.).
4196 //
Chris Lattner686775d2011-07-20 06:58:45 +00004197 SmallVector<QualType, 4> ParamTypes;
4198 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004199 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004200
Douglas Gregordab60ad2010-10-01 18:44:50 +00004201 QualType ResultType;
4202
4203 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004204 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4205 TL.getParmArray(),
4206 TL.getNumArgs(),
4207 TL.getTypePtr()->arg_type_begin(),
4208 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004209 return QualType();
4210
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004211 {
4212 // C++11 [expr.prim.general]p3:
4213 // If a declaration declares a member function or member function
4214 // template of a class X, the expression this is a prvalue of type
4215 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
4216 // and the end of the function-definition, member-declarator, or
4217 // declarator.
4218 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
4219
4220 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4221 if (ResultType.isNull())
4222 return QualType();
4223 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004224 }
4225 else {
4226 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4227 if (ResultType.isNull())
4228 return QualType();
4229
Douglas Gregora009b592011-01-07 00:20:55 +00004230 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4231 TL.getParmArray(),
4232 TL.getNumArgs(),
4233 TL.getTypePtr()->arg_type_begin(),
4234 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004235 return QualType();
4236 }
4237
Richard Smithe6975e92012-04-17 00:58:00 +00004238 // FIXME: Need to transform the exception-specification too.
4239
John McCalla2becad2009-10-21 00:40:46 +00004240 QualType Result = TL.getType();
4241 if (getDerived().AlwaysRebuild() ||
4242 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004243 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004244 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4245 Result = getDerived().RebuildFunctionProtoType(ResultType,
4246 ParamTypes.data(),
4247 ParamTypes.size(),
4248 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004249 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004250 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004251 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004252 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004253 if (Result.isNull())
4254 return QualType();
4255 }
Mike Stump1eb44332009-09-09 15:08:12 +00004256
John McCalla2becad2009-10-21 00:40:46 +00004257 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004258 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4259 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004260 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004261 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4262 NewTL.setArg(i, ParamDecls[i]);
4263
4264 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004265}
Mike Stump1eb44332009-09-09 15:08:12 +00004266
Douglas Gregor577f75a2009-08-04 16:50:30 +00004267template<typename Derived>
4268QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004269 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004270 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004271 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004272 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4273 if (ResultType.isNull())
4274 return QualType();
4275
4276 QualType Result = TL.getType();
4277 if (getDerived().AlwaysRebuild() ||
4278 ResultType != T->getResultType())
4279 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4280
4281 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004282 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4283 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004284 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004285
4286 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004287}
Mike Stump1eb44332009-09-09 15:08:12 +00004288
John McCalled976492009-12-04 22:46:56 +00004289template<typename Derived> QualType
4290TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004291 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004292 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004293 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004294 if (!D)
4295 return QualType();
4296
4297 QualType Result = TL.getType();
4298 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4299 Result = getDerived().RebuildUnresolvedUsingType(D);
4300 if (Result.isNull())
4301 return QualType();
4302 }
4303
4304 // We might get an arbitrary type spec type back. We should at
4305 // least always get a type spec type, though.
4306 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4307 NewTL.setNameLoc(TL.getNameLoc());
4308
4309 return Result;
4310}
4311
Douglas Gregor577f75a2009-08-04 16:50:30 +00004312template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004313QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004314 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004315 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004316 TypedefNameDecl *Typedef
4317 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4318 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004319 if (!Typedef)
4320 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004321
John McCalla2becad2009-10-21 00:40:46 +00004322 QualType Result = TL.getType();
4323 if (getDerived().AlwaysRebuild() ||
4324 Typedef != T->getDecl()) {
4325 Result = getDerived().RebuildTypedefType(Typedef);
4326 if (Result.isNull())
4327 return QualType();
4328 }
Mike Stump1eb44332009-09-09 15:08:12 +00004329
John McCalla2becad2009-10-21 00:40:46 +00004330 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4331 NewTL.setNameLoc(TL.getNameLoc());
4332
4333 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004334}
Mike Stump1eb44332009-09-09 15:08:12 +00004335
Douglas Gregor577f75a2009-08-04 16:50:30 +00004336template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004337QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004338 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004339 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004340 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004341
John McCall60d7b3a2010-08-24 06:29:42 +00004342 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004343 if (E.isInvalid())
4344 return QualType();
4345
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004346 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4347 if (E.isInvalid())
4348 return QualType();
4349
John McCalla2becad2009-10-21 00:40:46 +00004350 QualType Result = TL.getType();
4351 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004352 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004353 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004354 if (Result.isNull())
4355 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004356 }
John McCalla2becad2009-10-21 00:40:46 +00004357 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004358
John McCalla2becad2009-10-21 00:40:46 +00004359 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004360 NewTL.setTypeofLoc(TL.getTypeofLoc());
4361 NewTL.setLParenLoc(TL.getLParenLoc());
4362 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004363
4364 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004365}
Mike Stump1eb44332009-09-09 15:08:12 +00004366
4367template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004368QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004369 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004370 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4371 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4372 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004373 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004374
John McCalla2becad2009-10-21 00:40:46 +00004375 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004376 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4377 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004378 if (Result.isNull())
4379 return QualType();
4380 }
Mike Stump1eb44332009-09-09 15:08:12 +00004381
John McCalla2becad2009-10-21 00:40:46 +00004382 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004383 NewTL.setTypeofLoc(TL.getTypeofLoc());
4384 NewTL.setLParenLoc(TL.getLParenLoc());
4385 NewTL.setRParenLoc(TL.getRParenLoc());
4386 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004387
4388 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004389}
Mike Stump1eb44332009-09-09 15:08:12 +00004390
4391template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004392QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004393 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004394 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004395
Douglas Gregor670444e2009-08-04 22:27:00 +00004396 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004397 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4398 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004399
John McCall60d7b3a2010-08-24 06:29:42 +00004400 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004401 if (E.isInvalid())
4402 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004403
Richard Smith76f3f692012-02-22 02:04:18 +00004404 E = getSema().ActOnDecltypeExpression(E.take());
4405 if (E.isInvalid())
4406 return QualType();
4407
John McCalla2becad2009-10-21 00:40:46 +00004408 QualType Result = TL.getType();
4409 if (getDerived().AlwaysRebuild() ||
4410 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004411 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004412 if (Result.isNull())
4413 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004414 }
John McCalla2becad2009-10-21 00:40:46 +00004415 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004416
John McCalla2becad2009-10-21 00:40:46 +00004417 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4418 NewTL.setNameLoc(TL.getNameLoc());
4419
4420 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004421}
4422
4423template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004424QualType TreeTransform<Derived>::TransformUnaryTransformType(
4425 TypeLocBuilder &TLB,
4426 UnaryTransformTypeLoc TL) {
4427 QualType Result = TL.getType();
4428 if (Result->isDependentType()) {
4429 const UnaryTransformType *T = TL.getTypePtr();
4430 QualType NewBase =
4431 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4432 Result = getDerived().RebuildUnaryTransformType(NewBase,
4433 T->getUTTKind(),
4434 TL.getKWLoc());
4435 if (Result.isNull())
4436 return QualType();
4437 }
4438
4439 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4440 NewTL.setKWLoc(TL.getKWLoc());
4441 NewTL.setParensRange(TL.getParensRange());
4442 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4443 return Result;
4444}
4445
4446template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004447QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4448 AutoTypeLoc TL) {
4449 const AutoType *T = TL.getTypePtr();
4450 QualType OldDeduced = T->getDeducedType();
4451 QualType NewDeduced;
4452 if (!OldDeduced.isNull()) {
4453 NewDeduced = getDerived().TransformType(OldDeduced);
4454 if (NewDeduced.isNull())
4455 return QualType();
4456 }
4457
4458 QualType Result = TL.getType();
4459 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4460 Result = getDerived().RebuildAutoType(NewDeduced);
4461 if (Result.isNull())
4462 return QualType();
4463 }
4464
4465 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4466 NewTL.setNameLoc(TL.getNameLoc());
4467
4468 return Result;
4469}
4470
4471template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004472QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004473 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004474 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004475 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004476 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4477 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004478 if (!Record)
4479 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004480
John McCalla2becad2009-10-21 00:40:46 +00004481 QualType Result = TL.getType();
4482 if (getDerived().AlwaysRebuild() ||
4483 Record != T->getDecl()) {
4484 Result = getDerived().RebuildRecordType(Record);
4485 if (Result.isNull())
4486 return QualType();
4487 }
Mike Stump1eb44332009-09-09 15:08:12 +00004488
John McCalla2becad2009-10-21 00:40:46 +00004489 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4490 NewTL.setNameLoc(TL.getNameLoc());
4491
4492 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004493}
Mike Stump1eb44332009-09-09 15:08:12 +00004494
4495template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004496QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004497 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004498 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004499 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004500 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4501 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004502 if (!Enum)
4503 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004504
John McCalla2becad2009-10-21 00:40:46 +00004505 QualType Result = TL.getType();
4506 if (getDerived().AlwaysRebuild() ||
4507 Enum != T->getDecl()) {
4508 Result = getDerived().RebuildEnumType(Enum);
4509 if (Result.isNull())
4510 return QualType();
4511 }
Mike Stump1eb44332009-09-09 15:08:12 +00004512
John McCalla2becad2009-10-21 00:40:46 +00004513 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4514 NewTL.setNameLoc(TL.getNameLoc());
4515
4516 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004517}
John McCall7da24312009-09-05 00:15:47 +00004518
John McCall3cb0ebd2010-03-10 03:28:59 +00004519template<typename Derived>
4520QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4521 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004522 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004523 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4524 TL.getTypePtr()->getDecl());
4525 if (!D) return QualType();
4526
4527 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4528 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4529 return T;
4530}
4531
Douglas Gregor577f75a2009-08-04 16:50:30 +00004532template<typename Derived>
4533QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004534 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004535 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004536 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004537}
4538
Mike Stump1eb44332009-09-09 15:08:12 +00004539template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004540QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004541 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004542 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004543 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4544
4545 // Substitute into the replacement type, which itself might involve something
4546 // that needs to be transformed. This only tends to occur with default
4547 // template arguments of template template parameters.
4548 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4549 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4550 if (Replacement.isNull())
4551 return QualType();
4552
4553 // Always canonicalize the replacement type.
4554 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4555 QualType Result
4556 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4557 Replacement);
4558
4559 // Propagate type-source information.
4560 SubstTemplateTypeParmTypeLoc NewTL
4561 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4562 NewTL.setNameLoc(TL.getNameLoc());
4563 return Result;
4564
John McCall49a832b2009-10-18 09:09:24 +00004565}
4566
4567template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004568QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4569 TypeLocBuilder &TLB,
4570 SubstTemplateTypeParmPackTypeLoc TL) {
4571 return TransformTypeSpecType(TLB, TL);
4572}
4573
4574template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004575QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004576 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004577 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004578 const TemplateSpecializationType *T = TL.getTypePtr();
4579
Douglas Gregor1d752d72011-03-02 18:46:51 +00004580 // The nested-name-specifier never matters in a TemplateSpecializationType,
4581 // because we can't have a dependent nested-name-specifier anyway.
4582 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004583 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004584 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4585 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004586 if (Template.isNull())
4587 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004588
John McCall43fed0d2010-11-12 08:19:04 +00004589 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4590}
4591
Eli Friedmanb001de72011-10-06 23:00:33 +00004592template<typename Derived>
4593QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4594 AtomicTypeLoc TL) {
4595 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4596 if (ValueType.isNull())
4597 return QualType();
4598
4599 QualType Result = TL.getType();
4600 if (getDerived().AlwaysRebuild() ||
4601 ValueType != TL.getValueLoc().getType()) {
4602 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4603 if (Result.isNull())
4604 return QualType();
4605 }
4606
4607 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4608 NewTL.setKWLoc(TL.getKWLoc());
4609 NewTL.setLParenLoc(TL.getLParenLoc());
4610 NewTL.setRParenLoc(TL.getRParenLoc());
4611
4612 return Result;
4613}
4614
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004615namespace {
4616 /// \brief Simple iterator that traverses the template arguments in a
4617 /// container that provides a \c getArgLoc() member function.
4618 ///
4619 /// This iterator is intended to be used with the iterator form of
4620 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4621 template<typename ArgLocContainer>
4622 class TemplateArgumentLocContainerIterator {
4623 ArgLocContainer *Container;
4624 unsigned Index;
4625
4626 public:
4627 typedef TemplateArgumentLoc value_type;
4628 typedef TemplateArgumentLoc reference;
4629 typedef int difference_type;
4630 typedef std::input_iterator_tag iterator_category;
4631
4632 class pointer {
4633 TemplateArgumentLoc Arg;
4634
4635 public:
4636 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4637
4638 const TemplateArgumentLoc *operator->() const {
4639 return &Arg;
4640 }
4641 };
4642
4643
4644 TemplateArgumentLocContainerIterator() {}
4645
4646 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4647 unsigned Index)
4648 : Container(&Container), Index(Index) { }
4649
4650 TemplateArgumentLocContainerIterator &operator++() {
4651 ++Index;
4652 return *this;
4653 }
4654
4655 TemplateArgumentLocContainerIterator operator++(int) {
4656 TemplateArgumentLocContainerIterator Old(*this);
4657 ++(*this);
4658 return Old;
4659 }
4660
4661 TemplateArgumentLoc operator*() const {
4662 return Container->getArgLoc(Index);
4663 }
4664
4665 pointer operator->() const {
4666 return pointer(Container->getArgLoc(Index));
4667 }
4668
4669 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004670 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004671 return X.Container == Y.Container && X.Index == Y.Index;
4672 }
4673
4674 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004675 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004676 return !(X == Y);
4677 }
4678 };
4679}
4680
4681
John McCall43fed0d2010-11-12 08:19:04 +00004682template <typename Derived>
4683QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4684 TypeLocBuilder &TLB,
4685 TemplateSpecializationTypeLoc TL,
4686 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004687 TemplateArgumentListInfo NewTemplateArgs;
4688 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4689 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004690 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4691 ArgIterator;
4692 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4693 ArgIterator(TL, TL.getNumArgs()),
4694 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004695 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004696
John McCall833ca992009-10-29 08:12:44 +00004697 // FIXME: maybe don't rebuild if all the template arguments are the same.
4698
4699 QualType Result =
4700 getDerived().RebuildTemplateSpecializationType(Template,
4701 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004702 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004703
4704 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004705 // Specializations of template template parameters are represented as
4706 // TemplateSpecializationTypes, and substitution of type alias templates
4707 // within a dependent context can transform them into
4708 // DependentTemplateSpecializationTypes.
4709 if (isa<DependentTemplateSpecializationType>(Result)) {
4710 DependentTemplateSpecializationTypeLoc NewTL
4711 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004712 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004713 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004714 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004715 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004716 NewTL.setLAngleLoc(TL.getLAngleLoc());
4717 NewTL.setRAngleLoc(TL.getRAngleLoc());
4718 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4719 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4720 return Result;
4721 }
4722
John McCall833ca992009-10-29 08:12:44 +00004723 TemplateSpecializationTypeLoc NewTL
4724 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004725 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004726 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4727 NewTL.setLAngleLoc(TL.getLAngleLoc());
4728 NewTL.setRAngleLoc(TL.getRAngleLoc());
4729 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4730 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004731 }
Mike Stump1eb44332009-09-09 15:08:12 +00004732
John McCall833ca992009-10-29 08:12:44 +00004733 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004734}
Mike Stump1eb44332009-09-09 15:08:12 +00004735
Douglas Gregora88f09f2011-02-28 17:23:35 +00004736template <typename Derived>
4737QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4738 TypeLocBuilder &TLB,
4739 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004740 TemplateName Template,
4741 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004742 TemplateArgumentListInfo NewTemplateArgs;
4743 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4744 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4745 typedef TemplateArgumentLocContainerIterator<
4746 DependentTemplateSpecializationTypeLoc> ArgIterator;
4747 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4748 ArgIterator(TL, TL.getNumArgs()),
4749 NewTemplateArgs))
4750 return QualType();
4751
4752 // FIXME: maybe don't rebuild if all the template arguments are the same.
4753
4754 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4755 QualType Result
4756 = getSema().Context.getDependentTemplateSpecializationType(
4757 TL.getTypePtr()->getKeyword(),
4758 DTN->getQualifier(),
4759 DTN->getIdentifier(),
4760 NewTemplateArgs);
4761
4762 DependentTemplateSpecializationTypeLoc NewTL
4763 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004764 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004765 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004766 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004767 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004768 NewTL.setLAngleLoc(TL.getLAngleLoc());
4769 NewTL.setRAngleLoc(TL.getRAngleLoc());
4770 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4771 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4772 return Result;
4773 }
4774
4775 QualType Result
4776 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004777 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004778 NewTemplateArgs);
4779
4780 if (!Result.isNull()) {
4781 /// FIXME: Wrap this in an elaborated-type-specifier?
4782 TemplateSpecializationTypeLoc NewTL
4783 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004784 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004785 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004786 NewTL.setLAngleLoc(TL.getLAngleLoc());
4787 NewTL.setRAngleLoc(TL.getRAngleLoc());
4788 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4789 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4790 }
4791
4792 return Result;
4793}
4794
Mike Stump1eb44332009-09-09 15:08:12 +00004795template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004796QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004797TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004798 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004799 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004800
Douglas Gregor9e876872011-03-01 18:12:44 +00004801 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004802 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004803 if (TL.getQualifierLoc()) {
4804 QualifierLoc
4805 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4806 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004807 return QualType();
4808 }
Mike Stump1eb44332009-09-09 15:08:12 +00004809
John McCall43fed0d2010-11-12 08:19:04 +00004810 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4811 if (NamedT.isNull())
4812 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004813
Richard Smith3e4c6c42011-05-05 21:57:07 +00004814 // C++0x [dcl.type.elab]p2:
4815 // If the identifier resolves to a typedef-name or the simple-template-id
4816 // resolves to an alias template specialization, the
4817 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004818 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4819 if (const TemplateSpecializationType *TST =
4820 NamedT->getAs<TemplateSpecializationType>()) {
4821 TemplateName Template = TST->getTemplateName();
4822 if (TypeAliasTemplateDecl *TAT =
4823 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4824 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4825 diag::err_tag_reference_non_tag) << 4;
4826 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4827 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004828 }
4829 }
4830
John McCalla2becad2009-10-21 00:40:46 +00004831 QualType Result = TL.getType();
4832 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004833 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004834 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004835 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004836 T->getKeyword(),
4837 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004838 if (Result.isNull())
4839 return QualType();
4840 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004841
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004842 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004843 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004844 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004845 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004846}
Mike Stump1eb44332009-09-09 15:08:12 +00004847
4848template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004849QualType TreeTransform<Derived>::TransformAttributedType(
4850 TypeLocBuilder &TLB,
4851 AttributedTypeLoc TL) {
4852 const AttributedType *oldType = TL.getTypePtr();
4853 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4854 if (modifiedType.isNull())
4855 return QualType();
4856
4857 QualType result = TL.getType();
4858
4859 // FIXME: dependent operand expressions?
4860 if (getDerived().AlwaysRebuild() ||
4861 modifiedType != oldType->getModifiedType()) {
4862 // TODO: this is really lame; we should really be rebuilding the
4863 // equivalent type from first principles.
4864 QualType equivalentType
4865 = getDerived().TransformType(oldType->getEquivalentType());
4866 if (equivalentType.isNull())
4867 return QualType();
4868 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4869 modifiedType,
4870 equivalentType);
4871 }
4872
4873 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4874 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4875 if (TL.hasAttrOperand())
4876 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4877 if (TL.hasAttrExprOperand())
4878 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4879 else if (TL.hasAttrEnumOperand())
4880 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4881
4882 return result;
4883}
4884
4885template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004886QualType
4887TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4888 ParenTypeLoc TL) {
4889 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4890 if (Inner.isNull())
4891 return QualType();
4892
4893 QualType Result = TL.getType();
4894 if (getDerived().AlwaysRebuild() ||
4895 Inner != TL.getInnerLoc().getType()) {
4896 Result = getDerived().RebuildParenType(Inner);
4897 if (Result.isNull())
4898 return QualType();
4899 }
4900
4901 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4902 NewTL.setLParenLoc(TL.getLParenLoc());
4903 NewTL.setRParenLoc(TL.getRParenLoc());
4904 return Result;
4905}
4906
4907template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004908QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004909 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004910 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004911
Douglas Gregor2494dd02011-03-01 01:34:45 +00004912 NestedNameSpecifierLoc QualifierLoc
4913 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4914 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004915 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004916
John McCall33500952010-06-11 00:33:02 +00004917 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004918 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004919 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004920 QualifierLoc,
4921 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004922 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004923 if (Result.isNull())
4924 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004925
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004926 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4927 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004928 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4929
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004930 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004931 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004932 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004933 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004934 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004935 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004936 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004937 NewTL.setNameLoc(TL.getNameLoc());
4938 }
John McCalla2becad2009-10-21 00:40:46 +00004939 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004940}
Mike Stump1eb44332009-09-09 15:08:12 +00004941
Douglas Gregor577f75a2009-08-04 16:50:30 +00004942template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004943QualType TreeTransform<Derived>::
4944 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004945 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004946 NestedNameSpecifierLoc QualifierLoc;
4947 if (TL.getQualifierLoc()) {
4948 QualifierLoc
4949 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4950 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004951 return QualType();
4952 }
4953
John McCall43fed0d2010-11-12 08:19:04 +00004954 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004955 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004956}
4957
4958template<typename Derived>
4959QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004960TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4961 DependentTemplateSpecializationTypeLoc TL,
4962 NestedNameSpecifierLoc QualifierLoc) {
4963 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4964
4965 TemplateArgumentListInfo NewTemplateArgs;
4966 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4967 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4968
4969 typedef TemplateArgumentLocContainerIterator<
4970 DependentTemplateSpecializationTypeLoc> ArgIterator;
4971 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4972 ArgIterator(TL, TL.getNumArgs()),
4973 NewTemplateArgs))
4974 return QualType();
4975
4976 QualType Result
4977 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4978 QualifierLoc,
4979 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004980 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004981 NewTemplateArgs);
4982 if (Result.isNull())
4983 return QualType();
4984
4985 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4986 QualType NamedT = ElabT->getNamedType();
4987
4988 // Copy information relevant to the template specialization.
4989 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004990 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004991 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004992 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004993 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4994 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004995 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004996 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004997
4998 // Copy information relevant to the elaborated type.
4999 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005000 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005001 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005002 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5003 DependentTemplateSpecializationTypeLoc SpecTL
5004 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005005 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005006 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005007 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005008 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005009 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5010 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005011 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005012 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005013 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005014 TemplateSpecializationTypeLoc SpecTL
5015 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005016 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005017 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005018 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5019 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005020 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005021 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005022 }
5023 return Result;
5024}
5025
5026template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005027QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5028 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005029 QualType Pattern
5030 = getDerived().TransformType(TLB, TL.getPatternLoc());
5031 if (Pattern.isNull())
5032 return QualType();
5033
5034 QualType Result = TL.getType();
5035 if (getDerived().AlwaysRebuild() ||
5036 Pattern != TL.getPatternLoc().getType()) {
5037 Result = getDerived().RebuildPackExpansionType(Pattern,
5038 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005039 TL.getEllipsisLoc(),
5040 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005041 if (Result.isNull())
5042 return QualType();
5043 }
5044
5045 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5046 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5047 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005048}
5049
5050template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005051QualType
5052TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005053 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005054 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005055 TLB.pushFullCopy(TL);
5056 return TL.getType();
5057}
5058
5059template<typename Derived>
5060QualType
5061TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005062 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005063 // ObjCObjectType is never dependent.
5064 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005065 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005066}
Mike Stump1eb44332009-09-09 15:08:12 +00005067
5068template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005069QualType
5070TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005071 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005072 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005073 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005074 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005075}
5076
Douglas Gregor577f75a2009-08-04 16:50:30 +00005077//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005078// Statement transformation
5079//===----------------------------------------------------------------------===//
5080template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005081StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005082TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005083 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005084}
5085
5086template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005087StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005088TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5089 return getDerived().TransformCompoundStmt(S, false);
5090}
5091
5092template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005093StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005094TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005095 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005096 Sema::CompoundScopeRAII CompoundScope(getSema());
5097
John McCall7114cba2010-08-27 19:56:05 +00005098 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005099 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005100 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00005101 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5102 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005103 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005104 if (Result.isInvalid()) {
5105 // Immediately fail if this was a DeclStmt, since it's very
5106 // likely that this will cause problems for future statements.
5107 if (isa<DeclStmt>(*B))
5108 return StmtError();
5109
5110 // Otherwise, just keep processing substatements and fail later.
5111 SubStmtInvalid = true;
5112 continue;
5113 }
Mike Stump1eb44332009-09-09 15:08:12 +00005114
Douglas Gregor43959a92009-08-20 07:17:43 +00005115 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5116 Statements.push_back(Result.takeAs<Stmt>());
5117 }
Mike Stump1eb44332009-09-09 15:08:12 +00005118
John McCall7114cba2010-08-27 19:56:05 +00005119 if (SubStmtInvalid)
5120 return StmtError();
5121
Douglas Gregor43959a92009-08-20 07:17:43 +00005122 if (!getDerived().AlwaysRebuild() &&
5123 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005124 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005125
5126 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5127 move_arg(Statements),
5128 S->getRBracLoc(),
5129 IsStmtExpr);
5130}
Mike Stump1eb44332009-09-09 15:08:12 +00005131
Douglas Gregor43959a92009-08-20 07:17:43 +00005132template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005133StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005134TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005135 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005136 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005137 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5138 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005139
Eli Friedman264c1f82009-11-19 03:14:00 +00005140 // Transform the left-hand case value.
5141 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005142 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005143 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005144 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005145
Eli Friedman264c1f82009-11-19 03:14:00 +00005146 // Transform the right-hand case value (for the GNU case-range extension).
5147 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005148 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005149 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005150 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005151 }
Mike Stump1eb44332009-09-09 15:08:12 +00005152
Douglas Gregor43959a92009-08-20 07:17:43 +00005153 // Build the case statement.
5154 // Case statements are always rebuilt so that they will attached to their
5155 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005156 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005157 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005158 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005159 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005160 S->getColonLoc());
5161 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005162 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005163
Douglas Gregor43959a92009-08-20 07:17:43 +00005164 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005165 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005166 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005167 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005168
Douglas Gregor43959a92009-08-20 07:17:43 +00005169 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005170 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005171}
5172
5173template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005174StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005175TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005176 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005177 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005178 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005179 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005180
Douglas Gregor43959a92009-08-20 07:17:43 +00005181 // Default statements are always rebuilt
5182 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005183 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005184}
Mike Stump1eb44332009-09-09 15:08:12 +00005185
Douglas Gregor43959a92009-08-20 07:17:43 +00005186template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005187StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005188TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005189 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005190 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005191 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005192
Chris Lattner57ad3782011-02-17 20:34:02 +00005193 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5194 S->getDecl());
5195 if (!LD)
5196 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005197
5198
Douglas Gregor43959a92009-08-20 07:17:43 +00005199 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005200 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005201 cast<LabelDecl>(LD), SourceLocation(),
5202 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005203}
Mike Stump1eb44332009-09-09 15:08:12 +00005204
Douglas Gregor43959a92009-08-20 07:17:43 +00005205template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005206StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005207TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5208 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5209 if (SubStmt.isInvalid())
5210 return StmtError();
5211
5212 // TODO: transform attributes
5213 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5214 return S;
5215
5216 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5217 S->getAttrs(),
5218 SubStmt.get());
5219}
5220
5221template<typename Derived>
5222StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005223TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005224 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005225 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005226 VarDecl *ConditionVar = 0;
5227 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005228 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005229 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005230 getDerived().TransformDefinition(
5231 S->getConditionVariable()->getLocation(),
5232 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005233 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005234 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005235 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005236 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005237
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005238 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005239 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005240
5241 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005242 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005243 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5244 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005245 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005246 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005247
John McCall9ae2f072010-08-23 23:25:46 +00005248 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005249 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005250 }
Sean Huntc3021132010-05-05 15:23:54 +00005251
John McCall9ae2f072010-08-23 23:25:46 +00005252 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5253 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005254 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005255
Douglas Gregor43959a92009-08-20 07:17:43 +00005256 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005257 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005258 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005259 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005260
Douglas Gregor43959a92009-08-20 07:17:43 +00005261 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005262 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005263 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005264 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005265
Douglas Gregor43959a92009-08-20 07:17:43 +00005266 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005267 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005268 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005269 Then.get() == S->getThen() &&
5270 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005271 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005272
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005273 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005274 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005275 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005276}
5277
5278template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005279StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005280TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005281 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005282 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005283 VarDecl *ConditionVar = 0;
5284 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005285 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005286 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005287 getDerived().TransformDefinition(
5288 S->getConditionVariable()->getLocation(),
5289 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005290 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005291 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005292 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005293 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005294
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005295 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005296 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005297 }
Mike Stump1eb44332009-09-09 15:08:12 +00005298
Douglas Gregor43959a92009-08-20 07:17:43 +00005299 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005300 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005301 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005302 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005303 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005304 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005305
Douglas Gregor43959a92009-08-20 07:17:43 +00005306 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005307 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005308 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005309 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005310
Douglas Gregor43959a92009-08-20 07:17:43 +00005311 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005312 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5313 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005314}
Mike Stump1eb44332009-09-09 15:08:12 +00005315
Douglas Gregor43959a92009-08-20 07:17:43 +00005316template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005317StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005318TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005319 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005320 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005321 VarDecl *ConditionVar = 0;
5322 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005323 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005324 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005325 getDerived().TransformDefinition(
5326 S->getConditionVariable()->getLocation(),
5327 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005328 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005329 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005330 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005331 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005332
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005333 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005334 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005335
5336 if (S->getCond()) {
5337 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005338 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5339 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005340 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005341 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005342 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005343 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005344 }
Mike Stump1eb44332009-09-09 15:08:12 +00005345
John McCall9ae2f072010-08-23 23:25:46 +00005346 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5347 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005348 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005349
Douglas Gregor43959a92009-08-20 07:17:43 +00005350 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005351 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005352 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005353 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005354
Douglas Gregor43959a92009-08-20 07:17:43 +00005355 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005356 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005357 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005358 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005359 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005360
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005361 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005362 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005363}
Mike Stump1eb44332009-09-09 15:08:12 +00005364
Douglas Gregor43959a92009-08-20 07:17:43 +00005365template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005366StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005367TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005368 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005369 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005370 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005371 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005372
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005373 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005374 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005375 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005376 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005377
Douglas Gregor43959a92009-08-20 07:17:43 +00005378 if (!getDerived().AlwaysRebuild() &&
5379 Cond.get() == S->getCond() &&
5380 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005381 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005382
John McCall9ae2f072010-08-23 23:25:46 +00005383 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5384 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005385 S->getRParenLoc());
5386}
Mike Stump1eb44332009-09-09 15:08:12 +00005387
Douglas Gregor43959a92009-08-20 07:17:43 +00005388template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005389StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005390TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005391 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005392 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005393 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005394 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005395
Douglas Gregor43959a92009-08-20 07:17:43 +00005396 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005397 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005398 VarDecl *ConditionVar = 0;
5399 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005400 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005401 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005402 getDerived().TransformDefinition(
5403 S->getConditionVariable()->getLocation(),
5404 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005405 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005406 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005407 } else {
5408 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005409
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005410 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005411 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005412
5413 if (S->getCond()) {
5414 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005415 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5416 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005417 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005418 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005419
John McCall9ae2f072010-08-23 23:25:46 +00005420 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005421 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005422 }
Mike Stump1eb44332009-09-09 15:08:12 +00005423
John McCall9ae2f072010-08-23 23:25:46 +00005424 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5425 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005426 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005427
Douglas Gregor43959a92009-08-20 07:17:43 +00005428 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005429 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005430 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005431 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005432
John McCall9ae2f072010-08-23 23:25:46 +00005433 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5434 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005435 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005436
Douglas Gregor43959a92009-08-20 07:17:43 +00005437 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005438 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005439 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005440 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005441
Douglas Gregor43959a92009-08-20 07:17:43 +00005442 if (!getDerived().AlwaysRebuild() &&
5443 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005444 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005445 Inc.get() == S->getInc() &&
5446 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005447 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005448
Douglas Gregor43959a92009-08-20 07:17:43 +00005449 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005450 Init.get(), FullCond, ConditionVar,
5451 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005452}
5453
5454template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005455StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005456TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005457 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5458 S->getLabel());
5459 if (!LD)
5460 return StmtError();
5461
Douglas Gregor43959a92009-08-20 07:17:43 +00005462 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005463 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005464 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005465}
5466
5467template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005468StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005469TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005470 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005471 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005472 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005473 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005474
Douglas Gregor43959a92009-08-20 07:17:43 +00005475 if (!getDerived().AlwaysRebuild() &&
5476 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005477 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005478
5479 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005480 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005481}
5482
5483template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005484StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005485TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005486 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005487}
Mike Stump1eb44332009-09-09 15:08:12 +00005488
Douglas Gregor43959a92009-08-20 07:17:43 +00005489template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005490StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005491TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005492 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005493}
Mike Stump1eb44332009-09-09 15:08:12 +00005494
Douglas Gregor43959a92009-08-20 07:17:43 +00005495template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005496StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005497TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005498 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005499 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005500 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005501
Mike Stump1eb44332009-09-09 15:08:12 +00005502 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005503 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005504 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005505}
Mike Stump1eb44332009-09-09 15:08:12 +00005506
Douglas Gregor43959a92009-08-20 07:17:43 +00005507template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005508StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005509TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005510 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005511 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005512 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5513 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005514 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5515 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005516 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005517 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005518
Douglas Gregor43959a92009-08-20 07:17:43 +00005519 if (Transformed != *D)
5520 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005521
Douglas Gregor43959a92009-08-20 07:17:43 +00005522 Decls.push_back(Transformed);
5523 }
Mike Stump1eb44332009-09-09 15:08:12 +00005524
Douglas Gregor43959a92009-08-20 07:17:43 +00005525 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005526 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005527
5528 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005529 S->getStartLoc(), S->getEndLoc());
5530}
Mike Stump1eb44332009-09-09 15:08:12 +00005531
Douglas Gregor43959a92009-08-20 07:17:43 +00005532template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005533StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005534TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005535
John McCallca0408f2010-08-23 06:44:23 +00005536 ASTOwningVector<Expr*> Constraints(getSema());
5537 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005538 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005539
John McCall60d7b3a2010-08-24 06:29:42 +00005540 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005541 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005542
5543 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005544
Anders Carlsson703e3942010-01-24 05:50:09 +00005545 // Go through the outputs.
5546 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005547 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005548
Anders Carlsson703e3942010-01-24 05:50:09 +00005549 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005550 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005551
Anders Carlsson703e3942010-01-24 05:50:09 +00005552 // Transform the output expr.
5553 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005554 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005555 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005556 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005557
Anders Carlsson703e3942010-01-24 05:50:09 +00005558 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005559
John McCall9ae2f072010-08-23 23:25:46 +00005560 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005561 }
Sean Huntc3021132010-05-05 15:23:54 +00005562
Anders Carlsson703e3942010-01-24 05:50:09 +00005563 // Go through the inputs.
5564 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005565 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005566
Anders Carlsson703e3942010-01-24 05:50:09 +00005567 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005568 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005569
Anders Carlsson703e3942010-01-24 05:50:09 +00005570 // Transform the input expr.
5571 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005572 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005573 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005574 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005575
Anders Carlsson703e3942010-01-24 05:50:09 +00005576 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005577
John McCall9ae2f072010-08-23 23:25:46 +00005578 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005579 }
Sean Huntc3021132010-05-05 15:23:54 +00005580
Anders Carlsson703e3942010-01-24 05:50:09 +00005581 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005582 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005583
5584 // Go through the clobbers.
5585 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005586 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005587
5588 // No need to transform the asm string literal.
5589 AsmString = SemaRef.Owned(S->getAsmString());
5590
5591 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5592 S->isSimple(),
5593 S->isVolatile(),
5594 S->getNumOutputs(),
5595 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005596 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005597 move_arg(Constraints),
5598 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005599 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005600 move_arg(Clobbers),
5601 S->getRParenLoc(),
5602 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005603}
5604
Chad Rosier8cd64b42012-06-11 20:47:18 +00005605template<typename Derived>
5606StmtResult
5607TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
5608 // No need to transform the asm string literal.
5609 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(),
5610 *S->getAsmString(),
5611 S->getEndLoc());
5612}
Douglas Gregor43959a92009-08-20 07:17:43 +00005613
5614template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005615StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005616TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005617 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005618 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005619 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005620 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005621
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005622 // Transform the @catch statements (if present).
5623 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005624 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005625 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005626 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005627 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005628 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005629 if (Catch.get() != S->getCatchStmt(I))
5630 AnyCatchChanged = true;
5631 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005632 }
Sean Huntc3021132010-05-05 15:23:54 +00005633
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005634 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005635 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005636 if (S->getFinallyStmt()) {
5637 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5638 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005639 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005640 }
5641
5642 // If nothing changed, just retain this statement.
5643 if (!getDerived().AlwaysRebuild() &&
5644 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005645 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005646 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005647 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005648
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005649 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005650 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5651 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005652}
Mike Stump1eb44332009-09-09 15:08:12 +00005653
Douglas Gregor43959a92009-08-20 07:17:43 +00005654template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005655StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005656TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005657 // Transform the @catch parameter, if there is one.
5658 VarDecl *Var = 0;
5659 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5660 TypeSourceInfo *TSInfo = 0;
5661 if (FromVar->getTypeSourceInfo()) {
5662 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5663 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005664 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005665 }
Sean Huntc3021132010-05-05 15:23:54 +00005666
Douglas Gregorbe270a02010-04-26 17:57:08 +00005667 QualType T;
5668 if (TSInfo)
5669 T = TSInfo->getType();
5670 else {
5671 T = getDerived().TransformType(FromVar->getType());
5672 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005673 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005674 }
Sean Huntc3021132010-05-05 15:23:54 +00005675
Douglas Gregorbe270a02010-04-26 17:57:08 +00005676 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5677 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005678 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005679 }
Sean Huntc3021132010-05-05 15:23:54 +00005680
John McCall60d7b3a2010-08-24 06:29:42 +00005681 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005682 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005683 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005684
5685 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005686 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005687 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005688}
Mike Stump1eb44332009-09-09 15:08:12 +00005689
Douglas Gregor43959a92009-08-20 07:17:43 +00005690template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005691StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005692TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005693 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005694 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005695 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005696 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005697
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005698 // If nothing changed, just retain this statement.
5699 if (!getDerived().AlwaysRebuild() &&
5700 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005701 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005702
5703 // Build a new statement.
5704 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005705 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005706}
Mike Stump1eb44332009-09-09 15:08:12 +00005707
Douglas Gregor43959a92009-08-20 07:17:43 +00005708template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005709StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005710TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005711 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005712 if (S->getThrowExpr()) {
5713 Operand = getDerived().TransformExpr(S->getThrowExpr());
5714 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005715 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005716 }
Sean Huntc3021132010-05-05 15:23:54 +00005717
Douglas Gregord1377b22010-04-22 21:44:01 +00005718 if (!getDerived().AlwaysRebuild() &&
5719 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005720 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005721
John McCall9ae2f072010-08-23 23:25:46 +00005722 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005723}
Mike Stump1eb44332009-09-09 15:08:12 +00005724
Douglas Gregor43959a92009-08-20 07:17:43 +00005725template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005726StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005727TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005728 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005729 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005730 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005731 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005732 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005733 Object =
5734 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5735 Object.get());
5736 if (Object.isInvalid())
5737 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005738
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005739 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005740 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005741 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005742 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005743
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005744 // If nothing change, just retain the current statement.
5745 if (!getDerived().AlwaysRebuild() &&
5746 Object.get() == S->getSynchExpr() &&
5747 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005748 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005749
5750 // Build a new statement.
5751 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005752 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005753}
5754
5755template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005756StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005757TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5758 ObjCAutoreleasePoolStmt *S) {
5759 // Transform the body.
5760 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5761 if (Body.isInvalid())
5762 return StmtError();
5763
5764 // If nothing changed, just retain this statement.
5765 if (!getDerived().AlwaysRebuild() &&
5766 Body.get() == S->getSubStmt())
5767 return SemaRef.Owned(S);
5768
5769 // Build a new statement.
5770 return getDerived().RebuildObjCAutoreleasePoolStmt(
5771 S->getAtLoc(), Body.get());
5772}
5773
5774template<typename Derived>
5775StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005776TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005777 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005778 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005779 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005780 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005781 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005782
Douglas Gregorc3203e72010-04-22 23:10:45 +00005783 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005784 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005785 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005786 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005787
Douglas Gregorc3203e72010-04-22 23:10:45 +00005788 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005789 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005790 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005791 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005792
Douglas Gregorc3203e72010-04-22 23:10:45 +00005793 // If nothing changed, just retain this statement.
5794 if (!getDerived().AlwaysRebuild() &&
5795 Element.get() == S->getElement() &&
5796 Collection.get() == S->getCollection() &&
5797 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005798 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005799
Douglas Gregorc3203e72010-04-22 23:10:45 +00005800 // Build a new statement.
5801 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5802 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005803 Element.get(),
5804 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005805 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005806 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005807}
5808
5809
5810template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005811StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005812TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5813 // Transform the exception declaration, if any.
5814 VarDecl *Var = 0;
5815 if (S->getExceptionDecl()) {
5816 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005817 TypeSourceInfo *T = getDerived().TransformType(
5818 ExceptionDecl->getTypeSourceInfo());
5819 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005820 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005821
Douglas Gregor83cb9422010-09-09 17:09:21 +00005822 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005823 ExceptionDecl->getInnerLocStart(),
5824 ExceptionDecl->getLocation(),
5825 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005826 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005827 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005828 }
Mike Stump1eb44332009-09-09 15:08:12 +00005829
Douglas Gregor43959a92009-08-20 07:17:43 +00005830 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005831 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005832 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005833 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005834
Douglas Gregor43959a92009-08-20 07:17:43 +00005835 if (!getDerived().AlwaysRebuild() &&
5836 !Var &&
5837 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005838 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005839
5840 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5841 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005842 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005843}
Mike Stump1eb44332009-09-09 15:08:12 +00005844
Douglas Gregor43959a92009-08-20 07:17:43 +00005845template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005846StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005847TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5848 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005849 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005850 = getDerived().TransformCompoundStmt(S->getTryBlock());
5851 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005852 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005853
Douglas Gregor43959a92009-08-20 07:17:43 +00005854 // Transform the handlers.
5855 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005856 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005857 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005858 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005859 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5860 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005861 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005862
Douglas Gregor43959a92009-08-20 07:17:43 +00005863 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5864 Handlers.push_back(Handler.takeAs<Stmt>());
5865 }
Mike Stump1eb44332009-09-09 15:08:12 +00005866
Douglas Gregor43959a92009-08-20 07:17:43 +00005867 if (!getDerived().AlwaysRebuild() &&
5868 TryBlock.get() == S->getTryBlock() &&
5869 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005870 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005871
John McCall9ae2f072010-08-23 23:25:46 +00005872 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005873 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005874}
Mike Stump1eb44332009-09-09 15:08:12 +00005875
Richard Smithad762fc2011-04-14 22:09:26 +00005876template<typename Derived>
5877StmtResult
5878TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5879 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5880 if (Range.isInvalid())
5881 return StmtError();
5882
5883 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5884 if (BeginEnd.isInvalid())
5885 return StmtError();
5886
5887 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5888 if (Cond.isInvalid())
5889 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005890 if (Cond.get())
5891 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5892 if (Cond.isInvalid())
5893 return StmtError();
5894 if (Cond.get())
5895 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005896
5897 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5898 if (Inc.isInvalid())
5899 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005900 if (Inc.get())
5901 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005902
5903 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5904 if (LoopVar.isInvalid())
5905 return StmtError();
5906
5907 StmtResult NewStmt = S;
5908 if (getDerived().AlwaysRebuild() ||
5909 Range.get() != S->getRangeStmt() ||
5910 BeginEnd.get() != S->getBeginEndStmt() ||
5911 Cond.get() != S->getCond() ||
5912 Inc.get() != S->getInc() ||
5913 LoopVar.get() != S->getLoopVarStmt())
5914 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5915 S->getColonLoc(), Range.get(),
5916 BeginEnd.get(), Cond.get(),
5917 Inc.get(), LoopVar.get(),
5918 S->getRParenLoc());
5919
5920 StmtResult Body = getDerived().TransformStmt(S->getBody());
5921 if (Body.isInvalid())
5922 return StmtError();
5923
5924 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5925 // it now so we have a new statement to attach the body to.
5926 if (Body.get() != S->getBody() && NewStmt.get() == S)
5927 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5928 S->getColonLoc(), Range.get(),
5929 BeginEnd.get(), Cond.get(),
5930 Inc.get(), LoopVar.get(),
5931 S->getRParenLoc());
5932
5933 if (NewStmt.get() == S)
5934 return SemaRef.Owned(S);
5935
5936 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5937}
5938
John Wiegley28bbe4b2011-04-28 01:08:34 +00005939template<typename Derived>
5940StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005941TreeTransform<Derived>::TransformMSDependentExistsStmt(
5942 MSDependentExistsStmt *S) {
5943 // Transform the nested-name-specifier, if any.
5944 NestedNameSpecifierLoc QualifierLoc;
5945 if (S->getQualifierLoc()) {
5946 QualifierLoc
5947 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5948 if (!QualifierLoc)
5949 return StmtError();
5950 }
5951
5952 // Transform the declaration name.
5953 DeclarationNameInfo NameInfo = S->getNameInfo();
5954 if (NameInfo.getName()) {
5955 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5956 if (!NameInfo.getName())
5957 return StmtError();
5958 }
5959
5960 // Check whether anything changed.
5961 if (!getDerived().AlwaysRebuild() &&
5962 QualifierLoc == S->getQualifierLoc() &&
5963 NameInfo.getName() == S->getNameInfo().getName())
5964 return S;
5965
5966 // Determine whether this name exists, if we can.
5967 CXXScopeSpec SS;
5968 SS.Adopt(QualifierLoc);
5969 bool Dependent = false;
5970 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5971 case Sema::IER_Exists:
5972 if (S->isIfExists())
5973 break;
5974
5975 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5976
5977 case Sema::IER_DoesNotExist:
5978 if (S->isIfNotExists())
5979 break;
5980
5981 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5982
5983 case Sema::IER_Dependent:
5984 Dependent = true;
5985 break;
Douglas Gregor65019ac2011-10-25 03:44:56 +00005986
5987 case Sema::IER_Error:
5988 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005989 }
5990
5991 // We need to continue with the instantiation, so do so now.
5992 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5993 if (SubStmt.isInvalid())
5994 return StmtError();
5995
5996 // If we have resolved the name, just transform to the substatement.
5997 if (!Dependent)
5998 return SubStmt;
5999
6000 // The name is still dependent, so build a dependent expression again.
6001 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6002 S->isIfExists(),
6003 QualifierLoc,
6004 NameInfo,
6005 SubStmt.get());
6006}
6007
6008template<typename Derived>
6009StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006010TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6011 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6012 if(TryBlock.isInvalid()) return StmtError();
6013
6014 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6015 if(!getDerived().AlwaysRebuild() &&
6016 TryBlock.get() == S->getTryBlock() &&
6017 Handler.get() == S->getHandler())
6018 return SemaRef.Owned(S);
6019
6020 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6021 S->getTryLoc(),
6022 TryBlock.take(),
6023 Handler.take());
6024}
6025
6026template<typename Derived>
6027StmtResult
6028TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6029 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6030 if(Block.isInvalid()) return StmtError();
6031
6032 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6033 Block.take());
6034}
6035
6036template<typename Derived>
6037StmtResult
6038TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6039 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6040 if(FilterExpr.isInvalid()) return StmtError();
6041
6042 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6043 if(Block.isInvalid()) return StmtError();
6044
6045 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6046 FilterExpr.take(),
6047 Block.take());
6048}
6049
6050template<typename Derived>
6051StmtResult
6052TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6053 if(isa<SEHFinallyStmt>(Handler))
6054 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6055 else
6056 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6057}
6058
Douglas Gregor43959a92009-08-20 07:17:43 +00006059//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006060// Expression transformation
6061//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006062template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006063ExprResult
John McCall454feb92009-12-08 09:21:05 +00006064TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006065 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006066}
Mike Stump1eb44332009-09-09 15:08:12 +00006067
6068template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006069ExprResult
John McCall454feb92009-12-08 09:21:05 +00006070TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006071 NestedNameSpecifierLoc QualifierLoc;
6072 if (E->getQualifierLoc()) {
6073 QualifierLoc
6074 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6075 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006076 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006077 }
John McCalldbd872f2009-12-08 09:08:17 +00006078
6079 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006080 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6081 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006082 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006083 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006084
John McCallec8045d2010-08-17 21:27:17 +00006085 DeclarationNameInfo NameInfo = E->getNameInfo();
6086 if (NameInfo.getName()) {
6087 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6088 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006089 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006090 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006091
6092 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006093 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006094 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006095 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006096 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006097
6098 // Mark it referenced in the new context regardless.
6099 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006100 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006101
John McCall3fa5cae2010-10-26 07:05:15 +00006102 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006103 }
John McCalldbd872f2009-12-08 09:08:17 +00006104
6105 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006106 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006107 TemplateArgs = &TransArgs;
6108 TransArgs.setLAngleLoc(E->getLAngleLoc());
6109 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006110 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6111 E->getNumTemplateArgs(),
6112 TransArgs))
6113 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006114 }
6115
Douglas Gregor40d96a62011-02-28 21:54:11 +00006116 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
6117 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006118}
Mike Stump1eb44332009-09-09 15:08:12 +00006119
Douglas Gregorb98b1992009-08-11 05:31:07 +00006120template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006121ExprResult
John McCall454feb92009-12-08 09:21:05 +00006122TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006123 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006124}
Mike Stump1eb44332009-09-09 15:08:12 +00006125
Douglas Gregorb98b1992009-08-11 05:31:07 +00006126template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006127ExprResult
John McCall454feb92009-12-08 09:21:05 +00006128TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006129 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006130}
Mike Stump1eb44332009-09-09 15:08:12 +00006131
Douglas Gregorb98b1992009-08-11 05:31:07 +00006132template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006133ExprResult
John McCall454feb92009-12-08 09:21:05 +00006134TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006135 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006136}
Mike Stump1eb44332009-09-09 15:08:12 +00006137
Douglas Gregorb98b1992009-08-11 05:31:07 +00006138template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006139ExprResult
John McCall454feb92009-12-08 09:21:05 +00006140TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006141 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006142}
Mike Stump1eb44332009-09-09 15:08:12 +00006143
Douglas Gregorb98b1992009-08-11 05:31:07 +00006144template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006145ExprResult
John McCall454feb92009-12-08 09:21:05 +00006146TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006147 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006148}
6149
6150template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006151ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006152TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6153 return SemaRef.MaybeBindToTemporary(E);
6154}
6155
6156template<typename Derived>
6157ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006158TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6159 ExprResult ControllingExpr =
6160 getDerived().TransformExpr(E->getControllingExpr());
6161 if (ControllingExpr.isInvalid())
6162 return ExprError();
6163
Chris Lattner686775d2011-07-20 06:58:45 +00006164 SmallVector<Expr *, 4> AssocExprs;
6165 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006166 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6167 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6168 if (TS) {
6169 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6170 if (!AssocType)
6171 return ExprError();
6172 AssocTypes.push_back(AssocType);
6173 } else {
6174 AssocTypes.push_back(0);
6175 }
6176
6177 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6178 if (AssocExpr.isInvalid())
6179 return ExprError();
6180 AssocExprs.push_back(AssocExpr.release());
6181 }
6182
6183 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6184 E->getDefaultLoc(),
6185 E->getRParenLoc(),
6186 ControllingExpr.release(),
6187 AssocTypes.data(),
6188 AssocExprs.data(),
6189 E->getNumAssocs());
6190}
6191
6192template<typename Derived>
6193ExprResult
John McCall454feb92009-12-08 09:21:05 +00006194TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006195 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006196 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006197 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006198
Douglas Gregorb98b1992009-08-11 05:31:07 +00006199 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006200 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006201
John McCall9ae2f072010-08-23 23:25:46 +00006202 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006203 E->getRParen());
6204}
6205
Mike Stump1eb44332009-09-09 15:08:12 +00006206template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006207ExprResult
John McCall454feb92009-12-08 09:21:05 +00006208TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006209 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006210 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006211 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006212
Douglas Gregorb98b1992009-08-11 05:31:07 +00006213 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006214 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006215
Douglas Gregorb98b1992009-08-11 05:31:07 +00006216 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6217 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006218 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006219}
Mike Stump1eb44332009-09-09 15:08:12 +00006220
Douglas Gregorb98b1992009-08-11 05:31:07 +00006221template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006222ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006223TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6224 // Transform the type.
6225 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6226 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006227 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006228
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006229 // Transform all of the components into components similar to what the
6230 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00006231 // FIXME: It would be slightly more efficient in the non-dependent case to
6232 // just map FieldDecls, rather than requiring the rebuilder to look for
6233 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006234 // template code that we don't care.
6235 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006236 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006237 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006238 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006239 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6240 const Node &ON = E->getComponent(I);
6241 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006242 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006243 Comp.LocStart = ON.getSourceRange().getBegin();
6244 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006245 switch (ON.getKind()) {
6246 case Node::Array: {
6247 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006248 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006249 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006250 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006251
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006252 ExprChanged = ExprChanged || Index.get() != FromIndex;
6253 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006254 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006255 break;
6256 }
Sean Huntc3021132010-05-05 15:23:54 +00006257
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006258 case Node::Field:
6259 case Node::Identifier:
6260 Comp.isBrackets = false;
6261 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006262 if (!Comp.U.IdentInfo)
6263 continue;
Sean Huntc3021132010-05-05 15:23:54 +00006264
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006265 break;
Sean Huntc3021132010-05-05 15:23:54 +00006266
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006267 case Node::Base:
6268 // Will be recomputed during the rebuild.
6269 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006270 }
Sean Huntc3021132010-05-05 15:23:54 +00006271
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006272 Components.push_back(Comp);
6273 }
Sean Huntc3021132010-05-05 15:23:54 +00006274
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006275 // If nothing changed, retain the existing expression.
6276 if (!getDerived().AlwaysRebuild() &&
6277 Type == E->getTypeSourceInfo() &&
6278 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006279 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006280
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006281 // Build a new offsetof expression.
6282 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6283 Components.data(), Components.size(),
6284 E->getRParenLoc());
6285}
6286
6287template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006288ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006289TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6290 assert(getDerived().AlreadyTransformed(E->getType()) &&
6291 "opaque value expression requires transformation");
6292 return SemaRef.Owned(E);
6293}
6294
6295template<typename Derived>
6296ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006297TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006298 // Rebuild the syntactic form. The original syntactic form has
6299 // opaque-value expressions in it, so strip those away and rebuild
6300 // the result. This is a really awful way of doing this, but the
6301 // better solution (rebuilding the semantic expressions and
6302 // rebinding OVEs as necessary) doesn't work; we'd need
6303 // TreeTransform to not strip away implicit conversions.
6304 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6305 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006306 if (result.isInvalid()) return ExprError();
6307
6308 // If that gives us a pseudo-object result back, the pseudo-object
6309 // expression must have been an lvalue-to-rvalue conversion which we
6310 // should reapply.
6311 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6312 result = SemaRef.checkPseudoObjectRValue(result.take());
6313
6314 return result;
6315}
6316
6317template<typename Derived>
6318ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006319TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6320 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006321 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006322 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006323
John McCalla93c9342009-12-07 02:54:59 +00006324 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006325 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006326 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006327
John McCall5ab75172009-11-04 07:28:41 +00006328 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006329 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006330
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006331 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6332 E->getKind(),
6333 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006334 }
Mike Stump1eb44332009-09-09 15:08:12 +00006335
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006336 // C++0x [expr.sizeof]p1:
6337 // The operand is either an expression, which is an unevaluated operand
6338 // [...]
6339 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006340
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006341 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6342 if (SubExpr.isInvalid())
6343 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006344
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006345 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6346 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006347
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006348 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6349 E->getOperatorLoc(),
6350 E->getKind(),
6351 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006352}
Mike Stump1eb44332009-09-09 15:08:12 +00006353
Douglas Gregorb98b1992009-08-11 05:31:07 +00006354template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006355ExprResult
John McCall454feb92009-12-08 09:21:05 +00006356TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006357 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006358 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006359 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006360
John McCall60d7b3a2010-08-24 06:29:42 +00006361 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006362 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006363 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006364
6365
Douglas Gregorb98b1992009-08-11 05:31:07 +00006366 if (!getDerived().AlwaysRebuild() &&
6367 LHS.get() == E->getLHS() &&
6368 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006369 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006370
John McCall9ae2f072010-08-23 23:25:46 +00006371 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006372 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006373 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006374 E->getRBracketLoc());
6375}
Mike Stump1eb44332009-09-09 15:08:12 +00006376
6377template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006378ExprResult
John McCall454feb92009-12-08 09:21:05 +00006379TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006380 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006381 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006382 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006383 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006384
6385 // Transform arguments.
6386 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006387 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006388 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6389 &ArgChanged))
6390 return ExprError();
6391
Douglas Gregorb98b1992009-08-11 05:31:07 +00006392 if (!getDerived().AlwaysRebuild() &&
6393 Callee.get() == E->getCallee() &&
6394 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006395 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006396
Douglas Gregorb98b1992009-08-11 05:31:07 +00006397 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006398 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006399 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006400 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006401 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006402 E->getRParenLoc());
6403}
Mike Stump1eb44332009-09-09 15:08:12 +00006404
6405template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006406ExprResult
John McCall454feb92009-12-08 09:21:05 +00006407TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006408 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006409 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006410 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006411
Douglas Gregor40d96a62011-02-28 21:54:11 +00006412 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006413 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006414 QualifierLoc
6415 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6416
6417 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006418 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006419 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006420 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006421
Eli Friedmanf595cc42009-12-04 06:40:45 +00006422 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006423 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6424 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006425 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006426 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006427
John McCall6bb80172010-03-30 21:47:33 +00006428 NamedDecl *FoundDecl = E->getFoundDecl();
6429 if (FoundDecl == E->getMemberDecl()) {
6430 FoundDecl = Member;
6431 } else {
6432 FoundDecl = cast_or_null<NamedDecl>(
6433 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6434 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006435 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006436 }
6437
Douglas Gregorb98b1992009-08-11 05:31:07 +00006438 if (!getDerived().AlwaysRebuild() &&
6439 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006440 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006441 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006442 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006443 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006444
Anders Carlsson1f240322009-12-22 05:24:09 +00006445 // Mark it referenced in the new context regardless.
6446 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006447 SemaRef.MarkMemberReferenced(E);
6448
John McCall3fa5cae2010-10-26 07:05:15 +00006449 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006450 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006451
John McCalld5532b62009-11-23 01:53:49 +00006452 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006453 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006454 TransArgs.setLAngleLoc(E->getLAngleLoc());
6455 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006456 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6457 E->getNumTemplateArgs(),
6458 TransArgs))
6459 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006460 }
Sean Huntc3021132010-05-05 15:23:54 +00006461
Douglas Gregorb98b1992009-08-11 05:31:07 +00006462 // FIXME: Bogus source location for the operator
6463 SourceLocation FakeOperatorLoc
6464 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6465
John McCallc2233c52010-01-15 08:34:02 +00006466 // FIXME: to do this check properly, we will need to preserve the
6467 // first-qualifier-in-scope here, just in case we had a dependent
6468 // base (and therefore couldn't do the check) and a
6469 // nested-name-qualifier (and therefore could do the lookup).
6470 NamedDecl *FirstQualifierInScope = 0;
6471
John McCall9ae2f072010-08-23 23:25:46 +00006472 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006473 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006474 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006475 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006476 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006477 Member,
John McCall6bb80172010-03-30 21:47:33 +00006478 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006479 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006480 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006481 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006482}
Mike Stump1eb44332009-09-09 15:08:12 +00006483
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006485ExprResult
John McCall454feb92009-12-08 09:21:05 +00006486TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006487 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006488 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006489 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006490
John McCall60d7b3a2010-08-24 06:29:42 +00006491 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006492 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006493 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006494
Douglas Gregorb98b1992009-08-11 05:31:07 +00006495 if (!getDerived().AlwaysRebuild() &&
6496 LHS.get() == E->getLHS() &&
6497 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006498 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006499
Douglas Gregorb98b1992009-08-11 05:31:07 +00006500 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006501 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006502}
6503
Mike Stump1eb44332009-09-09 15:08:12 +00006504template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006505ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006506TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006507 CompoundAssignOperator *E) {
6508 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006509}
Mike Stump1eb44332009-09-09 15:08:12 +00006510
Douglas Gregorb98b1992009-08-11 05:31:07 +00006511template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006512ExprResult TreeTransform<Derived>::
6513TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6514 // Just rebuild the common and RHS expressions and see whether we
6515 // get any changes.
6516
6517 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6518 if (commonExpr.isInvalid())
6519 return ExprError();
6520
6521 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6522 if (rhs.isInvalid())
6523 return ExprError();
6524
6525 if (!getDerived().AlwaysRebuild() &&
6526 commonExpr.get() == e->getCommon() &&
6527 rhs.get() == e->getFalseExpr())
6528 return SemaRef.Owned(e);
6529
6530 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6531 e->getQuestionLoc(),
6532 0,
6533 e->getColonLoc(),
6534 rhs.get());
6535}
6536
6537template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006538ExprResult
John McCall454feb92009-12-08 09:21:05 +00006539TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006540 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006541 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006542 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006543
John McCall60d7b3a2010-08-24 06:29:42 +00006544 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006545 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006546 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006547
John McCall60d7b3a2010-08-24 06:29:42 +00006548 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006549 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006550 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006551
Douglas Gregorb98b1992009-08-11 05:31:07 +00006552 if (!getDerived().AlwaysRebuild() &&
6553 Cond.get() == E->getCond() &&
6554 LHS.get() == E->getLHS() &&
6555 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006556 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006557
John McCall9ae2f072010-08-23 23:25:46 +00006558 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006559 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006560 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006561 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006562 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006563}
Mike Stump1eb44332009-09-09 15:08:12 +00006564
6565template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006566ExprResult
John McCall454feb92009-12-08 09:21:05 +00006567TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006568 // Implicit casts are eliminated during transformation, since they
6569 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006570 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006571}
Mike Stump1eb44332009-09-09 15:08:12 +00006572
Douglas Gregorb98b1992009-08-11 05:31:07 +00006573template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006574ExprResult
John McCall454feb92009-12-08 09:21:05 +00006575TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006576 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6577 if (!Type)
6578 return ExprError();
6579
John McCall60d7b3a2010-08-24 06:29:42 +00006580 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006581 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006582 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006583 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006584
Douglas Gregorb98b1992009-08-11 05:31:07 +00006585 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006586 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006587 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006588 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006589
John McCall9d125032010-01-15 18:39:57 +00006590 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006591 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006592 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006593 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006594}
Mike Stump1eb44332009-09-09 15:08:12 +00006595
Douglas Gregorb98b1992009-08-11 05:31:07 +00006596template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006597ExprResult
John McCall454feb92009-12-08 09:21:05 +00006598TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006599 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6600 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6601 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006602 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006603
John McCall60d7b3a2010-08-24 06:29:42 +00006604 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006605 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006606 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006607
Douglas Gregorb98b1992009-08-11 05:31:07 +00006608 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006609 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006610 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006611 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006612
John McCall1d7d8d62010-01-19 22:33:45 +00006613 // Note: the expression type doesn't necessarily match the
6614 // type-as-written, but that's okay, because it should always be
6615 // derivable from the initializer.
6616
John McCall42f56b52010-01-18 19:35:47 +00006617 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006618 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006619 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006620}
Mike Stump1eb44332009-09-09 15:08:12 +00006621
Douglas Gregorb98b1992009-08-11 05:31:07 +00006622template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006623ExprResult
John McCall454feb92009-12-08 09:21:05 +00006624TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006625 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006626 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006627 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006628
Douglas Gregorb98b1992009-08-11 05:31:07 +00006629 if (!getDerived().AlwaysRebuild() &&
6630 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006631 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006632
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006634 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006636 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006637 E->getAccessorLoc(),
6638 E->getAccessor());
6639}
Mike Stump1eb44332009-09-09 15:08:12 +00006640
Douglas Gregorb98b1992009-08-11 05:31:07 +00006641template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006642ExprResult
John McCall454feb92009-12-08 09:21:05 +00006643TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006644 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006645
John McCallca0408f2010-08-23 06:44:23 +00006646 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006647 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6648 Inits, &InitChanged))
6649 return ExprError();
6650
Douglas Gregorb98b1992009-08-11 05:31:07 +00006651 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006652 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006653
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006655 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006656}
Mike Stump1eb44332009-09-09 15:08:12 +00006657
Douglas Gregorb98b1992009-08-11 05:31:07 +00006658template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006659ExprResult
John McCall454feb92009-12-08 09:21:05 +00006660TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006661 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006662
Douglas Gregor43959a92009-08-20 07:17:43 +00006663 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006664 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006665 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006666 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006667
Douglas Gregor43959a92009-08-20 07:17:43 +00006668 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006669 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006670 bool ExprChanged = false;
6671 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6672 DEnd = E->designators_end();
6673 D != DEnd; ++D) {
6674 if (D->isFieldDesignator()) {
6675 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6676 D->getDotLoc(),
6677 D->getFieldLoc()));
6678 continue;
6679 }
Mike Stump1eb44332009-09-09 15:08:12 +00006680
Douglas Gregorb98b1992009-08-11 05:31:07 +00006681 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006682 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006683 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006684 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006685
6686 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006687 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006688
Douglas Gregorb98b1992009-08-11 05:31:07 +00006689 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6690 ArrayExprs.push_back(Index.release());
6691 continue;
6692 }
Mike Stump1eb44332009-09-09 15:08:12 +00006693
Douglas Gregorb98b1992009-08-11 05:31:07 +00006694 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006695 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006696 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6697 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006698 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006699
John McCall60d7b3a2010-08-24 06:29:42 +00006700 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006701 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006702 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006703
6704 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006705 End.get(),
6706 D->getLBracketLoc(),
6707 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006708
Douglas Gregorb98b1992009-08-11 05:31:07 +00006709 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6710 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006711
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712 ArrayExprs.push_back(Start.release());
6713 ArrayExprs.push_back(End.release());
6714 }
Mike Stump1eb44332009-09-09 15:08:12 +00006715
Douglas Gregorb98b1992009-08-11 05:31:07 +00006716 if (!getDerived().AlwaysRebuild() &&
6717 Init.get() == E->getInit() &&
6718 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006719 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006720
Douglas Gregorb98b1992009-08-11 05:31:07 +00006721 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6722 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006723 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006724}
Mike Stump1eb44332009-09-09 15:08:12 +00006725
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006727ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006728TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006729 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006730 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006731
Douglas Gregor5557b252009-10-28 00:29:27 +00006732 // FIXME: Will we ever have proper type location here? Will we actually
6733 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006734 QualType T = getDerived().TransformType(E->getType());
6735 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006736 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006737
Douglas Gregorb98b1992009-08-11 05:31:07 +00006738 if (!getDerived().AlwaysRebuild() &&
6739 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006740 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006741
Douglas Gregorb98b1992009-08-11 05:31:07 +00006742 return getDerived().RebuildImplicitValueInitExpr(T);
6743}
Mike Stump1eb44332009-09-09 15:08:12 +00006744
Douglas Gregorb98b1992009-08-11 05:31:07 +00006745template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006746ExprResult
John McCall454feb92009-12-08 09:21:05 +00006747TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006748 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6749 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006750 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006751
John McCall60d7b3a2010-08-24 06:29:42 +00006752 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006753 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006754 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006755
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006757 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006758 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006759 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006760
John McCall9ae2f072010-08-23 23:25:46 +00006761 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006762 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006763}
6764
6765template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006766ExprResult
John McCall454feb92009-12-08 09:21:05 +00006767TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006768 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006769 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006770 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6771 &ArgumentChanged))
6772 return ExprError();
6773
Douglas Gregorb98b1992009-08-11 05:31:07 +00006774 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6775 move_arg(Inits),
6776 E->getRParenLoc());
6777}
Mike Stump1eb44332009-09-09 15:08:12 +00006778
Douglas Gregorb98b1992009-08-11 05:31:07 +00006779/// \brief Transform an address-of-label expression.
6780///
6781/// By default, the transformation of an address-of-label expression always
6782/// rebuilds the expression, so that the label identifier can be resolved to
6783/// the corresponding label statement by semantic analysis.
6784template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006785ExprResult
John McCall454feb92009-12-08 09:21:05 +00006786TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006787 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6788 E->getLabel());
6789 if (!LD)
6790 return ExprError();
6791
Douglas Gregorb98b1992009-08-11 05:31:07 +00006792 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006793 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006794}
Mike Stump1eb44332009-09-09 15:08:12 +00006795
6796template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006797ExprResult
John McCall454feb92009-12-08 09:21:05 +00006798TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006799 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006800 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006801 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006802 if (SubStmt.isInvalid()) {
6803 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006804 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006805 }
Mike Stump1eb44332009-09-09 15:08:12 +00006806
Douglas Gregorb98b1992009-08-11 05:31:07 +00006807 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006808 SubStmt.get() == E->getSubStmt()) {
6809 // Calling this an 'error' is unintuitive, but it does the right thing.
6810 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006811 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006812 }
Mike Stump1eb44332009-09-09 15:08:12 +00006813
6814 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006815 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006816 E->getRParenLoc());
6817}
Mike Stump1eb44332009-09-09 15:08:12 +00006818
Douglas Gregorb98b1992009-08-11 05:31:07 +00006819template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006820ExprResult
John McCall454feb92009-12-08 09:21:05 +00006821TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006822 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006823 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006824 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006825
John McCall60d7b3a2010-08-24 06:29:42 +00006826 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006827 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006828 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006829
John McCall60d7b3a2010-08-24 06:29:42 +00006830 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006831 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006832 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006833
Douglas Gregorb98b1992009-08-11 05:31:07 +00006834 if (!getDerived().AlwaysRebuild() &&
6835 Cond.get() == E->getCond() &&
6836 LHS.get() == E->getLHS() &&
6837 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006838 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006839
Douglas Gregorb98b1992009-08-11 05:31:07 +00006840 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006841 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006842 E->getRParenLoc());
6843}
Mike Stump1eb44332009-09-09 15:08:12 +00006844
Douglas Gregorb98b1992009-08-11 05:31:07 +00006845template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006846ExprResult
John McCall454feb92009-12-08 09:21:05 +00006847TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006848 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006849}
6850
6851template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006852ExprResult
John McCall454feb92009-12-08 09:21:05 +00006853TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006854 switch (E->getOperator()) {
6855 case OO_New:
6856 case OO_Delete:
6857 case OO_Array_New:
6858 case OO_Array_Delete:
6859 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Sean Huntc3021132010-05-05 15:23:54 +00006860
Douglas Gregor668d6d92009-12-13 20:44:55 +00006861 case OO_Call: {
6862 // This is a call to an object's operator().
6863 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6864
6865 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006866 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006867 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006868 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006869
6870 // FIXME: Poor location information
6871 SourceLocation FakeLParenLoc
6872 = SemaRef.PP.getLocForEndOfToken(
6873 static_cast<Expr *>(Object.get())->getLocEnd());
6874
6875 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006876 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006877 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6878 Args))
6879 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006880
John McCall9ae2f072010-08-23 23:25:46 +00006881 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006882 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006883 E->getLocEnd());
6884 }
6885
6886#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6887 case OO_##Name:
6888#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6889#include "clang/Basic/OperatorKinds.def"
6890 case OO_Subscript:
6891 // Handled below.
6892 break;
6893
6894 case OO_Conditional:
6895 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006896
6897 case OO_None:
6898 case NUM_OVERLOADED_OPERATORS:
6899 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006900 }
6901
John McCall60d7b3a2010-08-24 06:29:42 +00006902 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006903 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006904 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006905
John McCall60d7b3a2010-08-24 06:29:42 +00006906 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006907 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006908 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006909
John McCall60d7b3a2010-08-24 06:29:42 +00006910 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006911 if (E->getNumArgs() == 2) {
6912 Second = getDerived().TransformExpr(E->getArg(1));
6913 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006914 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006915 }
Mike Stump1eb44332009-09-09 15:08:12 +00006916
Douglas Gregorb98b1992009-08-11 05:31:07 +00006917 if (!getDerived().AlwaysRebuild() &&
6918 Callee.get() == E->getCallee() &&
6919 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006920 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006921 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006922
Douglas Gregorb98b1992009-08-11 05:31:07 +00006923 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6924 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006925 Callee.get(),
6926 First.get(),
6927 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006928}
Mike Stump1eb44332009-09-09 15:08:12 +00006929
Douglas Gregorb98b1992009-08-11 05:31:07 +00006930template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006931ExprResult
John McCall454feb92009-12-08 09:21:05 +00006932TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6933 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006934}
Mike Stump1eb44332009-09-09 15:08:12 +00006935
Douglas Gregorb98b1992009-08-11 05:31:07 +00006936template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006937ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006938TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6939 // Transform the callee.
6940 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6941 if (Callee.isInvalid())
6942 return ExprError();
6943
6944 // Transform exec config.
6945 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6946 if (EC.isInvalid())
6947 return ExprError();
6948
6949 // Transform arguments.
6950 bool ArgChanged = false;
6951 ASTOwningVector<Expr*> Args(SemaRef);
6952 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6953 &ArgChanged))
6954 return ExprError();
6955
6956 if (!getDerived().AlwaysRebuild() &&
6957 Callee.get() == E->getCallee() &&
6958 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006959 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006960
6961 // FIXME: Wrong source location information for the '('.
6962 SourceLocation FakeLParenLoc
6963 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6964 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6965 move_arg(Args),
6966 E->getRParenLoc(), EC.get());
6967}
6968
6969template<typename Derived>
6970ExprResult
John McCall454feb92009-12-08 09:21:05 +00006971TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006972 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6973 if (!Type)
6974 return ExprError();
6975
John McCall60d7b3a2010-08-24 06:29:42 +00006976 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006977 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006978 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006979 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006980
Douglas Gregorb98b1992009-08-11 05:31:07 +00006981 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006982 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006983 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006984 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006985
Douglas Gregorb98b1992009-08-11 05:31:07 +00006986 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006987 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006988 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6989 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6990 SourceLocation FakeRParenLoc
6991 = SemaRef.PP.getLocForEndOfToken(
6992 E->getSubExpr()->getSourceRange().getEnd());
6993 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006994 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006995 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006996 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006997 FakeRAngleLoc,
6998 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006999 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007000 FakeRParenLoc);
7001}
Mike Stump1eb44332009-09-09 15:08:12 +00007002
Douglas Gregorb98b1992009-08-11 05:31:07 +00007003template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007004ExprResult
John McCall454feb92009-12-08 09:21:05 +00007005TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7006 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007007}
Mike Stump1eb44332009-09-09 15:08:12 +00007008
7009template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007010ExprResult
John McCall454feb92009-12-08 09:21:05 +00007011TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7012 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007013}
7014
Douglas Gregorb98b1992009-08-11 05:31:07 +00007015template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007016ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007017TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007018 CXXReinterpretCastExpr *E) {
7019 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007020}
Mike Stump1eb44332009-09-09 15:08:12 +00007021
Douglas Gregorb98b1992009-08-11 05:31:07 +00007022template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007023ExprResult
John McCall454feb92009-12-08 09:21:05 +00007024TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7025 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007026}
Mike Stump1eb44332009-09-09 15:08:12 +00007027
Douglas Gregorb98b1992009-08-11 05:31:07 +00007028template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007029ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007030TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007031 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007032 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7033 if (!Type)
7034 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007035
John McCall60d7b3a2010-08-24 06:29:42 +00007036 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007037 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007038 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007039 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007040
Douglas Gregorb98b1992009-08-11 05:31:07 +00007041 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007042 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007043 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007044 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007045
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007046 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007047 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007048 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007049 E->getRParenLoc());
7050}
Mike Stump1eb44332009-09-09 15:08:12 +00007051
Douglas Gregorb98b1992009-08-11 05:31:07 +00007052template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007053ExprResult
John McCall454feb92009-12-08 09:21:05 +00007054TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007055 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007056 TypeSourceInfo *TInfo
7057 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7058 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007059 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007060
Douglas Gregorb98b1992009-08-11 05:31:07 +00007061 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007062 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007063 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007064
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007065 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7066 E->getLocStart(),
7067 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007068 E->getLocEnd());
7069 }
Mike Stump1eb44332009-09-09 15:08:12 +00007070
Eli Friedmanef331b72012-01-20 01:26:23 +00007071 // We don't know whether the subexpression is potentially evaluated until
7072 // after we perform semantic analysis. We speculatively assume it is
7073 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007074 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00007075 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00007076
John McCall60d7b3a2010-08-24 06:29:42 +00007077 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007078 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007079 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007080
Douglas Gregorb98b1992009-08-11 05:31:07 +00007081 if (!getDerived().AlwaysRebuild() &&
7082 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007083 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007084
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007085 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7086 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007087 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007088 E->getLocEnd());
7089}
7090
7091template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007092ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007093TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7094 if (E->isTypeOperand()) {
7095 TypeSourceInfo *TInfo
7096 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7097 if (!TInfo)
7098 return ExprError();
7099
7100 if (!getDerived().AlwaysRebuild() &&
7101 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007102 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007103
Douglas Gregor3c52a212011-03-06 17:40:41 +00007104 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007105 E->getLocStart(),
7106 TInfo,
7107 E->getLocEnd());
7108 }
7109
Francois Pichet01b7c302010-09-08 12:20:18 +00007110 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7111
7112 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7113 if (SubExpr.isInvalid())
7114 return ExprError();
7115
7116 if (!getDerived().AlwaysRebuild() &&
7117 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007118 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007119
7120 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7121 E->getLocStart(),
7122 SubExpr.get(),
7123 E->getLocEnd());
7124}
7125
7126template<typename Derived>
7127ExprResult
John McCall454feb92009-12-08 09:21:05 +00007128TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007129 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007130}
Mike Stump1eb44332009-09-09 15:08:12 +00007131
Douglas Gregorb98b1992009-08-11 05:31:07 +00007132template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007133ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007134TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007135 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007136 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007137}
Mike Stump1eb44332009-09-09 15:08:12 +00007138
Douglas Gregorb98b1992009-08-11 05:31:07 +00007139template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007140ExprResult
John McCall454feb92009-12-08 09:21:05 +00007141TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007142 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007143 QualType T;
7144 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7145 T = MD->getThisType(getSema().Context);
7146 else
7147 T = getSema().Context.getPointerType(
7148 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007149
Douglas Gregorec79d872012-02-24 17:41:38 +00007150 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7151 // Make sure that we capture 'this'.
7152 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007153 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007154 }
7155
Douglas Gregor828a1972010-01-07 23:12:05 +00007156 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007157}
Mike Stump1eb44332009-09-09 15:08:12 +00007158
Douglas Gregorb98b1992009-08-11 05:31:07 +00007159template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007160ExprResult
John McCall454feb92009-12-08 09:21:05 +00007161TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007162 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007163 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007164 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007165
Douglas Gregorb98b1992009-08-11 05:31:07 +00007166 if (!getDerived().AlwaysRebuild() &&
7167 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007168 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007169
Douglas Gregorbca01b42011-07-06 22:04:06 +00007170 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7171 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007172}
Mike Stump1eb44332009-09-09 15:08:12 +00007173
Douglas Gregorb98b1992009-08-11 05:31:07 +00007174template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007175ExprResult
John McCall454feb92009-12-08 09:21:05 +00007176TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007177 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007178 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7179 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007180 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007181 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007182
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007183 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007184 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007185 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007186
Douglas Gregor036aed12009-12-23 23:03:06 +00007187 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007188}
Mike Stump1eb44332009-09-09 15:08:12 +00007189
Douglas Gregorb98b1992009-08-11 05:31:07 +00007190template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007191ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007192TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7193 CXXScalarValueInitExpr *E) {
7194 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7195 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007196 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00007197
Douglas Gregorb98b1992009-08-11 05:31:07 +00007198 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007199 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007200 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007201
Douglas Gregorab6677e2010-09-08 00:15:04 +00007202 return getDerived().RebuildCXXScalarValueInitExpr(T,
7203 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007204 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007205}
Mike Stump1eb44332009-09-09 15:08:12 +00007206
Douglas Gregorb98b1992009-08-11 05:31:07 +00007207template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007208ExprResult
John McCall454feb92009-12-08 09:21:05 +00007209TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007210 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007211 TypeSourceInfo *AllocTypeInfo
7212 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7213 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007214 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007215
Douglas Gregorb98b1992009-08-11 05:31:07 +00007216 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007217 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007218 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007219 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007220
Douglas Gregorb98b1992009-08-11 05:31:07 +00007221 // Transform the placement arguments (if any).
7222 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007223 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007224 if (getDerived().TransformExprs(E->getPlacementArgs(),
7225 E->getNumPlacementArgs(), true,
7226 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007227 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007228
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007229 // Transform the initializer (if any).
7230 Expr *OldInit = E->getInitializer();
7231 ExprResult NewInit;
7232 if (OldInit)
7233 NewInit = getDerived().TransformExpr(OldInit);
7234 if (NewInit.isInvalid())
7235 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007236
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007237 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007238 FunctionDecl *OperatorNew = 0;
7239 if (E->getOperatorNew()) {
7240 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007241 getDerived().TransformDecl(E->getLocStart(),
7242 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007243 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007244 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007245 }
7246
7247 FunctionDecl *OperatorDelete = 0;
7248 if (E->getOperatorDelete()) {
7249 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007250 getDerived().TransformDecl(E->getLocStart(),
7251 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007252 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007253 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007254 }
Sean Huntc3021132010-05-05 15:23:54 +00007255
Douglas Gregorb98b1992009-08-11 05:31:07 +00007256 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007257 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007258 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007259 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007260 OperatorNew == E->getOperatorNew() &&
7261 OperatorDelete == E->getOperatorDelete() &&
7262 !ArgumentChanged) {
7263 // Mark any declarations we need as referenced.
7264 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007265 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007266 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007267 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007268 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007269
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007270 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007271 QualType ElementType
7272 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7273 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7274 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7275 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007276 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007277 }
7278 }
7279 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007280
John McCall3fa5cae2010-10-26 07:05:15 +00007281 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007282 }
Mike Stump1eb44332009-09-09 15:08:12 +00007283
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007284 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007285 if (!ArraySize.get()) {
7286 // If no array size was specified, but the new expression was
7287 // instantiated with an array type (e.g., "new T" where T is
7288 // instantiated with "int[4]"), extract the outer bound from the
7289 // array type as our array size. We do this with constant and
7290 // dependently-sized array types.
7291 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7292 if (!ArrayT) {
7293 // Do nothing
7294 } else if (const ConstantArrayType *ConsArrayT
7295 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007296 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007297 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7298 ConsArrayT->getSize(),
7299 SemaRef.Context.getSizeType(),
7300 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007301 AllocType = ConsArrayT->getElementType();
7302 } else if (const DependentSizedArrayType *DepArrayT
7303 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7304 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007305 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007306 AllocType = DepArrayT->getElementType();
7307 }
7308 }
7309 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007310
Douglas Gregorb98b1992009-08-11 05:31:07 +00007311 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7312 E->isGlobalNew(),
7313 /*FIXME:*/E->getLocStart(),
7314 move_arg(PlacementArgs),
7315 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007316 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007317 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007318 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007319 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007320 E->getDirectInitRange(),
7321 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007322}
Mike Stump1eb44332009-09-09 15:08:12 +00007323
Douglas Gregorb98b1992009-08-11 05:31:07 +00007324template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007325ExprResult
John McCall454feb92009-12-08 09:21:05 +00007326TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007327 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007328 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007329 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007330
Douglas Gregor1af74512010-02-26 00:38:10 +00007331 // Transform the delete operator, if known.
7332 FunctionDecl *OperatorDelete = 0;
7333 if (E->getOperatorDelete()) {
7334 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007335 getDerived().TransformDecl(E->getLocStart(),
7336 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007337 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007338 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007339 }
Sean Huntc3021132010-05-05 15:23:54 +00007340
Douglas Gregorb98b1992009-08-11 05:31:07 +00007341 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007342 Operand.get() == E->getArgument() &&
7343 OperatorDelete == E->getOperatorDelete()) {
7344 // Mark any declarations we need as referenced.
7345 // FIXME: instantiation-specific.
7346 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007347 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007348
7349 if (!E->getArgument()->isTypeDependent()) {
7350 QualType Destroyed = SemaRef.Context.getBaseElementType(
7351 E->getDestroyedType());
7352 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7353 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Eli Friedman5f2987c2012-02-02 03:46:19 +00007354 SemaRef.MarkFunctionReferenced(E->getLocStart(),
7355 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007356 }
7357 }
7358
John McCall3fa5cae2010-10-26 07:05:15 +00007359 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007360 }
Mike Stump1eb44332009-09-09 15:08:12 +00007361
Douglas Gregorb98b1992009-08-11 05:31:07 +00007362 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7363 E->isGlobalDelete(),
7364 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007365 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007366}
Mike Stump1eb44332009-09-09 15:08:12 +00007367
Douglas Gregorb98b1992009-08-11 05:31:07 +00007368template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007369ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007370TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007371 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007372 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007373 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007374 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007375
John McCallb3d87482010-08-24 05:47:05 +00007376 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007377 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007378 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007379 E->getOperatorLoc(),
7380 E->isArrow()? tok::arrow : tok::period,
7381 ObjectTypePtr,
7382 MayBePseudoDestructor);
7383 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007384 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007385
John McCallb3d87482010-08-24 05:47:05 +00007386 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007387 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7388 if (QualifierLoc) {
7389 QualifierLoc
7390 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7391 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007392 return ExprError();
7393 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007394 CXXScopeSpec SS;
7395 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007396
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007397 PseudoDestructorTypeStorage Destroyed;
7398 if (E->getDestroyedTypeInfo()) {
7399 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007400 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007401 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007402 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007403 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007404 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007405 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007406 // We aren't likely to be able to resolve the identifier down to a type
7407 // now anyway, so just retain the identifier.
7408 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7409 E->getDestroyedTypeLoc());
7410 } else {
7411 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007412 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007413 *E->getDestroyedTypeIdentifier(),
7414 E->getDestroyedTypeLoc(),
7415 /*Scope=*/0,
7416 SS, ObjectTypePtr,
7417 false);
7418 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007419 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007420
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007421 Destroyed
7422 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7423 E->getDestroyedTypeLoc());
7424 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007425
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007426 TypeSourceInfo *ScopeTypeInfo = 0;
7427 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007428 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007429 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007430 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007431 }
Sean Huntc3021132010-05-05 15:23:54 +00007432
John McCall9ae2f072010-08-23 23:25:46 +00007433 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007434 E->getOperatorLoc(),
7435 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007436 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007437 ScopeTypeInfo,
7438 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007439 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007440 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007441}
Mike Stump1eb44332009-09-09 15:08:12 +00007442
Douglas Gregora71d8192009-09-04 17:36:40 +00007443template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007444ExprResult
John McCallba135432009-11-21 08:51:07 +00007445TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007446 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007447 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7448 Sema::LookupOrdinaryName);
7449
7450 // Transform all the decls.
7451 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7452 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007453 NamedDecl *InstD = static_cast<NamedDecl*>(
7454 getDerived().TransformDecl(Old->getNameLoc(),
7455 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007456 if (!InstD) {
7457 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7458 // This can happen because of dependent hiding.
7459 if (isa<UsingShadowDecl>(*I))
7460 continue;
7461 else
John McCallf312b1e2010-08-26 23:41:50 +00007462 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007463 }
John McCallf7a1a742009-11-24 19:00:30 +00007464
7465 // Expand using declarations.
7466 if (isa<UsingDecl>(InstD)) {
7467 UsingDecl *UD = cast<UsingDecl>(InstD);
7468 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7469 E = UD->shadow_end(); I != E; ++I)
7470 R.addDecl(*I);
7471 continue;
7472 }
7473
7474 R.addDecl(InstD);
7475 }
7476
7477 // Resolve a kind, but don't do any further analysis. If it's
7478 // ambiguous, the callee needs to deal with it.
7479 R.resolveKind();
7480
7481 // Rebuild the nested-name qualifier, if present.
7482 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007483 if (Old->getQualifierLoc()) {
7484 NestedNameSpecifierLoc QualifierLoc
7485 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7486 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007487 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007488
Douglas Gregor4c9be892011-02-28 20:01:57 +00007489 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007490 }
7491
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007492 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007493 CXXRecordDecl *NamingClass
7494 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7495 Old->getNameLoc(),
7496 Old->getNamingClass()));
7497 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007498 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007499
Douglas Gregor66c45152010-04-27 16:10:10 +00007500 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007501 }
7502
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007503 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7504
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007505 // If we have neither explicit template arguments, nor the template keyword,
7506 // it's a normal declaration name.
7507 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007508 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7509
7510 // If we have template arguments, rebuild them, then rebuild the
7511 // templateid expression.
7512 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007513 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7514 Old->getNumTemplateArgs(),
7515 TransArgs))
7516 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007517
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007518 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007519 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007520}
Mike Stump1eb44332009-09-09 15:08:12 +00007521
Douglas Gregorb98b1992009-08-11 05:31:07 +00007522template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007523ExprResult
John McCall454feb92009-12-08 09:21:05 +00007524TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007525 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7526 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007527 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007528
Douglas Gregorb98b1992009-08-11 05:31:07 +00007529 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007530 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007531 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007532
Mike Stump1eb44332009-09-09 15:08:12 +00007533 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007534 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007535 T,
7536 E->getLocEnd());
7537}
Mike Stump1eb44332009-09-09 15:08:12 +00007538
Douglas Gregorb98b1992009-08-11 05:31:07 +00007539template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007540ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007541TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7542 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7543 if (!LhsT)
7544 return ExprError();
7545
7546 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7547 if (!RhsT)
7548 return ExprError();
7549
7550 if (!getDerived().AlwaysRebuild() &&
7551 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7552 return SemaRef.Owned(E);
7553
7554 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7555 E->getLocStart(),
7556 LhsT, RhsT,
7557 E->getLocEnd());
7558}
7559
7560template<typename Derived>
7561ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007562TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7563 bool ArgChanged = false;
7564 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7565 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7566 TypeSourceInfo *From = E->getArg(I);
7567 TypeLoc FromTL = From->getTypeLoc();
7568 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7569 TypeLocBuilder TLB;
7570 TLB.reserve(FromTL.getFullDataSize());
7571 QualType To = getDerived().TransformType(TLB, FromTL);
7572 if (To.isNull())
7573 return ExprError();
7574
7575 if (To == From->getType())
7576 Args.push_back(From);
7577 else {
7578 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7579 ArgChanged = true;
7580 }
7581 continue;
7582 }
7583
7584 ArgChanged = true;
7585
7586 // We have a pack expansion. Instantiate it.
7587 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
7588 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7589 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7590 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
7591
7592 // Determine whether the set of unexpanded parameter packs can and should
7593 // be expanded.
7594 bool Expand = true;
7595 bool RetainExpansion = false;
7596 llvm::Optional<unsigned> OrigNumExpansions
7597 = ExpansionTL.getTypePtr()->getNumExpansions();
7598 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7599 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7600 PatternTL.getSourceRange(),
7601 Unexpanded,
7602 Expand, RetainExpansion,
7603 NumExpansions))
7604 return ExprError();
7605
7606 if (!Expand) {
7607 // The transform has determined that we should perform a simple
7608 // transformation on the pack expansion, producing another pack
7609 // expansion.
7610 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7611
7612 TypeLocBuilder TLB;
7613 TLB.reserve(From->getTypeLoc().getFullDataSize());
7614
7615 QualType To = getDerived().TransformType(TLB, PatternTL);
7616 if (To.isNull())
7617 return ExprError();
7618
7619 To = getDerived().RebuildPackExpansionType(To,
7620 PatternTL.getSourceRange(),
7621 ExpansionTL.getEllipsisLoc(),
7622 NumExpansions);
7623 if (To.isNull())
7624 return ExprError();
7625
7626 PackExpansionTypeLoc ToExpansionTL
7627 = TLB.push<PackExpansionTypeLoc>(To);
7628 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7629 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7630 continue;
7631 }
7632
7633 // Expand the pack expansion by substituting for each argument in the
7634 // pack(s).
7635 for (unsigned I = 0; I != *NumExpansions; ++I) {
7636 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7637 TypeLocBuilder TLB;
7638 TLB.reserve(PatternTL.getFullDataSize());
7639 QualType To = getDerived().TransformType(TLB, PatternTL);
7640 if (To.isNull())
7641 return ExprError();
7642
7643 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7644 }
7645
7646 if (!RetainExpansion)
7647 continue;
7648
7649 // If we're supposed to retain a pack expansion, do so by temporarily
7650 // forgetting the partially-substituted parameter pack.
7651 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7652
7653 TypeLocBuilder TLB;
7654 TLB.reserve(From->getTypeLoc().getFullDataSize());
7655
7656 QualType To = getDerived().TransformType(TLB, PatternTL);
7657 if (To.isNull())
7658 return ExprError();
7659
7660 To = getDerived().RebuildPackExpansionType(To,
7661 PatternTL.getSourceRange(),
7662 ExpansionTL.getEllipsisLoc(),
7663 NumExpansions);
7664 if (To.isNull())
7665 return ExprError();
7666
7667 PackExpansionTypeLoc ToExpansionTL
7668 = TLB.push<PackExpansionTypeLoc>(To);
7669 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7670 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7671 }
7672
7673 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7674 return SemaRef.Owned(E);
7675
7676 return getDerived().RebuildTypeTrait(E->getTrait(),
7677 E->getLocStart(),
7678 Args,
7679 E->getLocEnd());
7680}
7681
7682template<typename Derived>
7683ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007684TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7685 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7686 if (!T)
7687 return ExprError();
7688
7689 if (!getDerived().AlwaysRebuild() &&
7690 T == E->getQueriedTypeSourceInfo())
7691 return SemaRef.Owned(E);
7692
7693 ExprResult SubExpr;
7694 {
7695 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7696 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7697 if (SubExpr.isInvalid())
7698 return ExprError();
7699
7700 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7701 return SemaRef.Owned(E);
7702 }
7703
7704 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7705 E->getLocStart(),
7706 T,
7707 SubExpr.get(),
7708 E->getLocEnd());
7709}
7710
7711template<typename Derived>
7712ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007713TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7714 ExprResult SubExpr;
7715 {
7716 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7717 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7718 if (SubExpr.isInvalid())
7719 return ExprError();
7720
7721 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7722 return SemaRef.Owned(E);
7723 }
7724
7725 return getDerived().RebuildExpressionTrait(
7726 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7727}
7728
7729template<typename Derived>
7730ExprResult
John McCall865d4472009-11-19 22:55:06 +00007731TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007732 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007733 NestedNameSpecifierLoc QualifierLoc
7734 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7735 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007736 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007737 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007738
John McCall43fed0d2010-11-12 08:19:04 +00007739 // TODO: If this is a conversion-function-id, verify that the
7740 // destination type name (if present) resolves the same way after
7741 // instantiation as it did in the local scope.
7742
Abramo Bagnara25777432010-08-11 22:01:17 +00007743 DeclarationNameInfo NameInfo
7744 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7745 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007746 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007747
John McCallf7a1a742009-11-24 19:00:30 +00007748 if (!E->hasExplicitTemplateArgs()) {
7749 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007750 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007751 // Note: it is sufficient to compare the Name component of NameInfo:
7752 // if name has not changed, DNLoc has not changed either.
7753 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007754 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007755
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007756 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007757 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007758 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007759 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007760 }
John McCalld5532b62009-11-23 01:53:49 +00007761
7762 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007763 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7764 E->getNumTemplateArgs(),
7765 TransArgs))
7766 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007767
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007768 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007769 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007770 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007771 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007772}
7773
7774template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007775ExprResult
John McCall454feb92009-12-08 09:21:05 +00007776TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007777 // CXXConstructExprs are always implicit, so when we have a
7778 // 1-argument construction we just transform that argument.
7779 if (E->getNumArgs() == 1 ||
7780 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7781 return getDerived().TransformExpr(E->getArg(0));
7782
Douglas Gregorb98b1992009-08-11 05:31:07 +00007783 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7784
7785 QualType T = getDerived().TransformType(E->getType());
7786 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007787 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007788
7789 CXXConstructorDecl *Constructor
7790 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007791 getDerived().TransformDecl(E->getLocStart(),
7792 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007793 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007794 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007795
Douglas Gregorb98b1992009-08-11 05:31:07 +00007796 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007797 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007798 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7799 &ArgumentChanged))
7800 return ExprError();
7801
Douglas Gregorb98b1992009-08-11 05:31:07 +00007802 if (!getDerived().AlwaysRebuild() &&
7803 T == E->getType() &&
7804 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007805 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007806 // Mark the constructor as referenced.
7807 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007808 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007809 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007810 }
Mike Stump1eb44332009-09-09 15:08:12 +00007811
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007812 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7813 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007814 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007815 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007816 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007817 E->getConstructionKind(),
7818 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007819}
Mike Stump1eb44332009-09-09 15:08:12 +00007820
Douglas Gregorb98b1992009-08-11 05:31:07 +00007821/// \brief Transform a C++ temporary-binding expression.
7822///
Douglas Gregor51326552009-12-24 18:51:59 +00007823/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7824/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007825template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007826ExprResult
John McCall454feb92009-12-08 09:21:05 +00007827TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007828 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007829}
Mike Stump1eb44332009-09-09 15:08:12 +00007830
John McCall4765fa02010-12-06 08:20:24 +00007831/// \brief Transform a C++ expression that contains cleanups that should
7832/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007833///
John McCall4765fa02010-12-06 08:20:24 +00007834/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007835/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007836template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007837ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007838TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007839 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007840}
Mike Stump1eb44332009-09-09 15:08:12 +00007841
Douglas Gregorb98b1992009-08-11 05:31:07 +00007842template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007843ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007844TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007845 CXXTemporaryObjectExpr *E) {
7846 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7847 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007848 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007849
Douglas Gregorb98b1992009-08-11 05:31:07 +00007850 CXXConstructorDecl *Constructor
7851 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007852 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007853 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007854 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007855 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007856
Douglas Gregorb98b1992009-08-11 05:31:07 +00007857 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007858 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007859 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007860 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7861 &ArgumentChanged))
7862 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007863
Douglas Gregorb98b1992009-08-11 05:31:07 +00007864 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007865 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007866 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007867 !ArgumentChanged) {
7868 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007869 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007870 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007871 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007872
7873 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7874 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007875 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007876 E->getLocEnd());
7877}
Mike Stump1eb44332009-09-09 15:08:12 +00007878
Douglas Gregorb98b1992009-08-11 05:31:07 +00007879template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007880ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007881TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007882 // Create the local class that will describe the lambda.
7883 CXXRecordDecl *Class
Douglas Gregorf54486a2012-04-04 17:40:10 +00007884 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7885 /*KnownDependent=*/false);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007886 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7887
7888 // Transform the type of the lambda parameters and start the definition of
7889 // the lambda itself.
7890 TypeSourceInfo *MethodTy
7891 = TransformType(E->getCallOperator()->getTypeSourceInfo());
7892 if (!MethodTy)
7893 return ExprError();
7894
Douglas Gregorc6889e72012-02-14 22:28:59 +00007895 // Transform lambda parameters.
7896 bool Invalid = false;
7897 llvm::SmallVector<QualType, 4> ParamTypes;
7898 llvm::SmallVector<ParmVarDecl *, 4> Params;
7899 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7900 E->getCallOperator()->param_begin(),
7901 E->getCallOperator()->param_size(),
7902 0, ParamTypes, &Params))
7903 Invalid = true;
7904
Douglas Gregordfca6f52012-02-13 22:00:16 +00007905 // Build the call operator.
Douglas Gregorf54486a2012-04-04 17:40:10 +00007906 // Note: Once a lambda mangling number and context declaration have been
7907 // assigned, they never change.
7908 unsigned ManglingNumber = E->getLambdaClass()->getLambdaManglingNumber();
7909 Decl *ContextDecl = E->getLambdaClass()->getLambdaContextDecl();
Douglas Gregordfca6f52012-02-13 22:00:16 +00007910 CXXMethodDecl *CallOperator
7911 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
7912 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007913 E->getCallOperator()->getLocEnd(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00007914 Params, ManglingNumber, ContextDecl);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007915 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
7916
Douglas Gregord5387e82012-02-14 00:00:48 +00007917 // FIXME: Instantiation-specific.
7918 CallOperator->setInstantiationOfMemberFunction(E->getCallOperator(),
7919 TSK_ImplicitInstantiation);
7920
7921 // Introduce the context of the call operator.
7922 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7923
Douglas Gregordfca6f52012-02-13 22:00:16 +00007924 // Enter the scope of the lambda.
7925 sema::LambdaScopeInfo *LSI
7926 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7927 E->getCaptureDefault(),
7928 E->hasExplicitParameters(),
7929 E->hasExplicitResultType(),
7930 E->isMutable());
7931
7932 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00007933 bool FinishedExplicitCaptures = false;
7934 for (LambdaExpr::capture_iterator C = E->capture_begin(),
7935 CEnd = E->capture_end();
7936 C != CEnd; ++C) {
7937 // When we hit the first implicit capture, tell Sema that we've finished
7938 // the list of explicit captures.
7939 if (!FinishedExplicitCaptures && C->isImplicit()) {
7940 getSema().finishLambdaExplicitCaptures(LSI);
7941 FinishedExplicitCaptures = true;
7942 }
7943
7944 // Capturing 'this' is trivial.
7945 if (C->capturesThis()) {
7946 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7947 continue;
7948 }
7949
Douglas Gregora7365242012-02-14 19:27:52 +00007950 // Determine the capture kind for Sema.
7951 Sema::TryCaptureKind Kind
7952 = C->isImplicit()? Sema::TryCapture_Implicit
7953 : C->getCaptureKind() == LCK_ByCopy
7954 ? Sema::TryCapture_ExplicitByVal
7955 : Sema::TryCapture_ExplicitByRef;
7956 SourceLocation EllipsisLoc;
7957 if (C->isPackExpansion()) {
7958 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7959 bool ShouldExpand = false;
7960 bool RetainExpansion = false;
7961 llvm::Optional<unsigned> NumExpansions;
7962 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7963 C->getLocation(),
7964 Unexpanded,
7965 ShouldExpand, RetainExpansion,
7966 NumExpansions))
7967 return ExprError();
7968
7969 if (ShouldExpand) {
7970 // The transform has determined that we should perform an expansion;
7971 // transform and capture each of the arguments.
7972 // expansion of the pattern. Do so.
7973 VarDecl *Pack = C->getCapturedVar();
7974 for (unsigned I = 0; I != *NumExpansions; ++I) {
7975 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7976 VarDecl *CapturedVar
7977 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7978 Pack));
7979 if (!CapturedVar) {
7980 Invalid = true;
7981 continue;
7982 }
7983
7984 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007985 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregora7365242012-02-14 19:27:52 +00007986 }
7987 continue;
7988 }
7989
7990 EllipsisLoc = C->getEllipsisLoc();
7991 }
7992
Douglas Gregordfca6f52012-02-13 22:00:16 +00007993 // Transform the captured variable.
7994 VarDecl *CapturedVar
7995 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7996 C->getCapturedVar()));
7997 if (!CapturedVar) {
7998 Invalid = true;
7999 continue;
8000 }
Douglas Gregora7365242012-02-14 19:27:52 +00008001
Douglas Gregordfca6f52012-02-13 22:00:16 +00008002 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008003 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008004 }
8005 if (!FinishedExplicitCaptures)
8006 getSema().finishLambdaExplicitCaptures(LSI);
8007
Douglas Gregordfca6f52012-02-13 22:00:16 +00008008
8009 // Enter a new evaluation context to insulate the lambda from any
8010 // cleanups from the enclosing full-expression.
8011 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
8012
8013 if (Invalid) {
8014 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
8015 /*IsInstantiation=*/true);
8016 return ExprError();
8017 }
8018
8019 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008020 StmtResult Body = getDerived().TransformStmt(E->getBody());
8021 if (Body.isInvalid()) {
8022 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
8023 /*IsInstantiation=*/true);
8024 return ExprError();
8025 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008026
Douglas Gregordfca6f52012-02-13 22:00:16 +00008027 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008028 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008029}
8030
8031template<typename Derived>
8032ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008033TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008034 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008035 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8036 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008037 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008038
Douglas Gregorb98b1992009-08-11 05:31:07 +00008039 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008040 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008041 Args.reserve(E->arg_size());
8042 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
8043 &ArgumentChanged))
8044 return ExprError();
8045
Douglas Gregorb98b1992009-08-11 05:31:07 +00008046 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008047 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008048 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008049 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008050
Douglas Gregorb98b1992009-08-11 05:31:07 +00008051 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008052 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008053 E->getLParenLoc(),
8054 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00008055 E->getRParenLoc());
8056}
Mike Stump1eb44332009-09-09 15:08:12 +00008057
Douglas Gregorb98b1992009-08-11 05:31:07 +00008058template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008059ExprResult
John McCall865d4472009-11-19 22:55:06 +00008060TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008061 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008062 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008063 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008064 Expr *OldBase;
8065 QualType BaseType;
8066 QualType ObjectType;
8067 if (!E->isImplicitAccess()) {
8068 OldBase = E->getBase();
8069 Base = getDerived().TransformExpr(OldBase);
8070 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008071 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008072
John McCallaa81e162009-12-01 22:10:20 +00008073 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008074 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008075 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008076 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008077 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008078 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008079 ObjectTy,
8080 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008081 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008082 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008083
John McCallb3d87482010-08-24 05:47:05 +00008084 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008085 BaseType = ((Expr*) Base.get())->getType();
8086 } else {
8087 OldBase = 0;
8088 BaseType = getDerived().TransformType(E->getBaseType());
8089 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8090 }
Mike Stump1eb44332009-09-09 15:08:12 +00008091
Douglas Gregor6cd21982009-10-20 05:58:46 +00008092 // Transform the first part of the nested-name-specifier that qualifies
8093 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008094 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008095 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008096 E->getFirstQualifierFoundInScope(),
8097 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008098
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008099 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008100 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008101 QualifierLoc
8102 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8103 ObjectType,
8104 FirstQualifierInScope);
8105 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008106 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008107 }
Mike Stump1eb44332009-09-09 15:08:12 +00008108
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008109 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8110
John McCall43fed0d2010-11-12 08:19:04 +00008111 // TODO: If this is a conversion-function-id, verify that the
8112 // destination type name (if present) resolves the same way after
8113 // instantiation as it did in the local scope.
8114
Abramo Bagnara25777432010-08-11 22:01:17 +00008115 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008116 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008117 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008118 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008119
John McCallaa81e162009-12-01 22:10:20 +00008120 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008121 // This is a reference to a member without an explicitly-specified
8122 // template argument list. Optimize for this common case.
8123 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008124 Base.get() == OldBase &&
8125 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008126 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008127 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008128 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008129 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008130
John McCall9ae2f072010-08-23 23:25:46 +00008131 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008132 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008133 E->isArrow(),
8134 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008135 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008136 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008137 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008138 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008139 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008140 }
8141
John McCalld5532b62009-11-23 01:53:49 +00008142 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008143 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8144 E->getNumTemplateArgs(),
8145 TransArgs))
8146 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008147
John McCall9ae2f072010-08-23 23:25:46 +00008148 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008149 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008150 E->isArrow(),
8151 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008152 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008153 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008154 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008155 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008156 &TransArgs);
8157}
8158
8159template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008160ExprResult
John McCall454feb92009-12-08 09:21:05 +00008161TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008162 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008163 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008164 QualType BaseType;
8165 if (!Old->isImplicitAccess()) {
8166 Base = getDerived().TransformExpr(Old->getBase());
8167 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008168 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008169 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8170 Old->isArrow());
8171 if (Base.isInvalid())
8172 return ExprError();
8173 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008174 } else {
8175 BaseType = getDerived().TransformType(Old->getBaseType());
8176 }
John McCall129e2df2009-11-30 22:42:35 +00008177
Douglas Gregor4c9be892011-02-28 20:01:57 +00008178 NestedNameSpecifierLoc QualifierLoc;
8179 if (Old->getQualifierLoc()) {
8180 QualifierLoc
8181 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8182 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008183 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008184 }
8185
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008186 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8187
Abramo Bagnara25777432010-08-11 22:01:17 +00008188 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008189 Sema::LookupOrdinaryName);
8190
8191 // Transform all the decls.
8192 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8193 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008194 NamedDecl *InstD = static_cast<NamedDecl*>(
8195 getDerived().TransformDecl(Old->getMemberLoc(),
8196 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008197 if (!InstD) {
8198 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8199 // This can happen because of dependent hiding.
8200 if (isa<UsingShadowDecl>(*I))
8201 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008202 else {
8203 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008204 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008205 }
John McCall9f54ad42009-12-10 09:41:52 +00008206 }
John McCall129e2df2009-11-30 22:42:35 +00008207
8208 // Expand using declarations.
8209 if (isa<UsingDecl>(InstD)) {
8210 UsingDecl *UD = cast<UsingDecl>(InstD);
8211 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8212 E = UD->shadow_end(); I != E; ++I)
8213 R.addDecl(*I);
8214 continue;
8215 }
8216
8217 R.addDecl(InstD);
8218 }
8219
8220 R.resolveKind();
8221
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008222 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008223 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00008224 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008225 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008226 Old->getMemberLoc(),
8227 Old->getNamingClass()));
8228 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008229 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008230
Douglas Gregor66c45152010-04-27 16:10:10 +00008231 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008232 }
Sean Huntc3021132010-05-05 15:23:54 +00008233
John McCall129e2df2009-11-30 22:42:35 +00008234 TemplateArgumentListInfo TransArgs;
8235 if (Old->hasExplicitTemplateArgs()) {
8236 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8237 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008238 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8239 Old->getNumTemplateArgs(),
8240 TransArgs))
8241 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008242 }
John McCallc2233c52010-01-15 08:34:02 +00008243
8244 // FIXME: to do this check properly, we will need to preserve the
8245 // first-qualifier-in-scope here, just in case we had a dependent
8246 // base (and therefore couldn't do the check) and a
8247 // nested-name-qualifier (and therefore could do the lookup).
8248 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00008249
John McCall9ae2f072010-08-23 23:25:46 +00008250 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008251 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008252 Old->getOperatorLoc(),
8253 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008254 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008255 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008256 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008257 R,
8258 (Old->hasExplicitTemplateArgs()
8259 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008260}
8261
8262template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008263ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008264TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008265 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008266 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8267 if (SubExpr.isInvalid())
8268 return ExprError();
8269
8270 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008271 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008272
8273 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8274}
8275
8276template<typename Derived>
8277ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008278TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008279 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8280 if (Pattern.isInvalid())
8281 return ExprError();
8282
8283 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8284 return SemaRef.Owned(E);
8285
Douglas Gregor67fd1252011-01-14 21:20:45 +00008286 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8287 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008288}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008289
8290template<typename Derived>
8291ExprResult
8292TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8293 // If E is not value-dependent, then nothing will change when we transform it.
8294 // Note: This is an instantiation-centric view.
8295 if (!E->isValueDependent())
8296 return SemaRef.Owned(E);
8297
8298 // Note: None of the implementations of TryExpandParameterPacks can ever
8299 // produce a diagnostic when given only a single unexpanded parameter pack,
8300 // so
8301 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8302 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008303 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008304 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00008305 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008306 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008307 ShouldExpand, RetainExpansion,
8308 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008309 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00008310
Douglas Gregor089e8932011-10-10 18:59:29 +00008311 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008312 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00008313
8314 NamedDecl *Pack = E->getPack();
8315 if (!ShouldExpand) {
8316 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
8317 Pack));
8318 if (!Pack)
8319 return ExprError();
8320 }
8321
Douglas Gregoree8aff02011-01-04 17:33:58 +00008322
8323 // We now know the length of the parameter pack, so build a new expression
8324 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00008325 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00008326 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008327 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008328}
8329
Douglas Gregorbe230c32011-01-03 17:17:50 +00008330template<typename Derived>
8331ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008332TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8333 SubstNonTypeTemplateParmPackExpr *E) {
8334 // Default behavior is to do nothing with this transformation.
8335 return SemaRef.Owned(E);
8336}
8337
8338template<typename Derived>
8339ExprResult
John McCall91a57552011-07-15 05:09:51 +00008340TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8341 SubstNonTypeTemplateParmExpr *E) {
8342 // Default behavior is to do nothing with this transformation.
8343 return SemaRef.Owned(E);
8344}
8345
8346template<typename Derived>
8347ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008348TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8349 MaterializeTemporaryExpr *E) {
8350 return getDerived().TransformExpr(E->GetTemporaryExpr());
8351}
8352
8353template<typename Derived>
8354ExprResult
John McCall454feb92009-12-08 09:21:05 +00008355TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008356 return SemaRef.MaybeBindToTemporary(E);
8357}
8358
8359template<typename Derived>
8360ExprResult
8361TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008362 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008363}
8364
8365template<typename Derived>
8366ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008367TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8368 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8369 if (SubExpr.isInvalid())
8370 return ExprError();
8371
8372 if (!getDerived().AlwaysRebuild() &&
8373 SubExpr.get() == E->getSubExpr())
8374 return SemaRef.Owned(E);
8375
8376 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008377}
8378
8379template<typename Derived>
8380ExprResult
8381TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8382 // Transform each of the elements.
8383 llvm::SmallVector<Expr *, 8> Elements;
8384 bool ArgChanged = false;
8385 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
8386 /*IsCall=*/false, Elements, &ArgChanged))
8387 return ExprError();
8388
8389 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8390 return SemaRef.MaybeBindToTemporary(E);
8391
8392 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8393 Elements.data(),
8394 Elements.size());
8395}
8396
8397template<typename Derived>
8398ExprResult
8399TreeTransform<Derived>::TransformObjCDictionaryLiteral(
8400 ObjCDictionaryLiteral *E) {
8401 // Transform each of the elements.
8402 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8403 bool ArgChanged = false;
8404 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8405 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
8406
8407 if (OrigElement.isPackExpansion()) {
8408 // This key/value element is a pack expansion.
8409 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8410 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8411 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8412 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8413
8414 // Determine whether the set of unexpanded parameter packs can
8415 // and should be expanded.
8416 bool Expand = true;
8417 bool RetainExpansion = false;
8418 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8419 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8420 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8421 OrigElement.Value->getLocEnd());
8422 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8423 PatternRange,
8424 Unexpanded,
8425 Expand, RetainExpansion,
8426 NumExpansions))
8427 return ExprError();
8428
8429 if (!Expand) {
8430 // The transform has determined that we should perform a simple
8431 // transformation on the pack expansion, producing another pack
8432 // expansion.
8433 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8434 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8435 if (Key.isInvalid())
8436 return ExprError();
8437
8438 if (Key.get() != OrigElement.Key)
8439 ArgChanged = true;
8440
8441 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8442 if (Value.isInvalid())
8443 return ExprError();
8444
8445 if (Value.get() != OrigElement.Value)
8446 ArgChanged = true;
8447
8448 ObjCDictionaryElement Expansion = {
8449 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8450 };
8451 Elements.push_back(Expansion);
8452 continue;
8453 }
8454
8455 // Record right away that the argument was changed. This needs
8456 // to happen even if the array expands to nothing.
8457 ArgChanged = true;
8458
8459 // The transform has determined that we should perform an elementwise
8460 // expansion of the pattern. Do so.
8461 for (unsigned I = 0; I != *NumExpansions; ++I) {
8462 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8463 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8464 if (Key.isInvalid())
8465 return ExprError();
8466
8467 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8468 if (Value.isInvalid())
8469 return ExprError();
8470
8471 ObjCDictionaryElement Element = {
8472 Key.get(), Value.get(), SourceLocation(), NumExpansions
8473 };
8474
8475 // If any unexpanded parameter packs remain, we still have a
8476 // pack expansion.
8477 if (Key.get()->containsUnexpandedParameterPack() ||
8478 Value.get()->containsUnexpandedParameterPack())
8479 Element.EllipsisLoc = OrigElement.EllipsisLoc;
8480
8481 Elements.push_back(Element);
8482 }
8483
8484 // We've finished with this pack expansion.
8485 continue;
8486 }
8487
8488 // Transform and check key.
8489 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8490 if (Key.isInvalid())
8491 return ExprError();
8492
8493 if (Key.get() != OrigElement.Key)
8494 ArgChanged = true;
8495
8496 // Transform and check value.
8497 ExprResult Value
8498 = getDerived().TransformExpr(OrigElement.Value);
8499 if (Value.isInvalid())
8500 return ExprError();
8501
8502 if (Value.get() != OrigElement.Value)
8503 ArgChanged = true;
8504
8505 ObjCDictionaryElement Element = {
8506 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8507 };
8508 Elements.push_back(Element);
8509 }
8510
8511 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8512 return SemaRef.MaybeBindToTemporary(E);
8513
8514 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8515 Elements.data(),
8516 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008517}
8518
Mike Stump1eb44332009-09-09 15:08:12 +00008519template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008520ExprResult
John McCall454feb92009-12-08 09:21:05 +00008521TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008522 TypeSourceInfo *EncodedTypeInfo
8523 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8524 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008525 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008526
Douglas Gregorb98b1992009-08-11 05:31:07 +00008527 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008528 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008529 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008530
8531 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008532 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008533 E->getRParenLoc());
8534}
Mike Stump1eb44332009-09-09 15:08:12 +00008535
Douglas Gregorb98b1992009-08-11 05:31:07 +00008536template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008537ExprResult TreeTransform<Derived>::
8538TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8539 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8540 if (result.isInvalid()) return ExprError();
8541 Expr *subExpr = result.take();
8542
8543 if (!getDerived().AlwaysRebuild() &&
8544 subExpr == E->getSubExpr())
8545 return SemaRef.Owned(E);
8546
8547 return SemaRef.Owned(new(SemaRef.Context)
8548 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8549}
8550
8551template<typename Derived>
8552ExprResult TreeTransform<Derived>::
8553TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
8554 TypeSourceInfo *TSInfo
8555 = getDerived().TransformType(E->getTypeInfoAsWritten());
8556 if (!TSInfo)
8557 return ExprError();
8558
8559 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
8560 if (Result.isInvalid())
8561 return ExprError();
8562
8563 if (!getDerived().AlwaysRebuild() &&
8564 TSInfo == E->getTypeInfoAsWritten() &&
8565 Result.get() == E->getSubExpr())
8566 return SemaRef.Owned(E);
8567
8568 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
8569 E->getBridgeKeywordLoc(), TSInfo,
8570 Result.get());
8571}
8572
8573template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008574ExprResult
John McCall454feb92009-12-08 09:21:05 +00008575TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008576 // Transform arguments.
8577 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008578 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008579 Args.reserve(E->getNumArgs());
8580 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
8581 &ArgChanged))
8582 return ExprError();
8583
Douglas Gregor92e986e2010-04-22 16:44:27 +00008584 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8585 // Class message: transform the receiver type.
8586 TypeSourceInfo *ReceiverTypeInfo
8587 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8588 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008589 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008590
Douglas Gregor92e986e2010-04-22 16:44:27 +00008591 // If nothing changed, just retain the existing message send.
8592 if (!getDerived().AlwaysRebuild() &&
8593 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008594 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008595
8596 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008597 SmallVector<SourceLocation, 16> SelLocs;
8598 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008599 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8600 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008601 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008602 E->getMethodDecl(),
8603 E->getLeftLoc(),
8604 move_arg(Args),
8605 E->getRightLoc());
8606 }
8607
8608 // Instance message: transform the receiver
8609 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8610 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008611 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008612 = getDerived().TransformExpr(E->getInstanceReceiver());
8613 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008614 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008615
8616 // If nothing changed, just retain the existing message send.
8617 if (!getDerived().AlwaysRebuild() &&
8618 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008619 return SemaRef.MaybeBindToTemporary(E);
Sean Huntc3021132010-05-05 15:23:54 +00008620
Douglas Gregor92e986e2010-04-22 16:44:27 +00008621 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008622 SmallVector<SourceLocation, 16> SelLocs;
8623 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008624 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008625 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008626 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008627 E->getMethodDecl(),
8628 E->getLeftLoc(),
8629 move_arg(Args),
8630 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008631}
8632
Mike Stump1eb44332009-09-09 15:08:12 +00008633template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008634ExprResult
John McCall454feb92009-12-08 09:21:05 +00008635TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008636 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008637}
8638
Mike Stump1eb44332009-09-09 15:08:12 +00008639template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008640ExprResult
John McCall454feb92009-12-08 09:21:05 +00008641TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008642 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008643}
8644
Mike Stump1eb44332009-09-09 15:08:12 +00008645template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008646ExprResult
John McCall454feb92009-12-08 09:21:05 +00008647TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008648 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008649 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008650 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008651 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008652
8653 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008654
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008655 // If nothing changed, just retain the existing expression.
8656 if (!getDerived().AlwaysRebuild() &&
8657 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008658 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008659
John McCall9ae2f072010-08-23 23:25:46 +00008660 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008661 E->getLocation(),
8662 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008663}
8664
Mike Stump1eb44332009-09-09 15:08:12 +00008665template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008666ExprResult
John McCall454feb92009-12-08 09:21:05 +00008667TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008668 // 'super' and types never change. Property never changes. Just
8669 // retain the existing expression.
8670 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008671 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00008672
Douglas Gregore3303542010-04-26 20:47:02 +00008673 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008674 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008675 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008676 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008677
Douglas Gregore3303542010-04-26 20:47:02 +00008678 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008679
Douglas Gregore3303542010-04-26 20:47:02 +00008680 // If nothing changed, just retain the existing expression.
8681 if (!getDerived().AlwaysRebuild() &&
8682 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008683 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008684
John McCall12f78a62010-12-02 01:19:52 +00008685 if (E->isExplicitProperty())
8686 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8687 E->getExplicitProperty(),
8688 E->getLocation());
8689
8690 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008691 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008692 E->getImplicitPropertyGetter(),
8693 E->getImplicitPropertySetter(),
8694 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008695}
8696
Mike Stump1eb44332009-09-09 15:08:12 +00008697template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008698ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008699TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8700 // Transform the base expression.
8701 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8702 if (Base.isInvalid())
8703 return ExprError();
8704
8705 // Transform the key expression.
8706 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8707 if (Key.isInvalid())
8708 return ExprError();
8709
8710 // If nothing changed, just retain the existing expression.
8711 if (!getDerived().AlwaysRebuild() &&
8712 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8713 return SemaRef.Owned(E);
8714
8715 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
8716 Base.get(), Key.get(),
8717 E->getAtIndexMethodDecl(),
8718 E->setAtIndexMethodDecl());
8719}
8720
8721template<typename Derived>
8722ExprResult
John McCall454feb92009-12-08 09:21:05 +00008723TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008724 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008725 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008726 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008727 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008728
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008729 // If nothing changed, just retain the existing expression.
8730 if (!getDerived().AlwaysRebuild() &&
8731 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008732 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008733
John McCall9ae2f072010-08-23 23:25:46 +00008734 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008735 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008736}
8737
Mike Stump1eb44332009-09-09 15:08:12 +00008738template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008739ExprResult
John McCall454feb92009-12-08 09:21:05 +00008740TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008741 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008742 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008743 SubExprs.reserve(E->getNumSubExprs());
8744 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8745 SubExprs, &ArgumentChanged))
8746 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008747
Douglas Gregorb98b1992009-08-11 05:31:07 +00008748 if (!getDerived().AlwaysRebuild() &&
8749 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008750 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008751
Douglas Gregorb98b1992009-08-11 05:31:07 +00008752 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8753 move_arg(SubExprs),
8754 E->getRParenLoc());
8755}
8756
Mike Stump1eb44332009-09-09 15:08:12 +00008757template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008758ExprResult
John McCall454feb92009-12-08 09:21:05 +00008759TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008760 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008761
John McCallc6ac9c32011-02-04 18:33:18 +00008762 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8763 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8764
8765 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008766 blockScope->TheDecl->setBlockMissingReturnType(
8767 oldBlock->blockMissingReturnType());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008768
Chris Lattner686775d2011-07-20 06:58:45 +00008769 SmallVector<ParmVarDecl*, 4> params;
8770 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008771
8772 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008773 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8774 oldBlock->param_begin(),
8775 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008776 0, paramTypes, &params)) {
8777 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008778 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008779 }
John McCallc6ac9c32011-02-04 18:33:18 +00008780
8781 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008782 QualType exprResultType =
8783 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008784
8785 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008786 if (exprResultType->isObjCObjectType()) {
John McCallc6ac9c32011-02-04 18:33:18 +00008787 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008788 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008789 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008790 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008791 return ExprError();
8792 }
John McCall711c52b2011-01-05 12:14:39 +00008793
John McCallc6ac9c32011-02-04 18:33:18 +00008794 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008795 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008796 paramTypes.data(),
8797 paramTypes.size(),
8798 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008799 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008800 exprFunctionType->getExtInfo());
8801 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008802
8803 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008804 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008805 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008806
8807 if (!oldBlock->blockMissingReturnType()) {
8808 blockScope->HasImplicitReturnType = false;
8809 blockScope->ReturnType = exprResultType;
8810 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008811
John McCall711c52b2011-01-05 12:14:39 +00008812 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008813 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008814 if (body.isInvalid()) {
8815 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008816 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008817 }
John McCall711c52b2011-01-05 12:14:39 +00008818
John McCallc6ac9c32011-02-04 18:33:18 +00008819#ifndef NDEBUG
8820 // In builds with assertions, make sure that we captured everything we
8821 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008822 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8823 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8824 e = oldBlock->capture_end(); i != e; ++i) {
8825 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008826
Douglas Gregorfc921372011-05-20 15:32:55 +00008827 // Ignore parameter packs.
8828 if (isa<ParmVarDecl>(oldCapture) &&
8829 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8830 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008831
Douglas Gregorfc921372011-05-20 15:32:55 +00008832 VarDecl *newCapture =
8833 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8834 oldCapture));
8835 assert(blockScope->CaptureMap.count(newCapture));
8836 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008837 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008838 }
8839#endif
8840
8841 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8842 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008843}
8844
Mike Stump1eb44332009-09-09 15:08:12 +00008845template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008846ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008847TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008848 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008849}
Eli Friedman276b0612011-10-11 02:20:01 +00008850
8851template<typename Derived>
8852ExprResult
8853TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008854 QualType RetTy = getDerived().TransformType(E->getType());
8855 bool ArgumentChanged = false;
8856 ASTOwningVector<Expr*> SubExprs(SemaRef);
8857 SubExprs.reserve(E->getNumSubExprs());
8858 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8859 SubExprs, &ArgumentChanged))
8860 return ExprError();
8861
8862 if (!getDerived().AlwaysRebuild() &&
8863 !ArgumentChanged)
8864 return SemaRef.Owned(E);
8865
8866 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8867 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008868}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008869
Douglas Gregorb98b1992009-08-11 05:31:07 +00008870//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008871// Type reconstruction
8872//===----------------------------------------------------------------------===//
8873
Mike Stump1eb44332009-09-09 15:08:12 +00008874template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008875QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8876 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008877 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008878 getDerived().getBaseEntity());
8879}
8880
Mike Stump1eb44332009-09-09 15:08:12 +00008881template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008882QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8883 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008884 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008885 getDerived().getBaseEntity());
8886}
8887
Mike Stump1eb44332009-09-09 15:08:12 +00008888template<typename Derived>
8889QualType
John McCall85737a72009-10-30 00:06:24 +00008890TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8891 bool WrittenAsLValue,
8892 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008893 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008894 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008895}
8896
8897template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008898QualType
John McCall85737a72009-10-30 00:06:24 +00008899TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8900 QualType ClassType,
8901 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008902 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008903 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008904}
8905
8906template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008907QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008908TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8909 ArrayType::ArraySizeModifier SizeMod,
8910 const llvm::APInt *Size,
8911 Expr *SizeExpr,
8912 unsigned IndexTypeQuals,
8913 SourceRange BracketsRange) {
8914 if (SizeExpr || !Size)
8915 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8916 IndexTypeQuals, BracketsRange,
8917 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008918
8919 QualType Types[] = {
8920 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8921 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8922 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008923 };
8924 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8925 QualType SizeType;
8926 for (unsigned I = 0; I != NumTypes; ++I)
8927 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8928 SizeType = Types[I];
8929 break;
8930 }
Mike Stump1eb44332009-09-09 15:08:12 +00008931
Eli Friedman01f276d2012-01-25 23:20:27 +00008932 // Note that we can return a VariableArrayType here in the case where
8933 // the element type was a dependent VariableArrayType.
8934 IntegerLiteral *ArraySize
8935 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8936 /*FIXME*/BracketsRange.getBegin());
8937 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008938 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008939 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008940}
Mike Stump1eb44332009-09-09 15:08:12 +00008941
Douglas Gregor577f75a2009-08-04 16:50:30 +00008942template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008943QualType
8944TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008945 ArrayType::ArraySizeModifier SizeMod,
8946 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008947 unsigned IndexTypeQuals,
8948 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008949 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008950 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008951}
8952
8953template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008954QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008955TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008956 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008957 unsigned IndexTypeQuals,
8958 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008959 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008960 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008961}
Mike Stump1eb44332009-09-09 15:08:12 +00008962
Douglas Gregor577f75a2009-08-04 16:50:30 +00008963template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008964QualType
8965TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008966 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008967 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008968 unsigned IndexTypeQuals,
8969 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008970 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008971 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008972 IndexTypeQuals, BracketsRange);
8973}
8974
8975template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008976QualType
8977TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008978 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008979 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008980 unsigned IndexTypeQuals,
8981 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008982 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008983 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008984 IndexTypeQuals, BracketsRange);
8985}
8986
8987template<typename Derived>
8988QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008989 unsigned NumElements,
8990 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008991 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008992 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008993}
Mike Stump1eb44332009-09-09 15:08:12 +00008994
Douglas Gregor577f75a2009-08-04 16:50:30 +00008995template<typename Derived>
8996QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8997 unsigned NumElements,
8998 SourceLocation AttributeLoc) {
8999 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9000 NumElements, true);
9001 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009002 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9003 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009004 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009005}
Mike Stump1eb44332009-09-09 15:08:12 +00009006
Douglas Gregor577f75a2009-08-04 16:50:30 +00009007template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009008QualType
9009TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009010 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009011 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009012 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009013}
Mike Stump1eb44332009-09-09 15:08:12 +00009014
Douglas Gregor577f75a2009-08-04 16:50:30 +00009015template<typename Derived>
9016QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00009017 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009018 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00009019 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009020 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00009021 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00009022 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00009023 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00009024 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009025 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009026 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009027 getDerived().getBaseEntity(),
9028 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009029}
Mike Stump1eb44332009-09-09 15:08:12 +00009030
Douglas Gregor577f75a2009-08-04 16:50:30 +00009031template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009032QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9033 return SemaRef.Context.getFunctionNoProtoType(T);
9034}
9035
9036template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009037QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9038 assert(D && "no decl found");
9039 if (D->isInvalidDecl()) return QualType();
9040
Douglas Gregor92e986e2010-04-22 16:44:27 +00009041 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009042 TypeDecl *Ty;
9043 if (isa<UsingDecl>(D)) {
9044 UsingDecl *Using = cast<UsingDecl>(D);
9045 assert(Using->isTypeName() &&
9046 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9047
9048 // A valid resolved using typename decl points to exactly one type decl.
9049 assert(++Using->shadow_begin() == Using->shadow_end());
9050 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00009051
John McCalled976492009-12-04 22:46:56 +00009052 } else {
9053 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9054 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9055 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9056 }
9057
9058 return SemaRef.Context.getTypeDeclType(Ty);
9059}
9060
9061template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009062QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9063 SourceLocation Loc) {
9064 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009065}
9066
9067template<typename Derived>
9068QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9069 return SemaRef.Context.getTypeOfType(Underlying);
9070}
9071
9072template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009073QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9074 SourceLocation Loc) {
9075 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009076}
9077
9078template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009079QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9080 UnaryTransformType::UTTKind UKind,
9081 SourceLocation Loc) {
9082 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9083}
9084
9085template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009086QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009087 TemplateName Template,
9088 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009089 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009090 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009091}
Mike Stump1eb44332009-09-09 15:08:12 +00009092
Douglas Gregordcee1a12009-08-06 05:28:30 +00009093template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009094QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9095 SourceLocation KWLoc) {
9096 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9097}
9098
9099template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009100TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009101TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009102 bool TemplateKW,
9103 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009104 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009105 Template);
9106}
9107
9108template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009109TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009110TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9111 const IdentifierInfo &Name,
9112 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009113 QualType ObjectType,
9114 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009115 UnqualifiedId TemplateName;
9116 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009117 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009118 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009119 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009120 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009121 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009122 /*EnteringContext=*/false,
9123 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009124 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009125}
Mike Stump1eb44332009-09-09 15:08:12 +00009126
Douglas Gregorb98b1992009-08-11 05:31:07 +00009127template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009128TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009129TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009130 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009131 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009132 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009133 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009134 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009135 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009136 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009137 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009138 Sema::TemplateTy Template;
9139 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009140 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009141 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009142 /*EnteringContext=*/false,
9143 Template);
9144 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009145}
Sean Huntc3021132010-05-05 15:23:54 +00009146
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009147template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009148ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009149TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9150 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009151 Expr *OrigCallee,
9152 Expr *First,
9153 Expr *Second) {
9154 Expr *Callee = OrigCallee->IgnoreParenCasts();
9155 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009156
Douglas Gregorb98b1992009-08-11 05:31:07 +00009157 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009158 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009159 if (!First->getType()->isOverloadableType() &&
9160 !Second->getType()->isOverloadableType())
9161 return getSema().CreateBuiltinArraySubscriptExpr(First,
9162 Callee->getLocStart(),
9163 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009164 } else if (Op == OO_Arrow) {
9165 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009166 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9167 } else if (Second == 0 || isPostIncDec) {
9168 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009169 // The argument is not of overloadable type, so try to create a
9170 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009171 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009172 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009173
John McCall9ae2f072010-08-23 23:25:46 +00009174 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009175 }
9176 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009177 if (!First->getType()->isOverloadableType() &&
9178 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009179 // Neither of the arguments is an overloadable type, so try to
9180 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009181 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009182 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009183 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009184 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009185 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009186
Douglas Gregorb98b1992009-08-11 05:31:07 +00009187 return move(Result);
9188 }
9189 }
Mike Stump1eb44332009-09-09 15:08:12 +00009190
9191 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009192 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009193 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009194
John McCall9ae2f072010-08-23 23:25:46 +00009195 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009196 assert(ULE->requiresADL());
9197
9198 // FIXME: Do we have to check
9199 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009200 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009201 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009202 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00009203 }
Mike Stump1eb44332009-09-09 15:08:12 +00009204
Douglas Gregorb98b1992009-08-11 05:31:07 +00009205 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009206 Expr *Args[2] = { First, Second };
9207 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009208
Douglas Gregorb98b1992009-08-11 05:31:07 +00009209 // Create the overloaded operator invocation for unary operators.
9210 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009211 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009212 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009213 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009214 }
Mike Stump1eb44332009-09-09 15:08:12 +00009215
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009216 if (Op == OO_Subscript) {
9217 SourceLocation LBrace;
9218 SourceLocation RBrace;
9219
9220 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9221 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9222 LBrace = SourceLocation::getFromRawEncoding(
9223 NameLoc.CXXOperatorName.BeginOpNameLoc);
9224 RBrace = SourceLocation::getFromRawEncoding(
9225 NameLoc.CXXOperatorName.EndOpNameLoc);
9226 } else {
9227 LBrace = Callee->getLocStart();
9228 RBrace = OpLoc;
9229 }
9230
9231 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9232 First, Second);
9233 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009234
Douglas Gregorb98b1992009-08-11 05:31:07 +00009235 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009236 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009237 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009238 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9239 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009240 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009241
Mike Stump1eb44332009-09-09 15:08:12 +00009242 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009243}
Mike Stump1eb44332009-09-09 15:08:12 +00009244
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009245template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009246ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009247TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009248 SourceLocation OperatorLoc,
9249 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009250 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009251 TypeSourceInfo *ScopeType,
9252 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009253 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009254 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009255 QualType BaseType = Base->getType();
9256 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009257 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00009258 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009259 !BaseType->getAs<PointerType>()->getPointeeType()
9260 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009261 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009262 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009263 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009264 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009265 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009266 /*FIXME?*/true);
9267 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009268
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009269 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009270 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9271 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9272 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9273 NameInfo.setNamedTypeInfo(DestroyedType);
9274
Richard Smith6314db92012-05-15 06:15:11 +00009275 // The scope type is now known to be a valid nested name specifier
9276 // component. Tack it on to the end of the nested name specifier.
9277 if (ScopeType)
9278 SS.Extend(SemaRef.Context, SourceLocation(),
9279 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009280
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009281 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009282 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009283 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009284 SS, TemplateKWLoc,
9285 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009286 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009287 /*TemplateArgs*/ 0);
9288}
9289
Douglas Gregor577f75a2009-08-04 16:50:30 +00009290} // end namespace clang
9291
9292#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H