blob: 71e520d9a9c1b319452db9cda0c4196c311c89eb [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;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000101
Douglas Gregord3731192011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000106
Douglas Gregord3731192011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier4a9d7952012-08-08 18:46:20 +0000111
Douglas Gregor577f75a2009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier4a9d7952012-08-08 18:46:20 +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;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000119
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();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000180
Douglas Gregorae201f72011-01-25 17:51:48 +0000181 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 }
Chad Rosier4a9d7952012-08-08 18:46:20 +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 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000224 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000225 /// 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 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000244 /// \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)
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000247 /// 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 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000257
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 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000266
Douglas Gregord3731192011-01-10 07:32:04 +0000267 /// \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) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000273
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) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000277
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 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000328 /// This routine transforms a list of expressions by invoking
329 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregoraa165f82011-01-03 19:04:46 +0000330 /// 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
Chad Rosier4a9d7952012-08-08 18:46:20 +0000339 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregoraa165f82011-01-03 19:04:46 +0000340 /// 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);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000352
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.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000359 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregordfca6f52012-02-13 22:00:16 +0000360 llvm::DenseMap<Decl *, Decl *>::iterator Known
361 = TransformedLocalDecls.find(D);
362 if (Known != TransformedLocalDecls.end())
363 return Known->second;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000364
365 return D;
Douglas Gregordfca6f52012-02-13 22:00:16 +0000366 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000367
Chad Rosier4a9d7952012-08-08 18:46:20 +0000368 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregordfca6f52012-02-13 22:00:16 +0000369 /// 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) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000374
Douglas Gregordfca6f52012-02-13 22:00:16 +0000375 /// \brief Note that a local declaration has been transformed by this
376 /// transformer.
377 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000378 /// Local declarations are typically transformed via a call to
Douglas Gregordfca6f52012-02-13 22:00:16 +0000379 /// 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 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000385
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.
Chad Rosier4a9d7952012-08-08 18:46:20 +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 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +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.
Chad Rosier4a9d7952012-08-08 18:46:20 +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 }
Chad Rosier4a9d7952012-08-08 18:46:20 +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 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000436 /// \param ObjectType If we're translating a template name within a member
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000437 /// 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 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000466 /// By default, this operation transforms all of the template arguments
Douglas Gregorfcc12532010-12-20 17:31:10 +0000467 /// 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 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000490 /// By default, this operation transforms all of the template arguments
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000491 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier4a9d7952012-08-08 18:46:20 +0000492 /// the transformed arguments to the output list.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000493 ///
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
Chad Rosier4a9d7952012-08-08 18:46:20 +0000530 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000531 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
532 TemplateSpecializationTypeLoc TL,
533 TemplateName Template);
534
Chad Rosier4a9d7952012-08-08 18:46:20 +0000535 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000536 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
Chad Rosier4a9d7952012-08-08 18:46:20 +0000541 QualType
Douglas Gregora88f09f2011-02-28 17:23:35 +0000542 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
Richard Smith612409e2012-07-25 03:56:55 +0000574 /// \brief Transform the captures and body of a lambda expression.
575 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
576
Richard Smith80ddc312012-10-19 06:32:17 +0000577 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
578 bool IsAddressOfOperand);
579
Douglas Gregor43959a92009-08-20 07:17:43 +0000580#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000581 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000582#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000583 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000584#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000585#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000586
Douglas Gregor577f75a2009-08-04 16:50:30 +0000587 /// \brief Build a new pointer type given its pointee type.
588 ///
589 /// By default, performs semantic analysis when building the pointer type.
590 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000591 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000592
593 /// \brief Build a new block pointer type given its pointee type.
594 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000595 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000596 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000597 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000598
John McCall85737a72009-10-30 00:06:24 +0000599 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000600 ///
John McCall85737a72009-10-30 00:06:24 +0000601 /// By default, performs semantic analysis when building the
602 /// reference type. Subclasses may override this routine to provide
603 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000604 ///
John McCall85737a72009-10-30 00:06:24 +0000605 /// \param LValue whether the type was written with an lvalue sigil
606 /// or an rvalue sigil.
607 QualType RebuildReferenceType(QualType ReferentType,
608 bool LValue,
609 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000610
Douglas Gregor577f75a2009-08-04 16:50:30 +0000611 /// \brief Build a new member pointer type given the pointee type and the
612 /// class type it refers into.
613 ///
614 /// By default, performs semantic analysis when building the member pointer
615 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000616 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
617 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000618
Douglas Gregor577f75a2009-08-04 16:50:30 +0000619 /// \brief Build a new array type given the element type, size
620 /// modifier, size of the array (if known), size expression, and index type
621 /// qualifiers.
622 ///
623 /// By default, performs semantic analysis when building the array type.
624 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000625 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000626 QualType RebuildArrayType(QualType ElementType,
627 ArrayType::ArraySizeModifier SizeMod,
628 const llvm::APInt *Size,
629 Expr *SizeExpr,
630 unsigned IndexTypeQuals,
631 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000632
Douglas Gregor577f75a2009-08-04 16:50:30 +0000633 /// \brief Build a new constant array type given the element type, size
634 /// modifier, (known) size of the array, and index type qualifiers.
635 ///
636 /// By default, performs semantic analysis when building the array type.
637 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000638 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000639 ArrayType::ArraySizeModifier SizeMod,
640 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000641 unsigned IndexTypeQuals,
642 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000643
Douglas Gregor577f75a2009-08-04 16:50:30 +0000644 /// \brief Build a new incomplete array type given the element type, size
645 /// modifier, and index type qualifiers.
646 ///
647 /// By default, performs semantic analysis when building the array type.
648 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000649 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000650 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000651 unsigned IndexTypeQuals,
652 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000653
Mike Stump1eb44332009-09-09 15:08:12 +0000654 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000655 /// size modifier, size expression, and index type qualifiers.
656 ///
657 /// By default, performs semantic analysis when building the array type.
658 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000659 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000660 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000661 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000662 unsigned IndexTypeQuals,
663 SourceRange BracketsRange);
664
Mike Stump1eb44332009-09-09 15:08:12 +0000665 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000666 /// size modifier, size expression, and index type qualifiers.
667 ///
668 /// By default, performs semantic analysis when building the array type.
669 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000670 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000671 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000672 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000673 unsigned IndexTypeQuals,
674 SourceRange BracketsRange);
675
676 /// \brief Build a new vector type given the element type and
677 /// number of elements.
678 ///
679 /// By default, performs semantic analysis when building the vector type.
680 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000681 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000682 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000683
Douglas Gregor577f75a2009-08-04 16:50:30 +0000684 /// \brief Build a new extended vector type given the element type and
685 /// number of elements.
686 ///
687 /// By default, performs semantic analysis when building the vector type.
688 /// Subclasses may override this routine to provide different behavior.
689 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
690 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000691
692 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000693 /// given the element type and number of elements.
694 ///
695 /// By default, performs semantic analysis when building the vector type.
696 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000697 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000698 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000699 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000700
Douglas Gregor577f75a2009-08-04 16:50:30 +0000701 /// \brief Build a new function type.
702 ///
703 /// By default, performs semantic analysis when building the function type.
704 /// Subclasses may override this routine to provide different behavior.
705 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000706 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000707 unsigned NumParamTypes,
Richard Smitheefb3d52012-02-10 09:58:53 +0000708 bool Variadic, bool HasTrailingReturn,
709 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000710 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000711 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000712
John McCalla2becad2009-10-21 00:40:46 +0000713 /// \brief Build a new unprototyped function type.
714 QualType RebuildFunctionNoProtoType(QualType ResultType);
715
John McCalled976492009-12-04 22:46:56 +0000716 /// \brief Rebuild an unresolved typename type, given the decl that
717 /// the UnresolvedUsingTypenameDecl was transformed to.
718 QualType RebuildUnresolvedUsingType(Decl *D);
719
Douglas Gregor577f75a2009-08-04 16:50:30 +0000720 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000721 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000722 return SemaRef.Context.getTypeDeclType(Typedef);
723 }
724
725 /// \brief Build a new class/struct/union type.
726 QualType RebuildRecordType(RecordDecl *Record) {
727 return SemaRef.Context.getTypeDeclType(Record);
728 }
729
730 /// \brief Build a new Enum type.
731 QualType RebuildEnumType(EnumDecl *Enum) {
732 return SemaRef.Context.getTypeDeclType(Enum);
733 }
John McCall7da24312009-09-05 00:15:47 +0000734
Mike Stump1eb44332009-09-09 15:08:12 +0000735 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000736 ///
737 /// By default, performs semantic analysis when building the typeof type.
738 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000739 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000740
Mike Stump1eb44332009-09-09 15:08:12 +0000741 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000742 ///
743 /// By default, builds a new TypeOfType with the given underlying type.
744 QualType RebuildTypeOfType(QualType Underlying);
745
Sean Huntca63c202011-05-24 22:41:36 +0000746 /// \brief Build a new unary transform type.
747 QualType RebuildUnaryTransformType(QualType BaseType,
748 UnaryTransformType::UTTKind UKind,
749 SourceLocation Loc);
750
Mike Stump1eb44332009-09-09 15:08:12 +0000751 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000752 ///
753 /// By default, performs semantic analysis when building the decltype type.
754 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000755 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000756
Richard Smith34b41d92011-02-20 03:19:35 +0000757 /// \brief Build a new C++0x auto type.
758 ///
759 /// By default, builds a new AutoType with the given deduced type.
760 QualType RebuildAutoType(QualType Deduced) {
761 return SemaRef.Context.getAutoType(Deduced);
762 }
763
Douglas Gregor577f75a2009-08-04 16:50:30 +0000764 /// \brief Build a new template specialization type.
765 ///
766 /// By default, performs semantic analysis when building the template
767 /// specialization type. Subclasses may override this routine to provide
768 /// different behavior.
769 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000770 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000771 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000772
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000773 /// \brief Build a new parenthesized type.
774 ///
775 /// By default, builds a new ParenType type from the inner type.
776 /// Subclasses may override this routine to provide different behavior.
777 QualType RebuildParenType(QualType InnerType) {
778 return SemaRef.Context.getParenType(InnerType);
779 }
780
Douglas Gregor577f75a2009-08-04 16:50:30 +0000781 /// \brief Build a new qualified name type.
782 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000783 /// By default, builds a new ElaboratedType type from the keyword,
784 /// the nested-name-specifier and the named type.
785 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000786 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
787 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000788 NestedNameSpecifierLoc QualifierLoc,
789 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000790 return SemaRef.Context.getElaboratedType(Keyword,
791 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000792 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000793 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000794
795 /// \brief Build a new typename type that refers to a template-id.
796 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000797 /// By default, builds a new DependentNameType type from the
798 /// nested-name-specifier and the given type. Subclasses may override
799 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000800 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000801 ElaboratedTypeKeyword Keyword,
802 NestedNameSpecifierLoc QualifierLoc,
803 const IdentifierInfo *Name,
804 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000805 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000806 // Rebuild the template name.
807 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000808 CXXScopeSpec SS;
809 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000810 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000811 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000812
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000813 if (InstName.isNull())
814 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000815
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000816 // If it's still dependent, make a dependent specialization.
817 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000818 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
819 QualifierLoc.getNestedNameSpecifier(),
820 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000821 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000822
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000823 // Otherwise, make an elaborated type wrapping a non-dependent
824 // specialization.
825 QualType T =
826 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
827 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000828
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000829 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
830 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000831
832 return SemaRef.Context.getElaboratedType(Keyword,
833 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000834 T);
835 }
836
Douglas Gregor577f75a2009-08-04 16:50:30 +0000837 /// \brief Build a new typename type that refers to an identifier.
838 ///
839 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000840 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000841 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000842 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000843 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000844 NestedNameSpecifierLoc QualifierLoc,
845 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000846 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000847 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000848 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000849
Douglas Gregor2494dd02011-03-01 01:34:45 +0000850 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000851 // If the name is still dependent, just build a new dependent name type.
852 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000853 return SemaRef.Context.getDependentNameType(Keyword,
854 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000855 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000856 }
857
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000858 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000859 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000860 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000861
862 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
863
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000864 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000865 // into a non-dependent elaborated-type-specifier. Find the tag we're
866 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000867 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000868 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
869 if (!DC)
870 return QualType();
871
John McCall56138762010-05-27 06:40:31 +0000872 if (SemaRef.RequireCompleteDeclContext(SS, DC))
873 return QualType();
874
Douglas Gregor40336422010-03-31 22:19:08 +0000875 TagDecl *Tag = 0;
876 SemaRef.LookupQualifiedName(Result, DC);
877 switch (Result.getResultKind()) {
878 case LookupResult::NotFound:
879 case LookupResult::NotFoundInCurrentInstantiation:
880 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000881
Douglas Gregor40336422010-03-31 22:19:08 +0000882 case LookupResult::Found:
883 Tag = Result.getAsSingle<TagDecl>();
884 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000885
Douglas Gregor40336422010-03-31 22:19:08 +0000886 case LookupResult::FoundOverloaded:
887 case LookupResult::FoundUnresolvedValue:
888 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000889
Douglas Gregor40336422010-03-31 22:19:08 +0000890 case LookupResult::Ambiguous:
891 // Let the LookupResult structure handle ambiguities.
892 return QualType();
893 }
894
895 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000896 // Check where the name exists but isn't a tag type and use that to emit
897 // better diagnostics.
898 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
899 SemaRef.LookupQualifiedName(Result, DC);
900 switch (Result.getResultKind()) {
901 case LookupResult::Found:
902 case LookupResult::FoundOverloaded:
903 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000904 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000905 unsigned Kind = 0;
906 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000907 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
908 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000909 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
910 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
911 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000912 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000913 default:
914 // FIXME: Would be nice to highlight just the source range.
915 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
916 << Kind << Id << DC;
917 break;
918 }
Douglas Gregor40336422010-03-31 22:19:08 +0000919 return QualType();
920 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000921
Richard Trieubbf34c02011-06-10 03:11:26 +0000922 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
923 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000924 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000925 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
926 return QualType();
927 }
928
929 // Build the elaborated-type-specifier type.
930 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000931 return SemaRef.Context.getElaboratedType(Keyword,
932 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000933 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000934 }
Mike Stump1eb44332009-09-09 15:08:12 +0000935
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000936 /// \brief Build a new pack expansion type.
937 ///
938 /// By default, builds a new PackExpansionType type from the given pattern.
939 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000940 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000941 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000942 SourceLocation EllipsisLoc,
943 llvm::Optional<unsigned> NumExpansions) {
944 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
945 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000946 }
947
Eli Friedmanb001de72011-10-06 23:00:33 +0000948 /// \brief Build a new atomic type given its value type.
949 ///
950 /// By default, performs semantic analysis when building the atomic type.
951 /// Subclasses may override this routine to provide different behavior.
952 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
953
Douglas Gregord1067e52009-08-06 06:41:21 +0000954 /// \brief Build a new template name given a nested name specifier, a flag
955 /// indicating whether the "template" keyword was provided, and the template
956 /// that the template name refers to.
957 ///
958 /// By default, builds the new template name directly. Subclasses may override
959 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000960 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000961 bool TemplateKW,
962 TemplateDecl *Template);
963
Douglas Gregord1067e52009-08-06 06:41:21 +0000964 /// \brief Build a new template name given a nested name specifier and the
965 /// name that is referred to as a template.
966 ///
967 /// By default, performs semantic analysis to determine whether the name can
968 /// be resolved to a specific template, then builds the appropriate kind of
969 /// template name. Subclasses may override this routine to provide different
970 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000971 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
972 const IdentifierInfo &Name,
973 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000974 QualType ObjectType,
975 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000976
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000977 /// \brief Build a new template name given a nested name specifier and the
978 /// overloaded operator name that is referred to as a template.
979 ///
980 /// By default, performs semantic analysis to determine whether the name can
981 /// be resolved to a specific template, then builds the appropriate kind of
982 /// template name. Subclasses may override this routine to provide different
983 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000984 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000985 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000986 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000987 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000988
989 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +0000990 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000991 ///
992 /// By default, performs semantic analysis to determine whether the name can
993 /// be resolved to a specific template, then builds the appropriate kind of
994 /// template name. Subclasses may override this routine to provide different
995 /// behavior.
996 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
997 const TemplateArgument &ArgPack) {
998 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
999 }
1000
Douglas Gregor43959a92009-08-20 07:17:43 +00001001 /// \brief Build a new compound statement.
1002 ///
1003 /// By default, performs semantic analysis to build the new statement.
1004 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001005 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001006 MultiStmtArg Statements,
1007 SourceLocation RBraceLoc,
1008 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001009 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001010 IsStmtExpr);
1011 }
1012
1013 /// \brief Build a new case statement.
1014 ///
1015 /// By default, performs semantic analysis to build the new statement.
1016 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001017 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001018 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001019 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001020 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001021 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001022 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001023 ColonLoc);
1024 }
Mike Stump1eb44332009-09-09 15:08:12 +00001025
Douglas Gregor43959a92009-08-20 07:17:43 +00001026 /// \brief Attach the body to a new case statement.
1027 ///
1028 /// By default, performs semantic analysis to build the new statement.
1029 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001030 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001031 getSema().ActOnCaseStmtBody(S, Body);
1032 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001033 }
Mike Stump1eb44332009-09-09 15:08:12 +00001034
Douglas Gregor43959a92009-08-20 07:17:43 +00001035 /// \brief Build a new default statement.
1036 ///
1037 /// By default, performs semantic analysis to build the new statement.
1038 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001039 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001040 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001041 Stmt *SubStmt) {
1042 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001043 /*CurScope=*/0);
1044 }
Mike Stump1eb44332009-09-09 15:08:12 +00001045
Douglas Gregor43959a92009-08-20 07:17:43 +00001046 /// \brief Build a new label statement.
1047 ///
1048 /// By default, performs semantic analysis to build the new statement.
1049 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001050 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1051 SourceLocation ColonLoc, Stmt *SubStmt) {
1052 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001053 }
Mike Stump1eb44332009-09-09 15:08:12 +00001054
Richard Smith534986f2012-04-14 00:33:13 +00001055 /// \brief Build a new label statement.
1056 ///
1057 /// By default, performs semantic analysis to build the new statement.
1058 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001059 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1060 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001061 Stmt *SubStmt) {
1062 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1063 }
1064
Douglas Gregor43959a92009-08-20 07:17:43 +00001065 /// \brief Build a new "if" statement.
1066 ///
1067 /// By default, performs semantic analysis to build the new statement.
1068 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001069 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001070 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001071 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001072 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001073 }
Mike Stump1eb44332009-09-09 15:08:12 +00001074
Douglas Gregor43959a92009-08-20 07:17:43 +00001075 /// \brief Start building a new switch statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001079 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001080 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001081 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001082 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001083 }
Mike Stump1eb44332009-09-09 15:08:12 +00001084
Douglas Gregor43959a92009-08-20 07:17:43 +00001085 /// \brief Attach the body to the switch statement.
1086 ///
1087 /// By default, performs semantic analysis to build the new statement.
1088 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001089 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001090 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001091 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001092 }
1093
1094 /// \brief Build a new while statement.
1095 ///
1096 /// By default, performs semantic analysis to build the new statement.
1097 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001098 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1099 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001100 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001101 }
Mike Stump1eb44332009-09-09 15:08:12 +00001102
Douglas Gregor43959a92009-08-20 07:17:43 +00001103 /// \brief Build a new do-while statement.
1104 ///
1105 /// By default, performs semantic analysis to build the new statement.
1106 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001107 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001108 SourceLocation WhileLoc, SourceLocation LParenLoc,
1109 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001110 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1111 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001112 }
1113
1114 /// \brief Build a new for statement.
1115 ///
1116 /// By default, performs semantic analysis to build the new statement.
1117 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001118 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001119 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001120 VarDecl *CondVar, Sema::FullExprArg Inc,
1121 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001122 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001123 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001124 }
Mike Stump1eb44332009-09-09 15:08:12 +00001125
Douglas Gregor43959a92009-08-20 07:17:43 +00001126 /// \brief Build a new goto statement.
1127 ///
1128 /// By default, performs semantic analysis to build the new statement.
1129 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001130 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1131 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001132 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001133 }
1134
1135 /// \brief Build a new indirect goto statement.
1136 ///
1137 /// By default, performs semantic analysis to build the new statement.
1138 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001139 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001140 SourceLocation StarLoc,
1141 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001142 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001143 }
Mike Stump1eb44332009-09-09 15:08:12 +00001144
Douglas Gregor43959a92009-08-20 07:17:43 +00001145 /// \brief Build a new return statement.
1146 ///
1147 /// By default, performs semantic analysis to build the new statement.
1148 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001149 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001150 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001151 }
Mike Stump1eb44332009-09-09 15:08:12 +00001152
Douglas Gregor43959a92009-08-20 07:17:43 +00001153 /// \brief Build a new declaration statement.
1154 ///
1155 /// By default, performs semantic analysis to build the new statement.
1156 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001157 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001158 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001159 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001160 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1161 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001162 }
Mike Stump1eb44332009-09-09 15:08:12 +00001163
Anders Carlsson703e3942010-01-24 05:50:09 +00001164 /// \brief Build a new inline asm statement.
1165 ///
1166 /// By default, performs semantic analysis to build the new statement.
1167 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001168 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1169 bool IsVolatile, unsigned NumOutputs,
1170 unsigned NumInputs, IdentifierInfo **Names,
1171 MultiExprArg Constraints, MultiExprArg Exprs,
1172 Expr *AsmString, MultiExprArg Clobbers,
1173 SourceLocation RParenLoc) {
1174 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1175 NumInputs, Names, Constraints, Exprs,
1176 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001177 }
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.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001183 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
1184 ArrayRef<Token> AsmToks, SourceLocation EndLoc) {
Chad Rosier7bd092b2012-08-15 16:53:30 +00001185 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001186 }
1187
James Dennett699c9042012-06-15 07:13:21 +00001188 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001189 ///
1190 /// By default, performs semantic analysis to build the new statement.
1191 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001192 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001193 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001194 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001195 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001196 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001197 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001198 }
1199
Douglas Gregorbe270a02010-04-26 17:57:08 +00001200 /// \brief Rebuild an Objective-C exception declaration.
1201 ///
1202 /// By default, performs semantic analysis to build the new declaration.
1203 /// Subclasses may override this routine to provide different behavior.
1204 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1205 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001206 return getSema().BuildObjCExceptionDecl(TInfo, T,
1207 ExceptionDecl->getInnerLocStart(),
1208 ExceptionDecl->getLocation(),
1209 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001210 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001211
James Dennett699c9042012-06-15 07:13:21 +00001212 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001213 ///
1214 /// By default, performs semantic analysis to build the new statement.
1215 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001216 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001217 SourceLocation RParenLoc,
1218 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001219 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001220 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001221 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001222 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001223
James Dennett699c9042012-06-15 07:13:21 +00001224 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001225 ///
1226 /// By default, performs semantic analysis to build the new statement.
1227 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001228 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001229 Stmt *Body) {
1230 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001231 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001232
James Dennett699c9042012-06-15 07:13:21 +00001233 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001234 ///
1235 /// By default, performs semantic analysis to build the new statement.
1236 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001237 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001238 Expr *Operand) {
1239 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001240 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001241
James Dennett699c9042012-06-15 07:13:21 +00001242 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001243 ///
1244 /// By default, performs semantic analysis to build the new statement.
1245 /// Subclasses may override this routine to provide different behavior.
1246 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1247 Expr *object) {
1248 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1249 }
1250
James Dennett699c9042012-06-15 07:13:21 +00001251 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001252 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001253 /// By default, performs semantic analysis to build the new statement.
1254 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001255 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001256 Expr *Object, Stmt *Body) {
1257 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001258 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001259
James Dennett699c9042012-06-15 07:13:21 +00001260 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001261 ///
1262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
1264 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1265 Stmt *Body) {
1266 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1267 }
John McCall990567c2011-07-27 01:07:15 +00001268
Douglas Gregorc3203e72010-04-22 23:10:45 +00001269 /// \brief Build a new Objective-C fast enumeration statement.
1270 ///
1271 /// By default, performs semantic analysis to build the new statement.
1272 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001273 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001274 Stmt *Element,
1275 Expr *Collection,
1276 SourceLocation RParenLoc,
1277 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001278 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001279 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001280 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001281 RParenLoc);
1282 if (ForEachStmt.isInvalid())
1283 return StmtError();
1284
1285 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001286 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001287
Douglas Gregor43959a92009-08-20 07:17:43 +00001288 /// \brief Build a new C++ exception declaration.
1289 ///
1290 /// By default, performs semantic analysis to build the new decaration.
1291 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001292 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001293 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001294 SourceLocation StartLoc,
1295 SourceLocation IdLoc,
1296 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001297 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1298 StartLoc, IdLoc, Id);
1299 if (Var)
1300 getSema().CurContext->addDecl(Var);
1301 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001302 }
1303
1304 /// \brief Build a new C++ catch statement.
1305 ///
1306 /// By default, performs semantic analysis to build the new statement.
1307 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001308 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001309 VarDecl *ExceptionDecl,
1310 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001311 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1312 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001313 }
Mike Stump1eb44332009-09-09 15:08:12 +00001314
Douglas Gregor43959a92009-08-20 07:17:43 +00001315 /// \brief Build a new C++ try statement.
1316 ///
1317 /// By default, performs semantic analysis to build the new statement.
1318 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001319 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001320 Stmt *TryBlock,
1321 MultiStmtArg Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001322 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001323 }
Mike Stump1eb44332009-09-09 15:08:12 +00001324
Richard Smithad762fc2011-04-14 22:09:26 +00001325 /// \brief Build a new C++0x range-based for statement.
1326 ///
1327 /// By default, performs semantic analysis to build the new statement.
1328 /// Subclasses may override this routine to provide different behavior.
1329 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1330 SourceLocation ColonLoc,
1331 Stmt *Range, Stmt *BeginEnd,
1332 Expr *Cond, Expr *Inc,
1333 Stmt *LoopVar,
1334 SourceLocation RParenLoc) {
1335 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001336 Cond, Inc, LoopVar, RParenLoc,
1337 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001338 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001339
1340 /// \brief Build a new C++0x range-based for statement.
1341 ///
1342 /// By default, performs semantic analysis to build the new statement.
1343 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001344 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001345 bool IsIfExists,
1346 NestedNameSpecifierLoc QualifierLoc,
1347 DeclarationNameInfo NameInfo,
1348 Stmt *Nested) {
1349 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1350 QualifierLoc, NameInfo, Nested);
1351 }
1352
Richard Smithad762fc2011-04-14 22:09:26 +00001353 /// \brief Attach body to a C++0x range-based for statement.
1354 ///
1355 /// By default, performs semantic analysis to finish the new statement.
1356 /// Subclasses may override this routine to provide different behavior.
1357 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1358 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1359 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001360
John Wiegley28bbe4b2011-04-28 01:08:34 +00001361 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1362 SourceLocation TryLoc,
1363 Stmt *TryBlock,
1364 Stmt *Handler) {
1365 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1366 }
1367
1368 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1369 Expr *FilterExpr,
1370 Stmt *Block) {
1371 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1372 }
1373
1374 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1375 Stmt *Block) {
1376 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1377 }
1378
Douglas Gregorb98b1992009-08-11 05:31:07 +00001379 /// \brief Build a new expression that references a declaration.
1380 ///
1381 /// By default, performs semantic analysis to build the new expression.
1382 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001383 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001384 LookupResult &R,
1385 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001386 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1387 }
1388
1389
1390 /// \brief Build a new expression that references a declaration.
1391 ///
1392 /// By default, performs semantic analysis to build the new expression.
1393 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001394 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001395 ValueDecl *VD,
1396 const DeclarationNameInfo &NameInfo,
1397 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001398 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001399 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001400
1401 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001402
1403 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001404 }
Mike Stump1eb44332009-09-09 15:08:12 +00001405
Douglas Gregorb98b1992009-08-11 05:31:07 +00001406 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001407 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001408 /// By default, performs semantic analysis to build the new expression.
1409 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001410 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001411 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001412 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001413 }
1414
Douglas Gregora71d8192009-09-04 17:36:40 +00001415 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001416 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001417 /// By default, performs semantic analysis to build the new expression.
1418 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001419 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001420 SourceLocation OperatorLoc,
1421 bool isArrow,
1422 CXXScopeSpec &SS,
1423 TypeSourceInfo *ScopeType,
1424 SourceLocation CCLoc,
1425 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001426 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001427
Douglas Gregorb98b1992009-08-11 05:31:07 +00001428 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001429 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001430 /// By default, performs semantic analysis to build the new expression.
1431 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001432 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001433 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001434 Expr *SubExpr) {
1435 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001436 }
Mike Stump1eb44332009-09-09 15:08:12 +00001437
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001438 /// \brief Build a new builtin offsetof expression.
1439 ///
1440 /// By default, performs semantic analysis to build the new expression.
1441 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001442 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001443 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001444 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001445 unsigned NumComponents,
1446 SourceLocation RParenLoc) {
1447 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1448 NumComponents, RParenLoc);
1449 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001450
1451 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001452 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001453 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001454 /// By default, performs semantic analysis to build the new expression.
1455 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001456 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1457 SourceLocation OpLoc,
1458 UnaryExprOrTypeTrait ExprKind,
1459 SourceRange R) {
1460 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001461 }
1462
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001463 /// \brief Build a new sizeof, alignof or vec step expression with an
1464 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001465 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001466 /// By default, performs semantic analysis to build the new expression.
1467 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001468 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1469 UnaryExprOrTypeTrait ExprKind,
1470 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001471 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001472 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001473 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001474 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001475
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001476 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001477 }
Mike Stump1eb44332009-09-09 15:08:12 +00001478
Douglas Gregorb98b1992009-08-11 05:31:07 +00001479 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001480 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001481 /// By default, performs semantic analysis to build the new expression.
1482 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001483 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001484 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001485 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001486 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001487 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1488 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001489 RBracketLoc);
1490 }
1491
1492 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001493 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001494 /// By default, performs semantic analysis to build the new expression.
1495 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001496 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001497 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001498 SourceLocation RParenLoc,
1499 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001500 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001501 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001502 }
1503
1504 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001505 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001506 /// By default, performs semantic analysis to build the new expression.
1507 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001508 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001509 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001510 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001511 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001512 const DeclarationNameInfo &MemberNameInfo,
1513 ValueDecl *Member,
1514 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001515 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001516 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001517 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1518 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001519 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001520 // We have a reference to an unnamed field. This is always the
1521 // base of an anonymous struct/union member access, i.e. the
1522 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001523 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001524 assert(Member->getType()->isRecordType() &&
1525 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001526
Richard Smith9138b4e2011-10-26 19:06:56 +00001527 BaseResult =
1528 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001529 QualifierLoc.getNestedNameSpecifier(),
1530 FoundDecl, Member);
1531 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001532 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001533 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001534 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001535 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001536 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001537 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001538 cast<FieldDecl>(Member)->getType(),
1539 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001540 return getSema().Owned(ME);
1541 }
Mike Stump1eb44332009-09-09 15:08:12 +00001542
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001543 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001544 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001545
John Wiegley429bb272011-04-08 18:41:53 +00001546 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001547 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001548
John McCall6bb80172010-03-30 21:47:33 +00001549 // FIXME: this involves duplicating earlier analysis in a lot of
1550 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001551 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001552 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001553 R.resolveKind();
1554
John McCall9ae2f072010-08-23 23:25:46 +00001555 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001556 SS, TemplateKWLoc,
1557 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001558 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001559 }
Mike Stump1eb44332009-09-09 15:08:12 +00001560
Douglas Gregorb98b1992009-08-11 05:31:07 +00001561 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001562 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001563 /// By default, performs semantic analysis to build the new expression.
1564 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001565 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001566 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001567 Expr *LHS, Expr *RHS) {
1568 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 }
1570
1571 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001572 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001573 /// By default, performs semantic analysis to build the new expression.
1574 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001575 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001576 SourceLocation QuestionLoc,
1577 Expr *LHS,
1578 SourceLocation ColonLoc,
1579 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001580 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1581 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 }
1583
Douglas Gregorb98b1992009-08-11 05:31:07 +00001584 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001585 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 /// By default, performs semantic analysis to build the new expression.
1587 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001588 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001589 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001591 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001592 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001593 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 }
Mike Stump1eb44332009-09-09 15:08:12 +00001595
Douglas Gregorb98b1992009-08-11 05:31:07 +00001596 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001597 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001598 /// By default, performs semantic analysis to build the new expression.
1599 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001600 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001601 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001603 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001604 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001605 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001606 }
Mike Stump1eb44332009-09-09 15:08:12 +00001607
Douglas Gregorb98b1992009-08-11 05:31:07 +00001608 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001609 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001610 /// By default, performs semantic analysis to build the new expression.
1611 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001612 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001613 SourceLocation OpLoc,
1614 SourceLocation AccessorLoc,
1615 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001616
John McCall129e2df2009-11-30 22:42:35 +00001617 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001618 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001619 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001620 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001621 SS, SourceLocation(),
1622 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001623 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001624 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001625 }
Mike Stump1eb44332009-09-09 15:08:12 +00001626
Douglas Gregorb98b1992009-08-11 05:31:07 +00001627 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001628 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001629 /// By default, performs semantic analysis to build the new expression.
1630 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001631 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001632 MultiExprArg Inits,
1633 SourceLocation RBraceLoc,
1634 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001635 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001636 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001637 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001638 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001639
Douglas Gregore48319a2009-11-09 17:16:50 +00001640 // Patch in the result type we were given, which may have been computed
1641 // when the initial InitListExpr was built.
1642 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1643 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001644 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001645 }
Mike Stump1eb44332009-09-09 15:08:12 +00001646
Douglas Gregorb98b1992009-08-11 05:31:07 +00001647 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001648 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001649 /// By default, performs semantic analysis to build the new expression.
1650 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001651 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001652 MultiExprArg ArrayExprs,
1653 SourceLocation EqualOrColonLoc,
1654 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001655 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001656 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001657 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001658 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001660 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001661
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001662 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 }
Mike Stump1eb44332009-09-09 15:08:12 +00001664
Douglas Gregorb98b1992009-08-11 05:31:07 +00001665 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001666 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 /// By default, builds the implicit value initialization without performing
1668 /// any semantic analysis. Subclasses may override this routine to provide
1669 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001670 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1672 }
Mike Stump1eb44332009-09-09 15:08:12 +00001673
Douglas Gregorb98b1992009-08-11 05:31:07 +00001674 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001675 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001676 /// By default, performs semantic analysis to build the new expression.
1677 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001678 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001679 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001680 SourceLocation RParenLoc) {
1681 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001682 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001683 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001684 }
1685
1686 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001687 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001688 /// By default, performs semantic analysis to build the new expression.
1689 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001690 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001691 MultiExprArg SubExprs,
1692 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001693 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001694 }
Mike Stump1eb44332009-09-09 15:08:12 +00001695
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001697 ///
1698 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001699 /// rather than attempting to map the label statement itself.
1700 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001701 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001702 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001703 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 }
Mike Stump1eb44332009-09-09 15:08:12 +00001705
Douglas Gregorb98b1992009-08-11 05:31:07 +00001706 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001707 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 /// By default, performs semantic analysis to build the new expression.
1709 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001710 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001711 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001713 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001714 }
Mike Stump1eb44332009-09-09 15:08:12 +00001715
Douglas Gregorb98b1992009-08-11 05:31:07 +00001716 /// \brief Build a new __builtin_choose_expr expression.
1717 ///
1718 /// By default, performs semantic analysis to build the new expression.
1719 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001720 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001721 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 SourceLocation RParenLoc) {
1723 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001724 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001725 RParenLoc);
1726 }
Mike Stump1eb44332009-09-09 15:08:12 +00001727
Peter Collingbournef111d932011-04-15 00:35:48 +00001728 /// \brief Build a new generic selection expression.
1729 ///
1730 /// By default, performs semantic analysis to build the new expression.
1731 /// Subclasses may override this routine to provide different behavior.
1732 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1733 SourceLocation DefaultLoc,
1734 SourceLocation RParenLoc,
1735 Expr *ControllingExpr,
1736 TypeSourceInfo **Types,
1737 Expr **Exprs,
1738 unsigned NumAssocs) {
1739 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1740 ControllingExpr, Types, Exprs,
1741 NumAssocs);
1742 }
1743
Douglas Gregorb98b1992009-08-11 05:31:07 +00001744 /// \brief Build a new overloaded operator call expression.
1745 ///
1746 /// By default, performs semantic analysis to build the new expression.
1747 /// The semantic analysis provides the behavior of template instantiation,
1748 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001749 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001750 /// argument-dependent lookup, etc. Subclasses may override this routine to
1751 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001752 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001753 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001754 Expr *Callee,
1755 Expr *First,
1756 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001757
1758 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 /// reinterpret_cast.
1760 ///
1761 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001762 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001763 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001764 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765 Stmt::StmtClass Class,
1766 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001767 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001768 SourceLocation RAngleLoc,
1769 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001770 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001771 SourceLocation RParenLoc) {
1772 switch (Class) {
1773 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001774 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001775 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001776 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001777
1778 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001779 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001780 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001781 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001782
Douglas Gregorb98b1992009-08-11 05:31:07 +00001783 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001784 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001785 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001786 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001788
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001790 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001791 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001792 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001793
Douglas Gregorb98b1992009-08-11 05:31:07 +00001794 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001795 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001796 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 }
Mike Stump1eb44332009-09-09 15:08:12 +00001798
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 /// \brief Build a new C++ static_cast expression.
1800 ///
1801 /// By default, performs semantic analysis to build the new expression.
1802 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001803 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001804 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001805 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 SourceLocation RAngleLoc,
1807 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001808 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001810 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001811 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001812 SourceRange(LAngleLoc, RAngleLoc),
1813 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001814 }
1815
1816 /// \brief Build a new C++ dynamic_cast expression.
1817 ///
1818 /// By default, performs semantic analysis to build the new expression.
1819 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001820 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001821 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001822 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001823 SourceLocation RAngleLoc,
1824 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001825 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001826 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001827 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001828 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001829 SourceRange(LAngleLoc, RAngleLoc),
1830 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001831 }
1832
1833 /// \brief Build a new C++ reinterpret_cast expression.
1834 ///
1835 /// By default, performs semantic analysis to build the new expression.
1836 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001837 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001838 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001839 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001840 SourceLocation RAngleLoc,
1841 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001842 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001843 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001844 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001845 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001846 SourceRange(LAngleLoc, RAngleLoc),
1847 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001848 }
1849
1850 /// \brief Build a new C++ const_cast expression.
1851 ///
1852 /// By default, performs semantic analysis to build the new expression.
1853 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001854 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001855 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001856 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001857 SourceLocation RAngleLoc,
1858 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001859 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001860 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001861 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001862 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001863 SourceRange(LAngleLoc, RAngleLoc),
1864 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001865 }
Mike Stump1eb44332009-09-09 15:08:12 +00001866
Douglas Gregorb98b1992009-08-11 05:31:07 +00001867 /// \brief Build a new C++ functional-style cast expression.
1868 ///
1869 /// By default, performs semantic analysis to build the new expression.
1870 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001871 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1872 SourceLocation LParenLoc,
1873 Expr *Sub,
1874 SourceLocation RParenLoc) {
1875 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001876 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001877 RParenLoc);
1878 }
Mike Stump1eb44332009-09-09 15:08:12 +00001879
Douglas Gregorb98b1992009-08-11 05:31:07 +00001880 /// \brief Build a new C++ typeid(type) expression.
1881 ///
1882 /// By default, performs semantic analysis to build the new expression.
1883 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001884 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001885 SourceLocation TypeidLoc,
1886 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001887 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001888 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001889 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001890 }
Mike Stump1eb44332009-09-09 15:08:12 +00001891
Francois Pichet01b7c302010-09-08 12:20:18 +00001892
Douglas Gregorb98b1992009-08-11 05:31:07 +00001893 /// \brief Build a new C++ typeid(expr) expression.
1894 ///
1895 /// By default, performs semantic analysis to build the new expression.
1896 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001897 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001898 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001899 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001900 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001901 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001902 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001903 }
1904
Francois Pichet01b7c302010-09-08 12:20:18 +00001905 /// \brief Build a new C++ __uuidof(type) expression.
1906 ///
1907 /// By default, performs semantic analysis to build the new expression.
1908 /// Subclasses may override this routine to provide different behavior.
1909 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1910 SourceLocation TypeidLoc,
1911 TypeSourceInfo *Operand,
1912 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001913 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001914 RParenLoc);
1915 }
1916
1917 /// \brief Build a new C++ __uuidof(expr) expression.
1918 ///
1919 /// By default, performs semantic analysis to build the new expression.
1920 /// Subclasses may override this routine to provide different behavior.
1921 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1922 SourceLocation TypeidLoc,
1923 Expr *Operand,
1924 SourceLocation RParenLoc) {
1925 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1926 RParenLoc);
1927 }
1928
Douglas Gregorb98b1992009-08-11 05:31:07 +00001929 /// \brief Build a new C++ "this" expression.
1930 ///
1931 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001932 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001933 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001934 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001935 QualType ThisType,
1936 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001937 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001938 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001939 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1940 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001941 }
1942
1943 /// \brief Build a new C++ throw expression.
1944 ///
1945 /// By default, performs semantic analysis to build the new expression.
1946 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001947 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1948 bool IsThrownVariableInScope) {
1949 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001950 }
1951
1952 /// \brief Build a new C++ default-argument expression.
1953 ///
1954 /// By default, builds a new default-argument expression, which does not
1955 /// require any semantic analysis. Subclasses may override this routine to
1956 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001957 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001958 ParmVarDecl *Param) {
1959 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1960 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001961 }
1962
1963 /// \brief Build a new C++ zero-initialization expression.
1964 ///
1965 /// By default, performs semantic analysis to build the new expression.
1966 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001967 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1968 SourceLocation LParenLoc,
1969 SourceLocation RParenLoc) {
1970 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Benjamin Kramer5354e772012-08-23 23:38:35 +00001971 MultiExprArg(), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001972 }
Mike Stump1eb44332009-09-09 15:08:12 +00001973
Douglas Gregorb98b1992009-08-11 05:31:07 +00001974 /// \brief Build a new C++ "new" expression.
1975 ///
1976 /// By default, performs semantic analysis to build the new expression.
1977 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001978 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001979 bool UseGlobal,
1980 SourceLocation PlacementLParen,
1981 MultiExprArg PlacementArgs,
1982 SourceLocation PlacementRParen,
1983 SourceRange TypeIdParens,
1984 QualType AllocatedType,
1985 TypeSourceInfo *AllocatedTypeInfo,
1986 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001987 SourceRange DirectInitRange,
1988 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001989 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001990 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001991 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001992 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001993 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001994 AllocatedType,
1995 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001996 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001997 DirectInitRange,
1998 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001999 }
Mike Stump1eb44332009-09-09 15:08:12 +00002000
Douglas Gregorb98b1992009-08-11 05:31:07 +00002001 /// \brief Build a new C++ "delete" expression.
2002 ///
2003 /// By default, performs semantic analysis to build the new expression.
2004 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002005 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002006 bool IsGlobalDelete,
2007 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002008 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002009 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002010 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002011 }
Mike Stump1eb44332009-09-09 15:08:12 +00002012
Douglas Gregorb98b1992009-08-11 05:31:07 +00002013 /// \brief Build a new unary type trait expression.
2014 ///
2015 /// By default, performs semantic analysis to build the new expression.
2016 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002017 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002018 SourceLocation StartLoc,
2019 TypeSourceInfo *T,
2020 SourceLocation RParenLoc) {
2021 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002022 }
2023
Francois Pichet6ad6f282010-12-07 00:08:36 +00002024 /// \brief Build a new binary type trait expression.
2025 ///
2026 /// By default, performs semantic analysis to build the new expression.
2027 /// Subclasses may override this routine to provide different behavior.
2028 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2029 SourceLocation StartLoc,
2030 TypeSourceInfo *LhsT,
2031 TypeSourceInfo *RhsT,
2032 SourceLocation RParenLoc) {
2033 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2034 }
2035
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002036 /// \brief Build a new type trait expression.
2037 ///
2038 /// By default, performs semantic analysis to build the new expression.
2039 /// Subclasses may override this routine to provide different behavior.
2040 ExprResult RebuildTypeTrait(TypeTrait Trait,
2041 SourceLocation StartLoc,
2042 ArrayRef<TypeSourceInfo *> Args,
2043 SourceLocation RParenLoc) {
2044 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2045 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002046
John Wiegley21ff2e52011-04-28 00:16:57 +00002047 /// \brief Build a new array type trait expression.
2048 ///
2049 /// By default, performs semantic analysis to build the new expression.
2050 /// Subclasses may override this routine to provide different behavior.
2051 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2052 SourceLocation StartLoc,
2053 TypeSourceInfo *TSInfo,
2054 Expr *DimExpr,
2055 SourceLocation RParenLoc) {
2056 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2057 }
2058
John Wiegley55262202011-04-25 06:54:41 +00002059 /// \brief Build a new expression trait expression.
2060 ///
2061 /// By default, performs semantic analysis to build the new expression.
2062 /// Subclasses may override this routine to provide different behavior.
2063 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2064 SourceLocation StartLoc,
2065 Expr *Queried,
2066 SourceLocation RParenLoc) {
2067 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2068 }
2069
Mike Stump1eb44332009-09-09 15:08:12 +00002070 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002071 /// expression.
2072 ///
2073 /// By default, performs semantic analysis to build the new expression.
2074 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002075 ExprResult RebuildDependentScopeDeclRefExpr(
2076 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002077 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002078 const DeclarationNameInfo &NameInfo,
Richard Smith80ddc312012-10-19 06:32:17 +00002079 const TemplateArgumentListInfo *TemplateArgs,
2080 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002081 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002082 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002083
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002084 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002085 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002086 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002087
Richard Smith80ddc312012-10-19 06:32:17 +00002088 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2089 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002090 }
2091
2092 /// \brief Build a new template-id expression.
2093 ///
2094 /// By default, performs semantic analysis to build the new expression.
2095 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002096 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002097 SourceLocation TemplateKWLoc,
2098 LookupResult &R,
2099 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002100 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002101 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2102 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002103 }
2104
2105 /// \brief Build a new object-construction expression.
2106 ///
2107 /// By default, performs semantic analysis to build the new expression.
2108 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002109 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002110 SourceLocation Loc,
2111 CXXConstructorDecl *Constructor,
2112 bool IsElidable,
2113 MultiExprArg Args,
2114 bool HadMultipleCandidates,
2115 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002116 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002117 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002118 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002119 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002120 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002121 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002122
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002123 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002124 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002125 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002126 RequiresZeroInit, ConstructKind,
2127 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002128 }
2129
2130 /// \brief Build a new object-construction expression.
2131 ///
2132 /// By default, performs semantic analysis to build the new expression.
2133 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002134 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2135 SourceLocation LParenLoc,
2136 MultiExprArg Args,
2137 SourceLocation RParenLoc) {
2138 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002139 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002140 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002141 RParenLoc);
2142 }
2143
2144 /// \brief Build a new object-construction expression.
2145 ///
2146 /// By default, performs semantic analysis to build the new expression.
2147 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002148 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2149 SourceLocation LParenLoc,
2150 MultiExprArg Args,
2151 SourceLocation RParenLoc) {
2152 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002153 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002154 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002155 RParenLoc);
2156 }
Mike Stump1eb44332009-09-09 15:08:12 +00002157
Douglas Gregorb98b1992009-08-11 05:31:07 +00002158 /// \brief Build a new member reference expression.
2159 ///
2160 /// By default, performs semantic analysis to build the new expression.
2161 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002162 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002163 QualType BaseType,
2164 bool IsArrow,
2165 SourceLocation OperatorLoc,
2166 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002167 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002168 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002169 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002170 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002171 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002172 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002173
John McCall9ae2f072010-08-23 23:25:46 +00002174 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002175 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002176 SS, TemplateKWLoc,
2177 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002178 MemberNameInfo,
2179 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002180 }
2181
John McCall129e2df2009-11-30 22:42:35 +00002182 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002183 ///
2184 /// By default, performs semantic analysis to build the new expression.
2185 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002186 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2187 SourceLocation OperatorLoc,
2188 bool IsArrow,
2189 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002190 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002191 NamedDecl *FirstQualifierInScope,
2192 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002193 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002194 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002195 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002196
John McCall9ae2f072010-08-23 23:25:46 +00002197 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002198 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002199 SS, TemplateKWLoc,
2200 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002201 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002202 }
Mike Stump1eb44332009-09-09 15:08:12 +00002203
Sebastian Redl2e156222010-09-10 20:55:43 +00002204 /// \brief Build a new noexcept expression.
2205 ///
2206 /// By default, performs semantic analysis to build the new expression.
2207 /// Subclasses may override this routine to provide different behavior.
2208 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2209 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2210 }
2211
Douglas Gregoree8aff02011-01-04 17:33:58 +00002212 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002213 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2214 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002215 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002216 llvm::Optional<unsigned> Length) {
2217 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002218 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2219 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002220 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002221
2222 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2223 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002224 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002225 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002226
Patrick Beardeb382ec2012-04-19 00:25:12 +00002227 /// \brief Build a new Objective-C boxed expression.
2228 ///
2229 /// By default, performs semantic analysis to build the new expression.
2230 /// Subclasses may override this routine to provide different behavior.
2231 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2232 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2233 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002234
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002235 /// \brief Build a new Objective-C array literal.
2236 ///
2237 /// By default, performs semantic analysis to build the new expression.
2238 /// Subclasses may override this routine to provide different behavior.
2239 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2240 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002241 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002242 MultiExprArg(Elements, NumElements));
2243 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002244
2245 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002246 Expr *Base, Expr *Key,
2247 ObjCMethodDecl *getterMethod,
2248 ObjCMethodDecl *setterMethod) {
2249 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2250 getterMethod, setterMethod);
2251 }
2252
2253 /// \brief Build a new Objective-C dictionary literal.
2254 ///
2255 /// By default, performs semantic analysis to build the new expression.
2256 /// Subclasses may override this routine to provide different behavior.
2257 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2258 ObjCDictionaryElement *Elements,
2259 unsigned NumElements) {
2260 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2261 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002262
James Dennett699c9042012-06-15 07:13:21 +00002263 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002264 ///
2265 /// By default, performs semantic analysis to build the new expression.
2266 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002267 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002268 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002269 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002270 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002271 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002272 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002273
Douglas Gregor92e986e2010-04-22 16:44:27 +00002274 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002275 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002276 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002277 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002278 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002279 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002280 MultiExprArg Args,
2281 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002282 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2283 ReceiverTypeInfo->getType(),
2284 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002285 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002286 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002287 }
2288
2289 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002290 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002291 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002292 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002293 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002294 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002295 MultiExprArg Args,
2296 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002297 return SemaRef.BuildInstanceMessage(Receiver,
2298 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002299 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002300 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002301 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002302 }
2303
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002304 /// \brief Build a new Objective-C ivar reference expression.
2305 ///
2306 /// By default, performs semantic analysis to build the new expression.
2307 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002308 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002309 SourceLocation IvarLoc,
2310 bool IsArrow, bool IsFreeIvar) {
2311 // FIXME: We lose track of the IsFreeIvar bit.
2312 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002313 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002314 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2315 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002316 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002317 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002318 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002319 false);
John Wiegley429bb272011-04-08 18:41:53 +00002320 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002321 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002322
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002323 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002324 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002325
John Wiegley429bb272011-04-08 18:41:53 +00002326 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002327 /*FIXME:*/IvarLoc, IsArrow,
2328 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002329 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002330 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002331 /*TemplateArgs=*/0);
2332 }
Douglas Gregore3303542010-04-26 20:47:02 +00002333
2334 /// \brief Build a new Objective-C property reference expression.
2335 ///
2336 /// By default, performs semantic analysis to build the new expression.
2337 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002338 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002339 ObjCPropertyDecl *Property,
2340 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002341 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002342 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002343 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2344 Sema::LookupMemberName);
2345 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002346 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002347 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002348 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002349 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002350 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002351
Douglas Gregore3303542010-04-26 20:47:02 +00002352 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002353 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002354
John Wiegley429bb272011-04-08 18:41:53 +00002355 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002356 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002357 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002358 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002359 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002360 /*TemplateArgs=*/0);
2361 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002362
John McCall12f78a62010-12-02 01:19:52 +00002363 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002364 ///
2365 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002366 /// Subclasses may override this routine to provide different behavior.
2367 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2368 ObjCMethodDecl *Getter,
2369 ObjCMethodDecl *Setter,
2370 SourceLocation PropertyLoc) {
2371 // Since these expressions can only be value-dependent, we do not
2372 // need to perform semantic analysis again.
2373 return Owned(
2374 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2375 VK_LValue, OK_ObjCProperty,
2376 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002377 }
2378
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002379 /// \brief Build a new Objective-C "isa" expression.
2380 ///
2381 /// By default, performs semantic analysis to build the new expression.
2382 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002383 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002384 bool IsArrow) {
2385 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002386 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002387 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2388 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002389 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002390 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002391 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002392 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002393 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002394
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002395 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002396 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002397
John Wiegley429bb272011-04-08 18:41:53 +00002398 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002399 /*FIXME:*/IsaLoc, IsArrow,
2400 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002401 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002402 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002403 /*TemplateArgs=*/0);
2404 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002405
Douglas Gregorb98b1992009-08-11 05:31:07 +00002406 /// \brief Build a new shuffle vector expression.
2407 ///
2408 /// By default, performs semantic analysis to build the new expression.
2409 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002410 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002411 MultiExprArg SubExprs,
2412 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002413 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002414 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002415 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2416 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2417 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2418 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002419
Douglas Gregorb98b1992009-08-11 05:31:07 +00002420 // Build a reference to the __builtin_shufflevector builtin
2421 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002422 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2423 SemaRef.Context.BuiltinFnTy,
2424 VK_RValue, BuiltinLoc);
2425 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2426 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2427 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002428
2429 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002430 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002431 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002432 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002433 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002434 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002435
Douglas Gregorb98b1992009-08-11 05:31:07 +00002436 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002437 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002438 }
John McCall43fed0d2010-11-12 08:19:04 +00002439
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002440 /// \brief Build a new template argument pack expansion.
2441 ///
2442 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002443 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002444 /// different behavior.
2445 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002446 SourceLocation EllipsisLoc,
2447 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002448 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002449 case TemplateArgument::Expression: {
2450 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002451 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2452 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002453 if (Result.isInvalid())
2454 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002455
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002456 return TemplateArgumentLoc(Result.get(), Result.get());
2457 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002458
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002459 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002460 return TemplateArgumentLoc(TemplateArgument(
2461 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002462 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002463 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002464 Pattern.getTemplateNameLoc(),
2465 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002466
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002467 case TemplateArgument::Null:
2468 case TemplateArgument::Integral:
2469 case TemplateArgument::Declaration:
2470 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002471 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002472 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002473 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002474
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002475 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002476 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002477 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002478 EllipsisLoc,
2479 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002480 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2481 Expansion);
2482 break;
2483 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002484
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002485 return TemplateArgumentLoc();
2486 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002487
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002488 /// \brief Build a new expression pack expansion.
2489 ///
2490 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002491 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002492 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002493 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2494 llvm::Optional<unsigned> NumExpansions) {
2495 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002496 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002497
2498 /// \brief Build a new atomic operation expression.
2499 ///
2500 /// By default, performs semantic analysis to build the new expression.
2501 /// Subclasses may override this routine to provide different behavior.
2502 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2503 MultiExprArg SubExprs,
2504 QualType RetTy,
2505 AtomicExpr::AtomicOp Op,
2506 SourceLocation RParenLoc) {
2507 // Just create the expression; there is not any interesting semantic
2508 // analysis here because we can't actually build an AtomicExpr until
2509 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002510 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002511 RParenLoc);
2512 }
2513
John McCall43fed0d2010-11-12 08:19:04 +00002514private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002515 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2516 QualType ObjectType,
2517 NamedDecl *FirstQualifierInScope,
2518 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002519
2520 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2521 QualType ObjectType,
2522 NamedDecl *FirstQualifierInScope,
2523 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002524};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002525
Douglas Gregor43959a92009-08-20 07:17:43 +00002526template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002527StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002528 if (!S)
2529 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002530
Douglas Gregor43959a92009-08-20 07:17:43 +00002531 switch (S->getStmtClass()) {
2532 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002533
Douglas Gregor43959a92009-08-20 07:17:43 +00002534 // Transform individual statement nodes
2535#define STMT(Node, Parent) \
2536 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002537#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002538#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002539#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002540
Douglas Gregor43959a92009-08-20 07:17:43 +00002541 // Transform expressions by calling TransformExpr.
2542#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002543#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002544#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002545#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002546 {
John McCall60d7b3a2010-08-24 06:29:42 +00002547 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002548 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002549 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002550
John McCall9ae2f072010-08-23 23:25:46 +00002551 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002552 }
Mike Stump1eb44332009-09-09 15:08:12 +00002553 }
2554
John McCall3fa5cae2010-10-26 07:05:15 +00002555 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002556}
Mike Stump1eb44332009-09-09 15:08:12 +00002557
2558
Douglas Gregor670444e2009-08-04 22:27:00 +00002559template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002560ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002561 if (!E)
2562 return SemaRef.Owned(E);
2563
2564 switch (E->getStmtClass()) {
2565 case Stmt::NoStmtClass: break;
2566#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002567#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002568#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002569 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002570#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002571 }
2572
John McCall3fa5cae2010-10-26 07:05:15 +00002573 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002574}
2575
2576template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002577bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2578 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002579 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002580 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002581 bool *ArgChanged) {
2582 for (unsigned I = 0; I != NumInputs; ++I) {
2583 // If requested, drop call arguments that need to be dropped.
2584 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2585 if (ArgChanged)
2586 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002587
Douglas Gregoraa165f82011-01-03 19:04:46 +00002588 break;
2589 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002590
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002591 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2592 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002593
Chris Lattner686775d2011-07-20 06:58:45 +00002594 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002595 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2596 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002597
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002598 // Determine whether the set of unexpanded parameter packs can and should
2599 // be expanded.
2600 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002601 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002602 llvm::Optional<unsigned> OrigNumExpansions
2603 = Expansion->getNumExpansions();
2604 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002605 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2606 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002607 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002608 Expand, RetainExpansion,
2609 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002610 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002611
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002612 if (!Expand) {
2613 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002614 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002615 // expansion.
2616 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2617 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2618 if (OutPattern.isInvalid())
2619 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002620
2621 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002622 Expansion->getEllipsisLoc(),
2623 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002624 if (Out.isInvalid())
2625 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002626
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002627 if (ArgChanged)
2628 *ArgChanged = true;
2629 Outputs.push_back(Out.get());
2630 continue;
2631 }
John McCallc8fc90a2011-07-06 07:30:07 +00002632
2633 // Record right away that the argument was changed. This needs
2634 // to happen even if the array expands to nothing.
2635 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002636
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002637 // The transform has determined that we should perform an elementwise
2638 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002639 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002640 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2641 ExprResult Out = getDerived().TransformExpr(Pattern);
2642 if (Out.isInvalid())
2643 return true;
2644
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002645 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002646 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2647 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002648 if (Out.isInvalid())
2649 return true;
2650 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002651
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002652 Outputs.push_back(Out.get());
2653 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002654
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002655 continue;
2656 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002657
Douglas Gregoraa165f82011-01-03 19:04:46 +00002658 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2659 if (Result.isInvalid())
2660 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002661
Douglas Gregoraa165f82011-01-03 19:04:46 +00002662 if (Result.get() != Inputs[I] && ArgChanged)
2663 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002664
2665 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002666 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002667
Douglas Gregoraa165f82011-01-03 19:04:46 +00002668 return false;
2669}
2670
2671template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002672NestedNameSpecifierLoc
2673TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2674 NestedNameSpecifierLoc NNS,
2675 QualType ObjectType,
2676 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002677 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002678 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002679 Qualifier = Qualifier.getPrefix())
2680 Qualifiers.push_back(Qualifier);
2681
2682 CXXScopeSpec SS;
2683 while (!Qualifiers.empty()) {
2684 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2685 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002686
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002687 switch (QNNS->getKind()) {
2688 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002689 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002690 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002691 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002692 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002693 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002694 FirstQualifierInScope, false))
2695 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002696
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002697 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002698
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002699 case NestedNameSpecifier::Namespace: {
2700 NamespaceDecl *NS
2701 = cast_or_null<NamespaceDecl>(
2702 getDerived().TransformDecl(
2703 Q.getLocalBeginLoc(),
2704 QNNS->getAsNamespace()));
2705 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2706 break;
2707 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002708
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002709 case NestedNameSpecifier::NamespaceAlias: {
2710 NamespaceAliasDecl *Alias
2711 = cast_or_null<NamespaceAliasDecl>(
2712 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2713 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002714 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002715 Q.getLocalEndLoc());
2716 break;
2717 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002718
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002719 case NestedNameSpecifier::Global:
2720 // There is no meaningful transformation that one could perform on the
2721 // global scope.
2722 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2723 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002724
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002725 case NestedNameSpecifier::TypeSpecWithTemplate:
2726 case NestedNameSpecifier::TypeSpec: {
2727 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2728 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002729
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002730 if (!TL)
2731 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002732
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002733 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00002734 (SemaRef.getLangOpts().CPlusPlus0x &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002735 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002736 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002737 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002738 if (TL.getType()->isEnumeralType())
2739 SemaRef.Diag(TL.getBeginLoc(),
2740 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002741 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2742 Q.getLocalEndLoc());
2743 break;
2744 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002745 // If the nested-name-specifier is an invalid type def, don't emit an
2746 // error because a previous error should have already been emitted.
2747 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2748 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002749 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002750 << TL.getType() << SS.getRange();
2751 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002752 return NestedNameSpecifierLoc();
2753 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002754 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002755
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002756 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002757 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002758 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002759 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002760
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002761 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002762 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002763 !getDerived().AlwaysRebuild())
2764 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002765
2766 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002767 // nested-name-specifier, do so.
2768 if (SS.location_size() == NNS.getDataLength() &&
2769 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2770 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2771
2772 // Allocate new nested-name-specifier location information.
2773 return SS.getWithLocInContext(SemaRef.Context);
2774}
2775
2776template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002777DeclarationNameInfo
2778TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002779::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002780 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002781 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002782 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002783
2784 switch (Name.getNameKind()) {
2785 case DeclarationName::Identifier:
2786 case DeclarationName::ObjCZeroArgSelector:
2787 case DeclarationName::ObjCOneArgSelector:
2788 case DeclarationName::ObjCMultiArgSelector:
2789 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002790 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002791 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002792 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002793
Douglas Gregor81499bb2009-09-03 22:13:48 +00002794 case DeclarationName::CXXConstructorName:
2795 case DeclarationName::CXXDestructorName:
2796 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002797 TypeSourceInfo *NewTInfo;
2798 CanQualType NewCanTy;
2799 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002800 NewTInfo = getDerived().TransformType(OldTInfo);
2801 if (!NewTInfo)
2802 return DeclarationNameInfo();
2803 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002804 }
2805 else {
2806 NewTInfo = 0;
2807 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002808 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002809 if (NewT.isNull())
2810 return DeclarationNameInfo();
2811 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2812 }
Mike Stump1eb44332009-09-09 15:08:12 +00002813
Abramo Bagnara25777432010-08-11 22:01:17 +00002814 DeclarationName NewName
2815 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2816 NewCanTy);
2817 DeclarationNameInfo NewNameInfo(NameInfo);
2818 NewNameInfo.setName(NewName);
2819 NewNameInfo.setNamedTypeInfo(NewTInfo);
2820 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002821 }
Mike Stump1eb44332009-09-09 15:08:12 +00002822 }
2823
David Blaikieb219cfc2011-09-23 05:06:16 +00002824 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002825}
2826
2827template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002828TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002829TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2830 TemplateName Name,
2831 SourceLocation NameLoc,
2832 QualType ObjectType,
2833 NamedDecl *FirstQualifierInScope) {
2834 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2835 TemplateDecl *Template = QTN->getTemplateDecl();
2836 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002837
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002838 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002839 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002840 Template));
2841 if (!TransTemplate)
2842 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002843
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002844 if (!getDerived().AlwaysRebuild() &&
2845 SS.getScopeRep() == QTN->getQualifier() &&
2846 TransTemplate == Template)
2847 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002848
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002849 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2850 TransTemplate);
2851 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002852
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002853 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2854 if (SS.getScopeRep()) {
2855 // These apply to the scope specifier, not the template.
2856 ObjectType = QualType();
2857 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002858 }
2859
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002860 if (!getDerived().AlwaysRebuild() &&
2861 SS.getScopeRep() == DTN->getQualifier() &&
2862 ObjectType.isNull())
2863 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002864
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002865 if (DTN->isIdentifier()) {
2866 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002867 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002868 NameLoc,
2869 ObjectType,
2870 FirstQualifierInScope);
2871 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002872
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002873 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2874 ObjectType);
2875 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002876
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002877 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2878 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002879 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002880 Template));
2881 if (!TransTemplate)
2882 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002883
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002884 if (!getDerived().AlwaysRebuild() &&
2885 TransTemplate == Template)
2886 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002887
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002888 return TemplateName(TransTemplate);
2889 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002890
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002891 if (SubstTemplateTemplateParmPackStorage *SubstPack
2892 = Name.getAsSubstTemplateTemplateParmPack()) {
2893 TemplateTemplateParmDecl *TransParam
2894 = cast_or_null<TemplateTemplateParmDecl>(
2895 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2896 if (!TransParam)
2897 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002898
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002899 if (!getDerived().AlwaysRebuild() &&
2900 TransParam == SubstPack->getParameterPack())
2901 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002902
2903 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002904 SubstPack->getArgumentPack());
2905 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002906
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002907 // These should be getting filtered out before they reach the AST.
2908 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002909}
2910
2911template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002912void TreeTransform<Derived>::InventTemplateArgumentLoc(
2913 const TemplateArgument &Arg,
2914 TemplateArgumentLoc &Output) {
2915 SourceLocation Loc = getDerived().getBaseLocation();
2916 switch (Arg.getKind()) {
2917 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002918 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002919 break;
2920
2921 case TemplateArgument::Type:
2922 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002923 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002924
John McCall833ca992009-10-29 08:12:44 +00002925 break;
2926
Douglas Gregor788cd062009-11-11 01:00:40 +00002927 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002928 case TemplateArgument::TemplateExpansion: {
2929 NestedNameSpecifierLocBuilder Builder;
2930 TemplateName Template = Arg.getAsTemplate();
2931 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2932 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2933 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2934 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002935
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002936 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002937 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002938 Builder.getWithLocInContext(SemaRef.Context),
2939 Loc);
2940 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00002941 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002942 Builder.getWithLocInContext(SemaRef.Context),
2943 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002944
Douglas Gregor788cd062009-11-11 01:00:40 +00002945 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002946 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002947
John McCall833ca992009-10-29 08:12:44 +00002948 case TemplateArgument::Expression:
2949 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2950 break;
2951
2952 case TemplateArgument::Declaration:
2953 case TemplateArgument::Integral:
2954 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002955 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00002956 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002957 break;
2958 }
2959}
2960
2961template<typename Derived>
2962bool TreeTransform<Derived>::TransformTemplateArgument(
2963 const TemplateArgumentLoc &Input,
2964 TemplateArgumentLoc &Output) {
2965 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002966 switch (Arg.getKind()) {
2967 case TemplateArgument::Null:
2968 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00002969 case TemplateArgument::Pack:
2970 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002971 case TemplateArgument::NullPtr:
2972 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00002973
Douglas Gregor670444e2009-08-04 22:27:00 +00002974 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002975 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002976 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002977 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002978
2979 DI = getDerived().TransformType(DI);
2980 if (!DI) return true;
2981
2982 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2983 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002984 }
Mike Stump1eb44332009-09-09 15:08:12 +00002985
Douglas Gregor788cd062009-11-11 01:00:40 +00002986 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002987 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2988 if (QualifierLoc) {
2989 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2990 if (!QualifierLoc)
2991 return true;
2992 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002993
Douglas Gregor1d752d72011-03-02 18:46:51 +00002994 CXXScopeSpec SS;
2995 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002996 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00002997 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2998 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00002999 if (Template.isNull())
3000 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003001
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003002 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003003 Input.getTemplateNameLoc());
3004 return false;
3005 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003006
3007 case TemplateArgument::TemplateExpansion:
3008 llvm_unreachable("Caller should expand pack expansions");
3009
Douglas Gregor670444e2009-08-04 22:27:00 +00003010 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003011 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003012 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003013 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003014
John McCall833ca992009-10-29 08:12:44 +00003015 Expr *InputExpr = Input.getSourceExpression();
3016 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3017
Chris Lattner223de242011-04-25 20:37:58 +00003018 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003019 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003020 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003021 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003022 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003023 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003024 }
Mike Stump1eb44332009-09-09 15:08:12 +00003025
Douglas Gregor670444e2009-08-04 22:27:00 +00003026 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003027 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003028}
3029
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003030/// \brief Iterator adaptor that invents template argument location information
3031/// for each of the template arguments in its underlying iterator.
3032template<typename Derived, typename InputIterator>
3033class TemplateArgumentLocInventIterator {
3034 TreeTransform<Derived> &Self;
3035 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003036
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003037public:
3038 typedef TemplateArgumentLoc value_type;
3039 typedef TemplateArgumentLoc reference;
3040 typedef typename std::iterator_traits<InputIterator>::difference_type
3041 difference_type;
3042 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003043
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003044 class pointer {
3045 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003046
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003047 public:
3048 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003049
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003050 const TemplateArgumentLoc *operator->() const { return &Arg; }
3051 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003052
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003053 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003054
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003055 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3056 InputIterator Iter)
3057 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003058
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003059 TemplateArgumentLocInventIterator &operator++() {
3060 ++Iter;
3061 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003062 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003063
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003064 TemplateArgumentLocInventIterator operator++(int) {
3065 TemplateArgumentLocInventIterator Old(*this);
3066 ++(*this);
3067 return Old;
3068 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003069
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003070 reference operator*() const {
3071 TemplateArgumentLoc Result;
3072 Self.InventTemplateArgumentLoc(*Iter, Result);
3073 return Result;
3074 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003075
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003076 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003077
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003078 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3079 const TemplateArgumentLocInventIterator &Y) {
3080 return X.Iter == Y.Iter;
3081 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003082
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003083 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3084 const TemplateArgumentLocInventIterator &Y) {
3085 return X.Iter != Y.Iter;
3086 }
3087};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003088
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003089template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003090template<typename InputIterator>
3091bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3092 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003093 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003094 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003095 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003096 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003097
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003098 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3099 // Unpack argument packs, which we translate them into separate
3100 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003101 // FIXME: We could do much better if we could guarantee that the
3102 // TemplateArgumentLocInfo for the pack expansion would be usable for
3103 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003104 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003105 TemplateArgument::pack_iterator>
3106 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003107 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003108 In.getArgument().pack_begin()),
3109 PackLocIterator(*this,
3110 In.getArgument().pack_end()),
3111 Outputs))
3112 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003113
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003114 continue;
3115 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003116
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003117 if (In.getArgument().isPackExpansion()) {
3118 // We have a pack expansion, for which we will be substituting into
3119 // the pattern.
3120 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003121 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003122 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003123 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003124 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003125
Chris Lattner686775d2011-07-20 06:58:45 +00003126 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003127 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3128 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003129
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003130 // Determine whether the set of unexpanded parameter packs can and should
3131 // be expanded.
3132 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003133 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003134 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003135 if (getDerived().TryExpandParameterPacks(Ellipsis,
3136 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003137 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003138 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003139 RetainExpansion,
3140 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003141 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003142
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003143 if (!Expand) {
3144 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003145 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003146 // expansion.
3147 TemplateArgumentLoc OutPattern;
3148 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3149 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3150 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003151
Douglas Gregorcded4f62011-01-14 17:04:44 +00003152 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3153 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003154 if (Out.getArgument().isNull())
3155 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003156
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003157 Outputs.addArgument(Out);
3158 continue;
3159 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003160
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003161 // The transform has determined that we should perform an elementwise
3162 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003163 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003164 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3165
3166 if (getDerived().TransformTemplateArgument(Pattern, Out))
3167 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003168
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003169 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003170 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3171 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003172 if (Out.getArgument().isNull())
3173 return true;
3174 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003175
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003176 Outputs.addArgument(Out);
3177 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003178
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003179 // If we're supposed to retain a pack expansion, do so by temporarily
3180 // forgetting the partially-substituted parameter pack.
3181 if (RetainExpansion) {
3182 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003183
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003184 if (getDerived().TransformTemplateArgument(Pattern, Out))
3185 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003186
Douglas Gregorcded4f62011-01-14 17:04:44 +00003187 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3188 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003189 if (Out.getArgument().isNull())
3190 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003191
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003192 Outputs.addArgument(Out);
3193 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003194
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003195 continue;
3196 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003197
3198 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003199 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003200 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003201
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003202 Outputs.addArgument(Out);
3203 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003204
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003205 return false;
3206
3207}
3208
Douglas Gregor577f75a2009-08-04 16:50:30 +00003209//===----------------------------------------------------------------------===//
3210// Type transformation
3211//===----------------------------------------------------------------------===//
3212
3213template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003214QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003215 if (getDerived().AlreadyTransformed(T))
3216 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003217
John McCalla2becad2009-10-21 00:40:46 +00003218 // Temporary workaround. All of these transformations should
3219 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003220 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3221 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003222
John McCall43fed0d2010-11-12 08:19:04 +00003223 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003224
John McCalla2becad2009-10-21 00:40:46 +00003225 if (!NewDI)
3226 return QualType();
3227
3228 return NewDI->getType();
3229}
3230
3231template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003232TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003233 // Refine the base location to the type's location.
3234 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3235 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003236 if (getDerived().AlreadyTransformed(DI->getType()))
3237 return DI;
3238
3239 TypeLocBuilder TLB;
3240
3241 TypeLoc TL = DI->getTypeLoc();
3242 TLB.reserve(TL.getFullDataSize());
3243
John McCall43fed0d2010-11-12 08:19:04 +00003244 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003245 if (Result.isNull())
3246 return 0;
3247
John McCalla93c9342009-12-07 02:54:59 +00003248 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003249}
3250
3251template<typename Derived>
3252QualType
John McCall43fed0d2010-11-12 08:19:04 +00003253TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003254 switch (T.getTypeLocClass()) {
3255#define ABSTRACT_TYPELOC(CLASS, PARENT)
3256#define TYPELOC(CLASS, PARENT) \
3257 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003258 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003259#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003260 }
Mike Stump1eb44332009-09-09 15:08:12 +00003261
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003262 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003263}
3264
3265/// FIXME: By default, this routine adds type qualifiers only to types
3266/// that can have qualifiers, and silently suppresses those qualifiers
3267/// that are not permitted (e.g., qualifiers on reference or function
3268/// types). This is the right thing for template instantiation, but
3269/// probably not for other clients.
3270template<typename Derived>
3271QualType
3272TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003273 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003274 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003275
John McCall43fed0d2010-11-12 08:19:04 +00003276 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003277 if (Result.isNull())
3278 return QualType();
3279
3280 // Silently suppress qualifiers if the result type can't be qualified.
3281 // FIXME: this is the right thing for template instantiation, but
3282 // probably not for other clients.
3283 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003284 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003285
John McCallf85e1932011-06-15 23:02:42 +00003286 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003287 // resulting type.
3288 if (Quals.hasObjCLifetime()) {
3289 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3290 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003291 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003292 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003293 // A lifetime qualifier applied to a substituted template parameter
3294 // overrides the lifetime qualifier from the template argument.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003295 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003296 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3297 QualType Replacement = SubstTypeParam->getReplacementType();
3298 Qualifiers Qs = Replacement.getQualifiers();
3299 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003300 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003301 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3302 Qs);
3303 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003304 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003305 Replacement);
3306 TLB.TypeWasModifiedSafely(Result);
3307 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003308 // Otherwise, complain about the addition of a qualifier to an
3309 // already-qualified type.
3310 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003311 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003312 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003313
Douglas Gregore559ca12011-06-17 22:11:49 +00003314 Quals.removeObjCLifetime();
3315 }
3316 }
3317 }
John McCall28654742010-06-05 06:41:15 +00003318 if (!Quals.empty()) {
3319 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3320 TLB.push<QualifiedTypeLoc>(Result);
3321 // No location information to preserve.
3322 }
John McCalla2becad2009-10-21 00:40:46 +00003323
3324 return Result;
3325}
3326
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003327template<typename Derived>
3328TypeLoc
3329TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3330 QualType ObjectType,
3331 NamedDecl *UnqualLookup,
3332 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003333 QualType T = TL.getType();
3334 if (getDerived().AlreadyTransformed(T))
3335 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003336
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003337 TypeLocBuilder TLB;
3338 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003339
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003340 if (isa<TemplateSpecializationType>(T)) {
3341 TemplateSpecializationTypeLoc SpecTL
3342 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003343
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003344 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003345 getDerived().TransformTemplateName(SS,
3346 SpecTL.getTypePtr()->getTemplateName(),
3347 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003348 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003349 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003350 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003351
3352 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003353 Template);
3354 } else if (isa<DependentTemplateSpecializationType>(T)) {
3355 DependentTemplateSpecializationTypeLoc SpecTL
3356 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003357
Douglas Gregora88f09f2011-02-28 17:23:35 +00003358 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003359 = getDerived().RebuildTemplateName(SS,
3360 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003361 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003362 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003363 if (Template.isNull())
3364 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003365
3366 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003367 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003368 Template,
3369 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003370 } else {
3371 // Nothing special needs to be done for these.
3372 Result = getDerived().TransformType(TLB, TL);
3373 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003374
3375 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003376 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003377
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003378 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3379}
3380
Douglas Gregorb71d8212011-03-02 18:32:08 +00003381template<typename Derived>
3382TypeSourceInfo *
3383TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3384 QualType ObjectType,
3385 NamedDecl *UnqualLookup,
3386 CXXScopeSpec &SS) {
3387 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003388
Douglas Gregorb71d8212011-03-02 18:32:08 +00003389 QualType T = TSInfo->getType();
3390 if (getDerived().AlreadyTransformed(T))
3391 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003392
Douglas Gregorb71d8212011-03-02 18:32:08 +00003393 TypeLocBuilder TLB;
3394 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003395
Douglas Gregorb71d8212011-03-02 18:32:08 +00003396 TypeLoc TL = TSInfo->getTypeLoc();
3397 if (isa<TemplateSpecializationType>(T)) {
3398 TemplateSpecializationTypeLoc SpecTL
3399 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003400
Douglas Gregorb71d8212011-03-02 18:32:08 +00003401 TemplateName Template
3402 = getDerived().TransformTemplateName(SS,
3403 SpecTL.getTypePtr()->getTemplateName(),
3404 SpecTL.getTemplateNameLoc(),
3405 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003406 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003407 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003408
3409 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003410 Template);
3411 } else if (isa<DependentTemplateSpecializationType>(T)) {
3412 DependentTemplateSpecializationTypeLoc SpecTL
3413 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003414
Douglas Gregorb71d8212011-03-02 18:32:08 +00003415 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003416 = getDerived().RebuildTemplateName(SS,
3417 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003418 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003419 ObjectType, UnqualLookup);
3420 if (Template.isNull())
3421 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003422
3423 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003424 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003425 Template,
3426 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003427 } else {
3428 // Nothing special needs to be done for these.
3429 Result = getDerived().TransformType(TLB, TL);
3430 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003431
3432 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003433 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003434
Douglas Gregorb71d8212011-03-02 18:32:08 +00003435 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3436}
3437
John McCalla2becad2009-10-21 00:40:46 +00003438template <class TyLoc> static inline
3439QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3440 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3441 NewT.setNameLoc(T.getNameLoc());
3442 return T.getType();
3443}
3444
John McCalla2becad2009-10-21 00:40:46 +00003445template<typename Derived>
3446QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003447 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003448 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3449 NewT.setBuiltinLoc(T.getBuiltinLoc());
3450 if (T.needsExtraLocalData())
3451 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3452 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003453}
Mike Stump1eb44332009-09-09 15:08:12 +00003454
Douglas Gregor577f75a2009-08-04 16:50:30 +00003455template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003456QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003457 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003458 // FIXME: recurse?
3459 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003460}
Mike Stump1eb44332009-09-09 15:08:12 +00003461
Douglas Gregor577f75a2009-08-04 16:50:30 +00003462template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003463QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003464 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003465 QualType PointeeType
3466 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003467 if (PointeeType.isNull())
3468 return QualType();
3469
3470 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003471 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003472 // A dependent pointer type 'T *' has is being transformed such
3473 // that an Objective-C class type is being replaced for 'T'. The
3474 // resulting pointer type is an ObjCObjectPointerType, not a
3475 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003476 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003477
John McCallc12c5bb2010-05-15 11:32:37 +00003478 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3479 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003480 return Result;
3481 }
John McCall43fed0d2010-11-12 08:19:04 +00003482
Douglas Gregor92e986e2010-04-22 16:44:27 +00003483 if (getDerived().AlwaysRebuild() ||
3484 PointeeType != TL.getPointeeLoc().getType()) {
3485 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3486 if (Result.isNull())
3487 return QualType();
3488 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003489
John McCallf85e1932011-06-15 23:02:42 +00003490 // Objective-C ARC can add lifetime qualifiers to the type that we're
3491 // pointing to.
3492 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003493
Douglas Gregor92e986e2010-04-22 16:44:27 +00003494 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3495 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003496 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003497}
Mike Stump1eb44332009-09-09 15:08:12 +00003498
3499template<typename Derived>
3500QualType
John McCalla2becad2009-10-21 00:40:46 +00003501TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003502 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003503 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003504 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3505 if (PointeeType.isNull())
3506 return QualType();
3507
3508 QualType Result = TL.getType();
3509 if (getDerived().AlwaysRebuild() ||
3510 PointeeType != TL.getPointeeLoc().getType()) {
3511 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003512 TL.getSigilLoc());
3513 if (Result.isNull())
3514 return QualType();
3515 }
3516
Douglas Gregor39968ad2010-04-22 16:50:51 +00003517 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003518 NewT.setSigilLoc(TL.getSigilLoc());
3519 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003520}
3521
John McCall85737a72009-10-30 00:06:24 +00003522/// Transforms a reference type. Note that somewhat paradoxically we
3523/// don't care whether the type itself is an l-value type or an r-value
3524/// type; we only care if the type was *written* as an l-value type
3525/// or an r-value type.
3526template<typename Derived>
3527QualType
3528TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003529 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003530 const ReferenceType *T = TL.getTypePtr();
3531
3532 // Note that this works with the pointee-as-written.
3533 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3534 if (PointeeType.isNull())
3535 return QualType();
3536
3537 QualType Result = TL.getType();
3538 if (getDerived().AlwaysRebuild() ||
3539 PointeeType != T->getPointeeTypeAsWritten()) {
3540 Result = getDerived().RebuildReferenceType(PointeeType,
3541 T->isSpelledAsLValue(),
3542 TL.getSigilLoc());
3543 if (Result.isNull())
3544 return QualType();
3545 }
3546
John McCallf85e1932011-06-15 23:02:42 +00003547 // Objective-C ARC can add lifetime qualifiers to the type that we're
3548 // referring to.
3549 TLB.TypeWasModifiedSafely(
3550 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3551
John McCall85737a72009-10-30 00:06:24 +00003552 // r-value references can be rebuilt as l-value references.
3553 ReferenceTypeLoc NewTL;
3554 if (isa<LValueReferenceType>(Result))
3555 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3556 else
3557 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3558 NewTL.setSigilLoc(TL.getSigilLoc());
3559
3560 return Result;
3561}
3562
Mike Stump1eb44332009-09-09 15:08:12 +00003563template<typename Derived>
3564QualType
John McCalla2becad2009-10-21 00:40:46 +00003565TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003566 LValueReferenceTypeLoc TL) {
3567 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003568}
3569
Mike Stump1eb44332009-09-09 15:08:12 +00003570template<typename Derived>
3571QualType
John McCalla2becad2009-10-21 00:40:46 +00003572TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003573 RValueReferenceTypeLoc TL) {
3574 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003575}
Mike Stump1eb44332009-09-09 15:08:12 +00003576
Douglas Gregor577f75a2009-08-04 16:50:30 +00003577template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003578QualType
John McCalla2becad2009-10-21 00:40:46 +00003579TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003580 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003581 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003582 if (PointeeType.isNull())
3583 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003584
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003585 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3586 TypeSourceInfo* NewClsTInfo = 0;
3587 if (OldClsTInfo) {
3588 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3589 if (!NewClsTInfo)
3590 return QualType();
3591 }
3592
3593 const MemberPointerType *T = TL.getTypePtr();
3594 QualType OldClsType = QualType(T->getClass(), 0);
3595 QualType NewClsType;
3596 if (NewClsTInfo)
3597 NewClsType = NewClsTInfo->getType();
3598 else {
3599 NewClsType = getDerived().TransformType(OldClsType);
3600 if (NewClsType.isNull())
3601 return QualType();
3602 }
Mike Stump1eb44332009-09-09 15:08:12 +00003603
John McCalla2becad2009-10-21 00:40:46 +00003604 QualType Result = TL.getType();
3605 if (getDerived().AlwaysRebuild() ||
3606 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003607 NewClsType != OldClsType) {
3608 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003609 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003610 if (Result.isNull())
3611 return QualType();
3612 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003613
John McCalla2becad2009-10-21 00:40:46 +00003614 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3615 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003616 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003617
3618 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003619}
3620
Mike Stump1eb44332009-09-09 15:08:12 +00003621template<typename Derived>
3622QualType
John McCalla2becad2009-10-21 00:40:46 +00003623TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003624 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003625 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003626 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003627 if (ElementType.isNull())
3628 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003629
John McCalla2becad2009-10-21 00:40:46 +00003630 QualType Result = TL.getType();
3631 if (getDerived().AlwaysRebuild() ||
3632 ElementType != T->getElementType()) {
3633 Result = getDerived().RebuildConstantArrayType(ElementType,
3634 T->getSizeModifier(),
3635 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003636 T->getIndexTypeCVRQualifiers(),
3637 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003638 if (Result.isNull())
3639 return QualType();
3640 }
Eli Friedman457a3772012-01-25 22:19:07 +00003641
3642 // We might have either a ConstantArrayType or a VariableArrayType now:
3643 // a ConstantArrayType is allowed to have an element type which is a
3644 // VariableArrayType if the type is dependent. Fortunately, all array
3645 // types have the same location layout.
3646 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003647 NewTL.setLBracketLoc(TL.getLBracketLoc());
3648 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003649
John McCalla2becad2009-10-21 00:40:46 +00003650 Expr *Size = TL.getSizeExpr();
3651 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003652 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3653 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003654 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003655 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003656 }
3657 NewTL.setSizeExpr(Size);
3658
3659 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003660}
Mike Stump1eb44332009-09-09 15:08:12 +00003661
Douglas Gregor577f75a2009-08-04 16:50:30 +00003662template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003663QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003664 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003665 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003666 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003667 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003668 if (ElementType.isNull())
3669 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003670
John McCalla2becad2009-10-21 00:40:46 +00003671 QualType Result = TL.getType();
3672 if (getDerived().AlwaysRebuild() ||
3673 ElementType != T->getElementType()) {
3674 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003675 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003676 T->getIndexTypeCVRQualifiers(),
3677 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003678 if (Result.isNull())
3679 return QualType();
3680 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003681
John McCalla2becad2009-10-21 00:40:46 +00003682 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3683 NewTL.setLBracketLoc(TL.getLBracketLoc());
3684 NewTL.setRBracketLoc(TL.getRBracketLoc());
3685 NewTL.setSizeExpr(0);
3686
3687 return Result;
3688}
3689
3690template<typename Derived>
3691QualType
3692TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003693 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003694 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003695 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3696 if (ElementType.isNull())
3697 return QualType();
3698
John McCall60d7b3a2010-08-24 06:29:42 +00003699 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003700 = getDerived().TransformExpr(T->getSizeExpr());
3701 if (SizeResult.isInvalid())
3702 return QualType();
3703
John McCall9ae2f072010-08-23 23:25:46 +00003704 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003705
3706 QualType Result = TL.getType();
3707 if (getDerived().AlwaysRebuild() ||
3708 ElementType != T->getElementType() ||
3709 Size != T->getSizeExpr()) {
3710 Result = getDerived().RebuildVariableArrayType(ElementType,
3711 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003712 Size,
John McCalla2becad2009-10-21 00:40:46 +00003713 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003714 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003715 if (Result.isNull())
3716 return QualType();
3717 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003718
John McCalla2becad2009-10-21 00:40:46 +00003719 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3720 NewTL.setLBracketLoc(TL.getLBracketLoc());
3721 NewTL.setRBracketLoc(TL.getRBracketLoc());
3722 NewTL.setSizeExpr(Size);
3723
3724 return Result;
3725}
3726
3727template<typename Derived>
3728QualType
3729TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003730 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003731 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003732 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3733 if (ElementType.isNull())
3734 return QualType();
3735
Richard Smithf6702a32011-12-20 02:08:33 +00003736 // Array bounds are constant expressions.
3737 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3738 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003739
John McCall3b657512011-01-19 10:06:00 +00003740 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3741 Expr *origSize = TL.getSizeExpr();
3742 if (!origSize) origSize = T->getSizeExpr();
3743
3744 ExprResult sizeResult
3745 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003746 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003747 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003748 return QualType();
3749
John McCall3b657512011-01-19 10:06:00 +00003750 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003751
3752 QualType Result = TL.getType();
3753 if (getDerived().AlwaysRebuild() ||
3754 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003755 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003756 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3757 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003758 size,
John McCalla2becad2009-10-21 00:40:46 +00003759 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003760 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003761 if (Result.isNull())
3762 return QualType();
3763 }
John McCalla2becad2009-10-21 00:40:46 +00003764
3765 // We might have any sort of array type now, but fortunately they
3766 // all have the same location layout.
3767 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3768 NewTL.setLBracketLoc(TL.getLBracketLoc());
3769 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003770 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003771
3772 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003773}
Mike Stump1eb44332009-09-09 15:08:12 +00003774
3775template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003776QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003777 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003778 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003779 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003780
3781 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003782 QualType ElementType = getDerived().TransformType(T->getElementType());
3783 if (ElementType.isNull())
3784 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003785
Richard Smithf6702a32011-12-20 02:08:33 +00003786 // Vector sizes are constant expressions.
3787 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3788 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003789
John McCall60d7b3a2010-08-24 06:29:42 +00003790 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003791 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003792 if (Size.isInvalid())
3793 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003794
John McCalla2becad2009-10-21 00:40:46 +00003795 QualType Result = TL.getType();
3796 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003797 ElementType != T->getElementType() ||
3798 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003799 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003800 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003801 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003802 if (Result.isNull())
3803 return QualType();
3804 }
John McCalla2becad2009-10-21 00:40:46 +00003805
3806 // Result might be dependent or not.
3807 if (isa<DependentSizedExtVectorType>(Result)) {
3808 DependentSizedExtVectorTypeLoc NewTL
3809 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3810 NewTL.setNameLoc(TL.getNameLoc());
3811 } else {
3812 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3813 NewTL.setNameLoc(TL.getNameLoc());
3814 }
3815
3816 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003817}
Mike Stump1eb44332009-09-09 15:08:12 +00003818
3819template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003820QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003821 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003822 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003823 QualType ElementType = getDerived().TransformType(T->getElementType());
3824 if (ElementType.isNull())
3825 return QualType();
3826
John McCalla2becad2009-10-21 00:40:46 +00003827 QualType Result = TL.getType();
3828 if (getDerived().AlwaysRebuild() ||
3829 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003830 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003831 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003832 if (Result.isNull())
3833 return QualType();
3834 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003835
John McCalla2becad2009-10-21 00:40:46 +00003836 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3837 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003838
John McCalla2becad2009-10-21 00:40:46 +00003839 return Result;
3840}
3841
3842template<typename Derived>
3843QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003844 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003845 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003846 QualType ElementType = getDerived().TransformType(T->getElementType());
3847 if (ElementType.isNull())
3848 return QualType();
3849
3850 QualType Result = TL.getType();
3851 if (getDerived().AlwaysRebuild() ||
3852 ElementType != T->getElementType()) {
3853 Result = getDerived().RebuildExtVectorType(ElementType,
3854 T->getNumElements(),
3855 /*FIXME*/ SourceLocation());
3856 if (Result.isNull())
3857 return QualType();
3858 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003859
John McCalla2becad2009-10-21 00:40:46 +00003860 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3861 NewTL.setNameLoc(TL.getNameLoc());
3862
3863 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003864}
Mike Stump1eb44332009-09-09 15:08:12 +00003865
3866template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003867ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003868TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003869 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003870 llvm::Optional<unsigned> NumExpansions,
3871 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003872 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003873 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003874
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003875 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003876 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003877 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003878 TypeLoc OldTL = OldDI->getTypeLoc();
3879 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003880
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003881 TypeLocBuilder TLB;
3882 TypeLoc NewTL = OldDI->getTypeLoc();
3883 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003884
3885 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003886 OldExpansionTL.getPatternLoc());
3887 if (Result.isNull())
3888 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003889
3890 Result = RebuildPackExpansionType(Result,
3891 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003892 OldExpansionTL.getEllipsisLoc(),
3893 NumExpansions);
3894 if (Result.isNull())
3895 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003896
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003897 PackExpansionTypeLoc NewExpansionTL
3898 = TLB.push<PackExpansionTypeLoc>(Result);
3899 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3900 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3901 } else
3902 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003903 if (!NewDI)
3904 return 0;
3905
John McCallfb44de92011-05-01 22:35:37 +00003906 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003907 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003908
3909 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3910 OldParm->getDeclContext(),
3911 OldParm->getInnerLocStart(),
3912 OldParm->getLocation(),
3913 OldParm->getIdentifier(),
3914 NewDI->getType(),
3915 NewDI,
3916 OldParm->getStorageClass(),
3917 OldParm->getStorageClassAsWritten(),
3918 /* DefArg */ NULL);
3919 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3920 OldParm->getFunctionScopeIndex() + indexAdjustment);
3921 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003922}
3923
3924template<typename Derived>
3925bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003926 TransformFunctionTypeParams(SourceLocation Loc,
3927 ParmVarDecl **Params, unsigned NumParams,
3928 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003929 SmallVectorImpl<QualType> &OutParamTypes,
3930 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003931 int indexAdjustment = 0;
3932
Douglas Gregora009b592011-01-07 00:20:55 +00003933 for (unsigned i = 0; i != NumParams; ++i) {
3934 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003935 assert(OldParm->getFunctionScopeIndex() == i);
3936
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003937 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003938 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003939 if (OldParm->isParameterPack()) {
3940 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003941 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003942
Douglas Gregor603cfb42011-01-05 23:12:31 +00003943 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003944 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3945 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3946 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3947 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003948 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3949
Douglas Gregor603cfb42011-01-05 23:12:31 +00003950 // Determine whether we should expand the parameter packs.
3951 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003952 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003953 llvm::Optional<unsigned> OrigNumExpansions
3954 = ExpansionTL.getTypePtr()->getNumExpansions();
3955 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003956 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3957 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00003958 Unexpanded,
3959 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00003960 RetainExpansion,
3961 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003962 return true;
3963 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003964
Douglas Gregor603cfb42011-01-05 23:12:31 +00003965 if (ShouldExpand) {
3966 // Expand the function parameter pack into multiple, separate
3967 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003968 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003969 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003970 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003971 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003972 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003973 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003974 OrigNumExpansions,
3975 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003976 if (!NewParm)
3977 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003978
Douglas Gregora009b592011-01-07 00:20:55 +00003979 OutParamTypes.push_back(NewParm->getType());
3980 if (PVars)
3981 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003982 }
Douglas Gregord3731192011-01-10 07:32:04 +00003983
3984 // If we're supposed to retain a pack expansion, do so by temporarily
3985 // forgetting the partially-substituted parameter pack.
3986 if (RetainExpansion) {
3987 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003988 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003989 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003990 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003991 OrigNumExpansions,
3992 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00003993 if (!NewParm)
3994 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003995
Douglas Gregord3731192011-01-10 07:32:04 +00003996 OutParamTypes.push_back(NewParm->getType());
3997 if (PVars)
3998 PVars->push_back(NewParm);
3999 }
4000
John McCallfb44de92011-05-01 22:35:37 +00004001 // The next parameter should have the same adjustment as the
4002 // last thing we pushed, but we post-incremented indexAdjustment
4003 // on every push. Also, if we push nothing, the adjustment should
4004 // go down by one.
4005 indexAdjustment--;
4006
Douglas Gregor603cfb42011-01-05 23:12:31 +00004007 // We're done with the pack expansion.
4008 continue;
4009 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004010
4011 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004012 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004013 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4014 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004015 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004016 NumExpansions,
4017 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004018 } else {
4019 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004020 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004021 llvm::Optional<unsigned>(),
4022 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004023 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004024
John McCall21ef0fa2010-03-11 09:03:00 +00004025 if (!NewParm)
4026 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004027
Douglas Gregora009b592011-01-07 00:20:55 +00004028 OutParamTypes.push_back(NewParm->getType());
4029 if (PVars)
4030 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004031 continue;
4032 }
John McCall21ef0fa2010-03-11 09:03:00 +00004033
4034 // Deal with the possibility that we don't have a parameter
4035 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004036 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004037 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004038 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004039 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004040 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004041 = dyn_cast<PackExpansionType>(OldType)) {
4042 // We have a function parameter pack that may need to be expanded.
4043 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004044 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004045 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004046
Douglas Gregor603cfb42011-01-05 23:12:31 +00004047 // Determine whether we should expand the parameter packs.
4048 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004049 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004050 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004051 Unexpanded,
4052 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004053 RetainExpansion,
4054 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004055 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004056 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004057
Douglas Gregor603cfb42011-01-05 23:12:31 +00004058 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004059 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004060 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004061 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004062 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4063 QualType NewType = getDerived().TransformType(Pattern);
4064 if (NewType.isNull())
4065 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004066
Douglas Gregora009b592011-01-07 00:20:55 +00004067 OutParamTypes.push_back(NewType);
4068 if (PVars)
4069 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004070 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004071
Douglas Gregor603cfb42011-01-05 23:12:31 +00004072 // We're done with the pack expansion.
4073 continue;
4074 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004075
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004076 // If we're supposed to retain a pack expansion, do so by temporarily
4077 // forgetting the partially-substituted parameter pack.
4078 if (RetainExpansion) {
4079 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4080 QualType NewType = getDerived().TransformType(Pattern);
4081 if (NewType.isNull())
4082 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004083
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004084 OutParamTypes.push_back(NewType);
4085 if (PVars)
4086 PVars->push_back(0);
4087 }
Douglas Gregord3731192011-01-10 07:32:04 +00004088
Chad Rosier4a9d7952012-08-08 18:46:20 +00004089 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004090 // expansion.
4091 OldType = Expansion->getPattern();
4092 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004093 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4094 NewType = getDerived().TransformType(OldType);
4095 } else {
4096 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004097 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004098
Douglas Gregor603cfb42011-01-05 23:12:31 +00004099 if (NewType.isNull())
4100 return true;
4101
4102 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004103 NewType = getSema().Context.getPackExpansionType(NewType,
4104 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004105
Douglas Gregora009b592011-01-07 00:20:55 +00004106 OutParamTypes.push_back(NewType);
4107 if (PVars)
4108 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004109 }
4110
John McCallfb44de92011-05-01 22:35:37 +00004111#ifndef NDEBUG
4112 if (PVars) {
4113 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4114 if (ParmVarDecl *parm = (*PVars)[i])
4115 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004116 }
John McCallfb44de92011-05-01 22:35:37 +00004117#endif
4118
4119 return false;
4120}
John McCall21ef0fa2010-03-11 09:03:00 +00004121
4122template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004123QualType
John McCalla2becad2009-10-21 00:40:46 +00004124TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004125 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004126 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4127}
4128
4129template<typename Derived>
4130QualType
4131TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4132 FunctionProtoTypeLoc TL,
4133 CXXRecordDecl *ThisContext,
4134 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004135 // Transform the parameters and return type.
4136 //
Richard Smithe6975e92012-04-17 00:58:00 +00004137 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004138 // When the function has a trailing return type, we instantiate the
4139 // parameters before the return type, since the return type can then refer
4140 // to the parameters themselves (via decltype, sizeof, etc.).
4141 //
Chris Lattner686775d2011-07-20 06:58:45 +00004142 SmallVector<QualType, 4> ParamTypes;
4143 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004144 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004145
Douglas Gregordab60ad2010-10-01 18:44:50 +00004146 QualType ResultType;
4147
Richard Smith9fbf3272012-08-14 22:51:13 +00004148 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004149 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004150 TL.getParmArray(),
4151 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004152 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004153 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004154 return QualType();
4155
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004156 {
4157 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004158 // If a declaration declares a member function or member function
4159 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004160 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004161 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004162 // declarator.
4163 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004164
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004165 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4166 if (ResultType.isNull())
4167 return QualType();
4168 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004169 }
4170 else {
4171 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4172 if (ResultType.isNull())
4173 return QualType();
4174
Chad Rosier4a9d7952012-08-08 18:46:20 +00004175 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004176 TL.getParmArray(),
4177 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004178 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004179 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004180 return QualType();
4181 }
4182
Richard Smithe6975e92012-04-17 00:58:00 +00004183 // FIXME: Need to transform the exception-specification too.
4184
John McCalla2becad2009-10-21 00:40:46 +00004185 QualType Result = TL.getType();
4186 if (getDerived().AlwaysRebuild() ||
4187 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004188 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004189 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4190 Result = getDerived().RebuildFunctionProtoType(ResultType,
4191 ParamTypes.data(),
4192 ParamTypes.size(),
4193 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004194 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004195 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004196 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004197 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004198 if (Result.isNull())
4199 return QualType();
4200 }
Mike Stump1eb44332009-09-09 15:08:12 +00004201
John McCalla2becad2009-10-21 00:40:46 +00004202 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004203 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004204 NewTL.setLParenLoc(TL.getLParenLoc());
4205 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004206 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004207 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4208 NewTL.setArg(i, ParamDecls[i]);
4209
4210 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004211}
Mike Stump1eb44332009-09-09 15:08:12 +00004212
Douglas Gregor577f75a2009-08-04 16:50:30 +00004213template<typename Derived>
4214QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004215 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004216 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004217 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004218 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4219 if (ResultType.isNull())
4220 return QualType();
4221
4222 QualType Result = TL.getType();
4223 if (getDerived().AlwaysRebuild() ||
4224 ResultType != T->getResultType())
4225 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4226
4227 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004228 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004229 NewTL.setLParenLoc(TL.getLParenLoc());
4230 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004231 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004232
4233 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004234}
Mike Stump1eb44332009-09-09 15:08:12 +00004235
John McCalled976492009-12-04 22:46:56 +00004236template<typename Derived> QualType
4237TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004238 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004239 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004240 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004241 if (!D)
4242 return QualType();
4243
4244 QualType Result = TL.getType();
4245 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4246 Result = getDerived().RebuildUnresolvedUsingType(D);
4247 if (Result.isNull())
4248 return QualType();
4249 }
4250
4251 // We might get an arbitrary type spec type back. We should at
4252 // least always get a type spec type, though.
4253 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4254 NewTL.setNameLoc(TL.getNameLoc());
4255
4256 return Result;
4257}
4258
Douglas Gregor577f75a2009-08-04 16:50:30 +00004259template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004260QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004261 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004262 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004263 TypedefNameDecl *Typedef
4264 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4265 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004266 if (!Typedef)
4267 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004268
John McCalla2becad2009-10-21 00:40:46 +00004269 QualType Result = TL.getType();
4270 if (getDerived().AlwaysRebuild() ||
4271 Typedef != T->getDecl()) {
4272 Result = getDerived().RebuildTypedefType(Typedef);
4273 if (Result.isNull())
4274 return QualType();
4275 }
Mike Stump1eb44332009-09-09 15:08:12 +00004276
John McCalla2becad2009-10-21 00:40:46 +00004277 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4278 NewTL.setNameLoc(TL.getNameLoc());
4279
4280 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004281}
Mike Stump1eb44332009-09-09 15:08:12 +00004282
Douglas Gregor577f75a2009-08-04 16:50:30 +00004283template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004284QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004285 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004286 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004287 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4288 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004289
John McCall60d7b3a2010-08-24 06:29:42 +00004290 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004291 if (E.isInvalid())
4292 return QualType();
4293
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004294 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4295 if (E.isInvalid())
4296 return QualType();
4297
John McCalla2becad2009-10-21 00:40:46 +00004298 QualType Result = TL.getType();
4299 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004300 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004301 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004302 if (Result.isNull())
4303 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004304 }
John McCalla2becad2009-10-21 00:40:46 +00004305 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004306
John McCalla2becad2009-10-21 00:40:46 +00004307 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004308 NewTL.setTypeofLoc(TL.getTypeofLoc());
4309 NewTL.setLParenLoc(TL.getLParenLoc());
4310 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004311
4312 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004313}
Mike Stump1eb44332009-09-09 15:08:12 +00004314
4315template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004316QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004317 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004318 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4319 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4320 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004321 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004322
John McCalla2becad2009-10-21 00:40:46 +00004323 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004324 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4325 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004326 if (Result.isNull())
4327 return QualType();
4328 }
Mike Stump1eb44332009-09-09 15:08:12 +00004329
John McCalla2becad2009-10-21 00:40:46 +00004330 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004331 NewTL.setTypeofLoc(TL.getTypeofLoc());
4332 NewTL.setLParenLoc(TL.getLParenLoc());
4333 NewTL.setRParenLoc(TL.getRParenLoc());
4334 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004335
4336 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004337}
Mike Stump1eb44332009-09-09 15:08:12 +00004338
4339template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004340QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004341 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004342 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004343
Douglas Gregor670444e2009-08-04 22:27:00 +00004344 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004345 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4346 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004347
John McCall60d7b3a2010-08-24 06:29:42 +00004348 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004349 if (E.isInvalid())
4350 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004351
Richard Smith76f3f692012-02-22 02:04:18 +00004352 E = getSema().ActOnDecltypeExpression(E.take());
4353 if (E.isInvalid())
4354 return QualType();
4355
John McCalla2becad2009-10-21 00:40:46 +00004356 QualType Result = TL.getType();
4357 if (getDerived().AlwaysRebuild() ||
4358 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004359 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004360 if (Result.isNull())
4361 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004362 }
John McCalla2becad2009-10-21 00:40:46 +00004363 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004364
John McCalla2becad2009-10-21 00:40:46 +00004365 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4366 NewTL.setNameLoc(TL.getNameLoc());
4367
4368 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004369}
4370
4371template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004372QualType TreeTransform<Derived>::TransformUnaryTransformType(
4373 TypeLocBuilder &TLB,
4374 UnaryTransformTypeLoc TL) {
4375 QualType Result = TL.getType();
4376 if (Result->isDependentType()) {
4377 const UnaryTransformType *T = TL.getTypePtr();
4378 QualType NewBase =
4379 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4380 Result = getDerived().RebuildUnaryTransformType(NewBase,
4381 T->getUTTKind(),
4382 TL.getKWLoc());
4383 if (Result.isNull())
4384 return QualType();
4385 }
4386
4387 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4388 NewTL.setKWLoc(TL.getKWLoc());
4389 NewTL.setParensRange(TL.getParensRange());
4390 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4391 return Result;
4392}
4393
4394template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004395QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4396 AutoTypeLoc TL) {
4397 const AutoType *T = TL.getTypePtr();
4398 QualType OldDeduced = T->getDeducedType();
4399 QualType NewDeduced;
4400 if (!OldDeduced.isNull()) {
4401 NewDeduced = getDerived().TransformType(OldDeduced);
4402 if (NewDeduced.isNull())
4403 return QualType();
4404 }
4405
4406 QualType Result = TL.getType();
4407 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4408 Result = getDerived().RebuildAutoType(NewDeduced);
4409 if (Result.isNull())
4410 return QualType();
4411 }
4412
4413 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4414 NewTL.setNameLoc(TL.getNameLoc());
4415
4416 return Result;
4417}
4418
4419template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004420QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004421 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004422 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004423 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004424 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4425 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004426 if (!Record)
4427 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004428
John McCalla2becad2009-10-21 00:40:46 +00004429 QualType Result = TL.getType();
4430 if (getDerived().AlwaysRebuild() ||
4431 Record != T->getDecl()) {
4432 Result = getDerived().RebuildRecordType(Record);
4433 if (Result.isNull())
4434 return QualType();
4435 }
Mike Stump1eb44332009-09-09 15:08:12 +00004436
John McCalla2becad2009-10-21 00:40:46 +00004437 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4438 NewTL.setNameLoc(TL.getNameLoc());
4439
4440 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004441}
Mike Stump1eb44332009-09-09 15:08:12 +00004442
4443template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004444QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004445 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004446 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004447 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004448 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4449 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004450 if (!Enum)
4451 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004452
John McCalla2becad2009-10-21 00:40:46 +00004453 QualType Result = TL.getType();
4454 if (getDerived().AlwaysRebuild() ||
4455 Enum != T->getDecl()) {
4456 Result = getDerived().RebuildEnumType(Enum);
4457 if (Result.isNull())
4458 return QualType();
4459 }
Mike Stump1eb44332009-09-09 15:08:12 +00004460
John McCalla2becad2009-10-21 00:40:46 +00004461 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4462 NewTL.setNameLoc(TL.getNameLoc());
4463
4464 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004465}
John McCall7da24312009-09-05 00:15:47 +00004466
John McCall3cb0ebd2010-03-10 03:28:59 +00004467template<typename Derived>
4468QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4469 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004470 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004471 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4472 TL.getTypePtr()->getDecl());
4473 if (!D) return QualType();
4474
4475 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4476 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4477 return T;
4478}
4479
Douglas Gregor577f75a2009-08-04 16:50:30 +00004480template<typename Derived>
4481QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004482 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004483 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004484 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004485}
4486
Mike Stump1eb44332009-09-09 15:08:12 +00004487template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004488QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004489 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004490 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004491 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004492
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004493 // Substitute into the replacement type, which itself might involve something
4494 // that needs to be transformed. This only tends to occur with default
4495 // template arguments of template template parameters.
4496 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4497 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4498 if (Replacement.isNull())
4499 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004500
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004501 // Always canonicalize the replacement type.
4502 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4503 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004504 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004505 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004506
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004507 // Propagate type-source information.
4508 SubstTemplateTypeParmTypeLoc NewTL
4509 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4510 NewTL.setNameLoc(TL.getNameLoc());
4511 return Result;
4512
John McCall49a832b2009-10-18 09:09:24 +00004513}
4514
4515template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004516QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4517 TypeLocBuilder &TLB,
4518 SubstTemplateTypeParmPackTypeLoc TL) {
4519 return TransformTypeSpecType(TLB, TL);
4520}
4521
4522template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004523QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004524 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004525 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004526 const TemplateSpecializationType *T = TL.getTypePtr();
4527
Douglas Gregor1d752d72011-03-02 18:46:51 +00004528 // The nested-name-specifier never matters in a TemplateSpecializationType,
4529 // because we can't have a dependent nested-name-specifier anyway.
4530 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004531 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004532 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4533 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004534 if (Template.isNull())
4535 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004536
John McCall43fed0d2010-11-12 08:19:04 +00004537 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4538}
4539
Eli Friedmanb001de72011-10-06 23:00:33 +00004540template<typename Derived>
4541QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4542 AtomicTypeLoc TL) {
4543 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4544 if (ValueType.isNull())
4545 return QualType();
4546
4547 QualType Result = TL.getType();
4548 if (getDerived().AlwaysRebuild() ||
4549 ValueType != TL.getValueLoc().getType()) {
4550 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4551 if (Result.isNull())
4552 return QualType();
4553 }
4554
4555 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4556 NewTL.setKWLoc(TL.getKWLoc());
4557 NewTL.setLParenLoc(TL.getLParenLoc());
4558 NewTL.setRParenLoc(TL.getRParenLoc());
4559
4560 return Result;
4561}
4562
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004563namespace {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004564 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004565 /// container that provides a \c getArgLoc() member function.
4566 ///
4567 /// This iterator is intended to be used with the iterator form of
4568 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4569 template<typename ArgLocContainer>
4570 class TemplateArgumentLocContainerIterator {
4571 ArgLocContainer *Container;
4572 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004573
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004574 public:
4575 typedef TemplateArgumentLoc value_type;
4576 typedef TemplateArgumentLoc reference;
4577 typedef int difference_type;
4578 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004579
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004580 class pointer {
4581 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004582
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004583 public:
4584 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004585
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004586 const TemplateArgumentLoc *operator->() const {
4587 return &Arg;
4588 }
4589 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004590
4591
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004592 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004593
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004594 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4595 unsigned Index)
4596 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004597
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004598 TemplateArgumentLocContainerIterator &operator++() {
4599 ++Index;
4600 return *this;
4601 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004602
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004603 TemplateArgumentLocContainerIterator operator++(int) {
4604 TemplateArgumentLocContainerIterator Old(*this);
4605 ++(*this);
4606 return Old;
4607 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004608
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004609 TemplateArgumentLoc operator*() const {
4610 return Container->getArgLoc(Index);
4611 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004612
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004613 pointer operator->() const {
4614 return pointer(Container->getArgLoc(Index));
4615 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004616
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004617 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004618 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004619 return X.Container == Y.Container && X.Index == Y.Index;
4620 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004621
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004622 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004623 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004624 return !(X == Y);
4625 }
4626 };
4627}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004628
4629
John McCall43fed0d2010-11-12 08:19:04 +00004630template <typename Derived>
4631QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4632 TypeLocBuilder &TLB,
4633 TemplateSpecializationTypeLoc TL,
4634 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004635 TemplateArgumentListInfo NewTemplateArgs;
4636 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4637 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004638 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4639 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004640 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004641 ArgIterator(TL, TL.getNumArgs()),
4642 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004643 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004644
John McCall833ca992009-10-29 08:12:44 +00004645 // FIXME: maybe don't rebuild if all the template arguments are the same.
4646
4647 QualType Result =
4648 getDerived().RebuildTemplateSpecializationType(Template,
4649 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004650 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004651
4652 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004653 // Specializations of template template parameters are represented as
4654 // TemplateSpecializationTypes, and substitution of type alias templates
4655 // within a dependent context can transform them into
4656 // DependentTemplateSpecializationTypes.
4657 if (isa<DependentTemplateSpecializationType>(Result)) {
4658 DependentTemplateSpecializationTypeLoc NewTL
4659 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004660 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004661 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004662 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004663 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004664 NewTL.setLAngleLoc(TL.getLAngleLoc());
4665 NewTL.setRAngleLoc(TL.getRAngleLoc());
4666 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4667 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4668 return Result;
4669 }
4670
John McCall833ca992009-10-29 08:12:44 +00004671 TemplateSpecializationTypeLoc NewTL
4672 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004673 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004674 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4675 NewTL.setLAngleLoc(TL.getLAngleLoc());
4676 NewTL.setRAngleLoc(TL.getRAngleLoc());
4677 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4678 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004679 }
Mike Stump1eb44332009-09-09 15:08:12 +00004680
John McCall833ca992009-10-29 08:12:44 +00004681 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004682}
Mike Stump1eb44332009-09-09 15:08:12 +00004683
Douglas Gregora88f09f2011-02-28 17:23:35 +00004684template <typename Derived>
4685QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4686 TypeLocBuilder &TLB,
4687 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004688 TemplateName Template,
4689 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004690 TemplateArgumentListInfo NewTemplateArgs;
4691 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4692 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4693 typedef TemplateArgumentLocContainerIterator<
4694 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004695 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004696 ArgIterator(TL, TL.getNumArgs()),
4697 NewTemplateArgs))
4698 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004699
Douglas Gregora88f09f2011-02-28 17:23:35 +00004700 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004701
Douglas Gregora88f09f2011-02-28 17:23:35 +00004702 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4703 QualType Result
4704 = getSema().Context.getDependentTemplateSpecializationType(
4705 TL.getTypePtr()->getKeyword(),
4706 DTN->getQualifier(),
4707 DTN->getIdentifier(),
4708 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004709
Douglas Gregora88f09f2011-02-28 17:23:35 +00004710 DependentTemplateSpecializationTypeLoc NewTL
4711 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004712 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004713 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004714 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004715 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +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 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004722
4723 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004724 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004725 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004726 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004727
Douglas Gregora88f09f2011-02-28 17:23:35 +00004728 if (!Result.isNull()) {
4729 /// FIXME: Wrap this in an elaborated-type-specifier?
4730 TemplateSpecializationTypeLoc NewTL
4731 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004732 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004733 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004734 NewTL.setLAngleLoc(TL.getLAngleLoc());
4735 NewTL.setRAngleLoc(TL.getRAngleLoc());
4736 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4737 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4738 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004739
Douglas Gregora88f09f2011-02-28 17:23:35 +00004740 return Result;
4741}
4742
Mike Stump1eb44332009-09-09 15:08:12 +00004743template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004744QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004745TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004746 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004747 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004748
Douglas Gregor9e876872011-03-01 18:12:44 +00004749 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004750 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004751 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004752 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004753 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4754 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004755 return QualType();
4756 }
Mike Stump1eb44332009-09-09 15:08:12 +00004757
John McCall43fed0d2010-11-12 08:19:04 +00004758 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4759 if (NamedT.isNull())
4760 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004761
Richard Smith3e4c6c42011-05-05 21:57:07 +00004762 // C++0x [dcl.type.elab]p2:
4763 // If the identifier resolves to a typedef-name or the simple-template-id
4764 // resolves to an alias template specialization, the
4765 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004766 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4767 if (const TemplateSpecializationType *TST =
4768 NamedT->getAs<TemplateSpecializationType>()) {
4769 TemplateName Template = TST->getTemplateName();
4770 if (TypeAliasTemplateDecl *TAT =
4771 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4772 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4773 diag::err_tag_reference_non_tag) << 4;
4774 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4775 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004776 }
4777 }
4778
John McCalla2becad2009-10-21 00:40:46 +00004779 QualType Result = TL.getType();
4780 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004781 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004782 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004783 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004784 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004785 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004786 if (Result.isNull())
4787 return QualType();
4788 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004789
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004790 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004791 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004792 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004793 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004794}
Mike Stump1eb44332009-09-09 15:08:12 +00004795
4796template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004797QualType TreeTransform<Derived>::TransformAttributedType(
4798 TypeLocBuilder &TLB,
4799 AttributedTypeLoc TL) {
4800 const AttributedType *oldType = TL.getTypePtr();
4801 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4802 if (modifiedType.isNull())
4803 return QualType();
4804
4805 QualType result = TL.getType();
4806
4807 // FIXME: dependent operand expressions?
4808 if (getDerived().AlwaysRebuild() ||
4809 modifiedType != oldType->getModifiedType()) {
4810 // TODO: this is really lame; we should really be rebuilding the
4811 // equivalent type from first principles.
4812 QualType equivalentType
4813 = getDerived().TransformType(oldType->getEquivalentType());
4814 if (equivalentType.isNull())
4815 return QualType();
4816 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4817 modifiedType,
4818 equivalentType);
4819 }
4820
4821 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4822 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4823 if (TL.hasAttrOperand())
4824 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4825 if (TL.hasAttrExprOperand())
4826 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4827 else if (TL.hasAttrEnumOperand())
4828 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4829
4830 return result;
4831}
4832
4833template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004834QualType
4835TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4836 ParenTypeLoc TL) {
4837 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4838 if (Inner.isNull())
4839 return QualType();
4840
4841 QualType Result = TL.getType();
4842 if (getDerived().AlwaysRebuild() ||
4843 Inner != TL.getInnerLoc().getType()) {
4844 Result = getDerived().RebuildParenType(Inner);
4845 if (Result.isNull())
4846 return QualType();
4847 }
4848
4849 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4850 NewTL.setLParenLoc(TL.getLParenLoc());
4851 NewTL.setRParenLoc(TL.getRParenLoc());
4852 return Result;
4853}
4854
4855template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004856QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004857 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004858 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004859
Douglas Gregor2494dd02011-03-01 01:34:45 +00004860 NestedNameSpecifierLoc QualifierLoc
4861 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4862 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004863 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004864
John McCall33500952010-06-11 00:33:02 +00004865 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004866 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004867 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004868 QualifierLoc,
4869 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004870 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004871 if (Result.isNull())
4872 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004873
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004874 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4875 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004876 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4877
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004878 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004879 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004880 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004881 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004882 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004883 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004884 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004885 NewTL.setNameLoc(TL.getNameLoc());
4886 }
John McCalla2becad2009-10-21 00:40:46 +00004887 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004888}
Mike Stump1eb44332009-09-09 15:08:12 +00004889
Douglas Gregor577f75a2009-08-04 16:50:30 +00004890template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004891QualType TreeTransform<Derived>::
4892 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004893 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004894 NestedNameSpecifierLoc QualifierLoc;
4895 if (TL.getQualifierLoc()) {
4896 QualifierLoc
4897 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4898 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004899 return QualType();
4900 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004901
John McCall43fed0d2010-11-12 08:19:04 +00004902 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004903 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004904}
4905
4906template<typename Derived>
4907QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004908TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4909 DependentTemplateSpecializationTypeLoc TL,
4910 NestedNameSpecifierLoc QualifierLoc) {
4911 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004912
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004913 TemplateArgumentListInfo NewTemplateArgs;
4914 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4915 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004916
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004917 typedef TemplateArgumentLocContainerIterator<
4918 DependentTemplateSpecializationTypeLoc> ArgIterator;
4919 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4920 ArgIterator(TL, TL.getNumArgs()),
4921 NewTemplateArgs))
4922 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004923
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004924 QualType Result
4925 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4926 QualifierLoc,
4927 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004928 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004929 NewTemplateArgs);
4930 if (Result.isNull())
4931 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004932
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004933 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4934 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004935
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004936 // Copy information relevant to the template specialization.
4937 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004938 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004939 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004940 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004941 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4942 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004943 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004944 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004945
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004946 // Copy information relevant to the elaborated type.
4947 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004948 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004949 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004950 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4951 DependentTemplateSpecializationTypeLoc SpecTL
4952 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004953 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004954 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004955 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004956 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004957 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4958 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004959 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004960 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004961 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004962 TemplateSpecializationTypeLoc SpecTL
4963 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004964 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004965 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004966 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4967 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004968 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004969 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004970 }
4971 return Result;
4972}
4973
4974template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004975QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4976 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004977 QualType Pattern
4978 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004979 if (Pattern.isNull())
4980 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004981
4982 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004983 if (getDerived().AlwaysRebuild() ||
4984 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004985 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004986 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004987 TL.getEllipsisLoc(),
4988 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004989 if (Result.isNull())
4990 return QualType();
4991 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004992
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004993 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4994 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4995 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004996}
4997
4998template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004999QualType
5000TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005001 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005002 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005003 TLB.pushFullCopy(TL);
5004 return TL.getType();
5005}
5006
5007template<typename Derived>
5008QualType
5009TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005010 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005011 // ObjCObjectType is never dependent.
5012 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005013 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005014}
Mike Stump1eb44332009-09-09 15:08:12 +00005015
5016template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005017QualType
5018TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005019 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005020 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005021 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005022 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005023}
5024
Douglas Gregor577f75a2009-08-04 16:50:30 +00005025//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005026// Statement transformation
5027//===----------------------------------------------------------------------===//
5028template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005029StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005030TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005031 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005032}
5033
5034template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005035StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005036TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5037 return getDerived().TransformCompoundStmt(S, false);
5038}
5039
5040template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005041StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005042TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005043 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005044 Sema::CompoundScopeRAII CompoundScope(getSema());
5045
John McCall7114cba2010-08-27 19:56:05 +00005046 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005047 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005048 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005049 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5050 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005051 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005052 if (Result.isInvalid()) {
5053 // Immediately fail if this was a DeclStmt, since it's very
5054 // likely that this will cause problems for future statements.
5055 if (isa<DeclStmt>(*B))
5056 return StmtError();
5057
5058 // Otherwise, just keep processing substatements and fail later.
5059 SubStmtInvalid = true;
5060 continue;
5061 }
Mike Stump1eb44332009-09-09 15:08:12 +00005062
Douglas Gregor43959a92009-08-20 07:17:43 +00005063 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5064 Statements.push_back(Result.takeAs<Stmt>());
5065 }
Mike Stump1eb44332009-09-09 15:08:12 +00005066
John McCall7114cba2010-08-27 19:56:05 +00005067 if (SubStmtInvalid)
5068 return StmtError();
5069
Douglas Gregor43959a92009-08-20 07:17:43 +00005070 if (!getDerived().AlwaysRebuild() &&
5071 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005072 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005073
5074 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005075 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005076 S->getRBracLoc(),
5077 IsStmtExpr);
5078}
Mike Stump1eb44332009-09-09 15:08:12 +00005079
Douglas Gregor43959a92009-08-20 07:17:43 +00005080template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005081StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005082TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005083 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005084 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005085 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5086 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005087
Eli Friedman264c1f82009-11-19 03:14:00 +00005088 // Transform the left-hand case value.
5089 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005090 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005091 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005092 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005093
Eli Friedman264c1f82009-11-19 03:14:00 +00005094 // Transform the right-hand case value (for the GNU case-range extension).
5095 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005096 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005097 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005098 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005099 }
Mike Stump1eb44332009-09-09 15:08:12 +00005100
Douglas Gregor43959a92009-08-20 07:17:43 +00005101 // Build the case statement.
5102 // Case statements are always rebuilt so that they will attached to their
5103 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005104 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005105 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005106 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005107 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005108 S->getColonLoc());
5109 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005110 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005111
Douglas Gregor43959a92009-08-20 07:17:43 +00005112 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005113 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005114 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005115 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005116
Douglas Gregor43959a92009-08-20 07:17:43 +00005117 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005118 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005119}
5120
5121template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005122StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005123TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005124 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005125 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005126 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005127 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005128
Douglas Gregor43959a92009-08-20 07:17:43 +00005129 // Default statements are always rebuilt
5130 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005131 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005132}
Mike Stump1eb44332009-09-09 15:08:12 +00005133
Douglas Gregor43959a92009-08-20 07:17:43 +00005134template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005135StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005136TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005137 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005138 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005139 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005140
Chris Lattner57ad3782011-02-17 20:34:02 +00005141 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5142 S->getDecl());
5143 if (!LD)
5144 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005145
5146
Douglas Gregor43959a92009-08-20 07:17:43 +00005147 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005148 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005149 cast<LabelDecl>(LD), SourceLocation(),
5150 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005151}
Mike Stump1eb44332009-09-09 15:08:12 +00005152
Douglas Gregor43959a92009-08-20 07:17:43 +00005153template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005154StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005155TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5156 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5157 if (SubStmt.isInvalid())
5158 return StmtError();
5159
5160 // TODO: transform attributes
5161 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5162 return S;
5163
5164 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5165 S->getAttrs(),
5166 SubStmt.get());
5167}
5168
5169template<typename Derived>
5170StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005171TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005172 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005173 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005174 VarDecl *ConditionVar = 0;
5175 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005176 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005177 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005178 getDerived().TransformDefinition(
5179 S->getConditionVariable()->getLocation(),
5180 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005181 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005182 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005183 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005184 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005185
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005186 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005187 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005188
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005189 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005190 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005191 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005192 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005193 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005194 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005195
John McCall9ae2f072010-08-23 23:25:46 +00005196 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005197 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005198 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005199
John McCall9ae2f072010-08-23 23:25:46 +00005200 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5201 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005202 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005203
Douglas Gregor43959a92009-08-20 07:17:43 +00005204 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005205 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005206 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005207 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005208
Douglas Gregor43959a92009-08-20 07:17:43 +00005209 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005210 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005211 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005212 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005213
Douglas Gregor43959a92009-08-20 07:17:43 +00005214 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005215 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005216 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005217 Then.get() == S->getThen() &&
5218 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005219 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005220
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005221 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005222 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005223 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005224}
5225
5226template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005227StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005228TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005229 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005230 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005231 VarDecl *ConditionVar = 0;
5232 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005233 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005234 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005235 getDerived().TransformDefinition(
5236 S->getConditionVariable()->getLocation(),
5237 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005238 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005239 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005240 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005241 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005242
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005243 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005244 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005245 }
Mike Stump1eb44332009-09-09 15:08:12 +00005246
Douglas Gregor43959a92009-08-20 07:17:43 +00005247 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005248 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005249 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005250 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005251 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005252 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005253
Douglas Gregor43959a92009-08-20 07:17:43 +00005254 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005255 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005256 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005257 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005258
Douglas Gregor43959a92009-08-20 07:17:43 +00005259 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005260 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5261 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005262}
Mike Stump1eb44332009-09-09 15:08:12 +00005263
Douglas Gregor43959a92009-08-20 07:17:43 +00005264template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005265StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005266TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005267 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005268 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005269 VarDecl *ConditionVar = 0;
5270 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005271 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005272 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005273 getDerived().TransformDefinition(
5274 S->getConditionVariable()->getLocation(),
5275 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005276 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005277 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005278 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005279 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005280
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005281 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005282 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005283
5284 if (S->getCond()) {
5285 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005286 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005287 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005288 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005289 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005290 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005291 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005292 }
Mike Stump1eb44332009-09-09 15:08:12 +00005293
John McCall9ae2f072010-08-23 23:25:46 +00005294 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5295 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005296 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005297
Douglas Gregor43959a92009-08-20 07:17:43 +00005298 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005299 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005300 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005301 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005302
Douglas Gregor43959a92009-08-20 07:17:43 +00005303 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005304 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005305 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005306 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005307 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005308
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005309 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005310 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005311}
Mike Stump1eb44332009-09-09 15:08:12 +00005312
Douglas Gregor43959a92009-08-20 07:17:43 +00005313template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005314StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005315TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005316 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005317 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005318 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005319 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005320
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005321 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005322 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005323 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005324 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005325
Douglas Gregor43959a92009-08-20 07:17:43 +00005326 if (!getDerived().AlwaysRebuild() &&
5327 Cond.get() == S->getCond() &&
5328 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005329 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005330
John McCall9ae2f072010-08-23 23:25:46 +00005331 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5332 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005333 S->getRParenLoc());
5334}
Mike Stump1eb44332009-09-09 15:08:12 +00005335
Douglas Gregor43959a92009-08-20 07:17:43 +00005336template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005337StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005338TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005339 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005340 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005341 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005342 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005343
Douglas Gregor43959a92009-08-20 07:17:43 +00005344 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005345 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005346 VarDecl *ConditionVar = 0;
5347 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005348 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005349 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005350 getDerived().TransformDefinition(
5351 S->getConditionVariable()->getLocation(),
5352 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005353 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005354 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005355 } else {
5356 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005357
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005358 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005359 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005360
5361 if (S->getCond()) {
5362 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005363 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005364 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005365 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005366 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005367
John McCall9ae2f072010-08-23 23:25:46 +00005368 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005369 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005370 }
Mike Stump1eb44332009-09-09 15:08:12 +00005371
Chad Rosier4a9d7952012-08-08 18:46:20 +00005372 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005373 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005374 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005375
Douglas Gregor43959a92009-08-20 07:17:43 +00005376 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005377 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005378 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005379 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005380
John McCall9ae2f072010-08-23 23:25:46 +00005381 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5382 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005383 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005384
Douglas Gregor43959a92009-08-20 07:17:43 +00005385 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005386 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005387 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005388 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005389
Douglas Gregor43959a92009-08-20 07:17:43 +00005390 if (!getDerived().AlwaysRebuild() &&
5391 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005392 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005393 Inc.get() == S->getInc() &&
5394 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005395 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005396
Douglas Gregor43959a92009-08-20 07:17:43 +00005397 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005398 Init.get(), FullCond, ConditionVar,
5399 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005400}
5401
5402template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005403StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005404TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005405 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5406 S->getLabel());
5407 if (!LD)
5408 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005409
Douglas Gregor43959a92009-08-20 07:17:43 +00005410 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005411 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005412 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005413}
5414
5415template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005416StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005417TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005418 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005419 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005420 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005421 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005422
Douglas Gregor43959a92009-08-20 07:17:43 +00005423 if (!getDerived().AlwaysRebuild() &&
5424 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005425 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005426
5427 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005428 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005429}
5430
5431template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005432StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005433TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005434 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005435}
Mike Stump1eb44332009-09-09 15:08:12 +00005436
Douglas Gregor43959a92009-08-20 07:17:43 +00005437template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005438StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005439TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005440 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005441}
Mike Stump1eb44332009-09-09 15:08:12 +00005442
Douglas Gregor43959a92009-08-20 07:17:43 +00005443template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005444StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005445TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005446 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005447 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005448 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005449
Mike Stump1eb44332009-09-09 15:08:12 +00005450 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005451 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005452 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005453}
Mike Stump1eb44332009-09-09 15:08:12 +00005454
Douglas Gregor43959a92009-08-20 07:17:43 +00005455template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005456StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005457TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005458 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005459 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005460 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5461 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005462 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5463 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005464 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005465 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005466
Douglas Gregor43959a92009-08-20 07:17:43 +00005467 if (Transformed != *D)
5468 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005469
Douglas Gregor43959a92009-08-20 07:17:43 +00005470 Decls.push_back(Transformed);
5471 }
Mike Stump1eb44332009-09-09 15:08:12 +00005472
Douglas Gregor43959a92009-08-20 07:17:43 +00005473 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005474 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005475
5476 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005477 S->getStartLoc(), S->getEndLoc());
5478}
Mike Stump1eb44332009-09-09 15:08:12 +00005479
Douglas Gregor43959a92009-08-20 07:17:43 +00005480template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005481StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005482TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005483
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005484 SmallVector<Expr*, 8> Constraints;
5485 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005486 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005487
John McCall60d7b3a2010-08-24 06:29:42 +00005488 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005489 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005490
5491 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005492
Anders Carlsson703e3942010-01-24 05:50:09 +00005493 // Go through the outputs.
5494 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005495 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005496
Anders Carlsson703e3942010-01-24 05:50:09 +00005497 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005498 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005499
Anders Carlsson703e3942010-01-24 05:50:09 +00005500 // Transform the output expr.
5501 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005502 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005503 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005504 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005505
Anders Carlsson703e3942010-01-24 05:50:09 +00005506 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005507
John McCall9ae2f072010-08-23 23:25:46 +00005508 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005509 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005510
Anders Carlsson703e3942010-01-24 05:50:09 +00005511 // Go through the inputs.
5512 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005513 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005514
Anders Carlsson703e3942010-01-24 05:50:09 +00005515 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005516 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005517
Anders Carlsson703e3942010-01-24 05:50:09 +00005518 // Transform the input expr.
5519 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005520 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005521 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005522 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005523
Anders Carlsson703e3942010-01-24 05:50:09 +00005524 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005525
John McCall9ae2f072010-08-23 23:25:46 +00005526 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005527 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005528
Anders Carlsson703e3942010-01-24 05:50:09 +00005529 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005530 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005531
5532 // Go through the clobbers.
5533 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005534 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005535
5536 // No need to transform the asm string literal.
5537 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005538 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5539 S->isVolatile(), S->getNumOutputs(),
5540 S->getNumInputs(), Names.data(),
5541 Constraints, Exprs, AsmString.get(),
5542 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005543}
5544
Chad Rosier8cd64b42012-06-11 20:47:18 +00005545template<typename Derived>
5546StmtResult
5547TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005548 ArrayRef<Token> AsmToks =
5549 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005550
Chad Rosier7bd092b2012-08-15 16:53:30 +00005551 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5552 AsmToks, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005553}
Douglas Gregor43959a92009-08-20 07:17:43 +00005554
5555template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005556StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005557TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005558 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005559 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005560 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005561 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005562
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005563 // Transform the @catch statements (if present).
5564 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005565 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005566 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005567 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005568 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005569 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005570 if (Catch.get() != S->getCatchStmt(I))
5571 AnyCatchChanged = true;
5572 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005573 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005574
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005575 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005576 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005577 if (S->getFinallyStmt()) {
5578 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5579 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005580 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005581 }
5582
5583 // If nothing changed, just retain this statement.
5584 if (!getDerived().AlwaysRebuild() &&
5585 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005586 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005587 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005588 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005589
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005590 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005591 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005592 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005593}
Mike Stump1eb44332009-09-09 15:08:12 +00005594
Douglas Gregor43959a92009-08-20 07:17:43 +00005595template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005596StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005597TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005598 // Transform the @catch parameter, if there is one.
5599 VarDecl *Var = 0;
5600 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5601 TypeSourceInfo *TSInfo = 0;
5602 if (FromVar->getTypeSourceInfo()) {
5603 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5604 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005605 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005606 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005607
Douglas Gregorbe270a02010-04-26 17:57:08 +00005608 QualType T;
5609 if (TSInfo)
5610 T = TSInfo->getType();
5611 else {
5612 T = getDerived().TransformType(FromVar->getType());
5613 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005614 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005615 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005616
Douglas Gregorbe270a02010-04-26 17:57:08 +00005617 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5618 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005619 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005620 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005621
John McCall60d7b3a2010-08-24 06:29:42 +00005622 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005623 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005624 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005625
5626 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005627 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005628 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005629}
Mike Stump1eb44332009-09-09 15:08:12 +00005630
Douglas Gregor43959a92009-08-20 07:17:43 +00005631template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005632StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005633TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005634 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005635 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005636 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005637 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005638
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005639 // If nothing changed, just retain this statement.
5640 if (!getDerived().AlwaysRebuild() &&
5641 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005642 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005643
5644 // Build a new statement.
5645 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005646 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005647}
Mike Stump1eb44332009-09-09 15:08:12 +00005648
Douglas Gregor43959a92009-08-20 07:17:43 +00005649template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005650StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005651TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005652 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005653 if (S->getThrowExpr()) {
5654 Operand = getDerived().TransformExpr(S->getThrowExpr());
5655 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005656 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005657 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005658
Douglas Gregord1377b22010-04-22 21:44:01 +00005659 if (!getDerived().AlwaysRebuild() &&
5660 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005661 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005662
John McCall9ae2f072010-08-23 23:25:46 +00005663 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005664}
Mike Stump1eb44332009-09-09 15:08:12 +00005665
Douglas Gregor43959a92009-08-20 07:17:43 +00005666template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005667StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005668TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005669 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005670 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005671 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005672 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005673 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005674 Object =
5675 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5676 Object.get());
5677 if (Object.isInvalid())
5678 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005679
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005680 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005681 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005682 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005683 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005684
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005685 // If nothing change, just retain the current statement.
5686 if (!getDerived().AlwaysRebuild() &&
5687 Object.get() == S->getSynchExpr() &&
5688 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005689 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005690
5691 // Build a new statement.
5692 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005693 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005694}
5695
5696template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005697StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005698TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5699 ObjCAutoreleasePoolStmt *S) {
5700 // Transform the body.
5701 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5702 if (Body.isInvalid())
5703 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005704
John McCallf85e1932011-06-15 23:02:42 +00005705 // If nothing changed, just retain this statement.
5706 if (!getDerived().AlwaysRebuild() &&
5707 Body.get() == S->getSubStmt())
5708 return SemaRef.Owned(S);
5709
5710 // Build a new statement.
5711 return getDerived().RebuildObjCAutoreleasePoolStmt(
5712 S->getAtLoc(), Body.get());
5713}
5714
5715template<typename Derived>
5716StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005717TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005718 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005719 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005720 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005721 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005722 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005723
Douglas Gregorc3203e72010-04-22 23:10:45 +00005724 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005725 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005726 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005727 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005728
Douglas Gregorc3203e72010-04-22 23:10:45 +00005729 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005730 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005731 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005732 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005733
Douglas Gregorc3203e72010-04-22 23:10:45 +00005734 // If nothing changed, just retain this statement.
5735 if (!getDerived().AlwaysRebuild() &&
5736 Element.get() == S->getElement() &&
5737 Collection.get() == S->getCollection() &&
5738 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005739 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005740
Douglas Gregorc3203e72010-04-22 23:10:45 +00005741 // Build a new statement.
5742 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005743 Element.get(),
5744 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005745 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005746 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005747}
5748
5749
5750template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005751StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005752TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5753 // Transform the exception declaration, if any.
5754 VarDecl *Var = 0;
5755 if (S->getExceptionDecl()) {
5756 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005757 TypeSourceInfo *T = getDerived().TransformType(
5758 ExceptionDecl->getTypeSourceInfo());
5759 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005760 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005761
Douglas Gregor83cb9422010-09-09 17:09:21 +00005762 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005763 ExceptionDecl->getInnerLocStart(),
5764 ExceptionDecl->getLocation(),
5765 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005766 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005767 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005768 }
Mike Stump1eb44332009-09-09 15:08:12 +00005769
Douglas Gregor43959a92009-08-20 07:17:43 +00005770 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005771 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005772 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005773 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005774
Douglas Gregor43959a92009-08-20 07:17:43 +00005775 if (!getDerived().AlwaysRebuild() &&
5776 !Var &&
5777 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005778 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005779
5780 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5781 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005782 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005783}
Mike Stump1eb44332009-09-09 15:08:12 +00005784
Douglas Gregor43959a92009-08-20 07:17:43 +00005785template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005786StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005787TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5788 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005789 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005790 = getDerived().TransformCompoundStmt(S->getTryBlock());
5791 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005792 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005793
Douglas Gregor43959a92009-08-20 07:17:43 +00005794 // Transform the handlers.
5795 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005796 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005797 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005798 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005799 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5800 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005801 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005802
Douglas Gregor43959a92009-08-20 07:17:43 +00005803 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5804 Handlers.push_back(Handler.takeAs<Stmt>());
5805 }
Mike Stump1eb44332009-09-09 15:08:12 +00005806
Douglas Gregor43959a92009-08-20 07:17:43 +00005807 if (!getDerived().AlwaysRebuild() &&
5808 TryBlock.get() == S->getTryBlock() &&
5809 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005810 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005811
John McCall9ae2f072010-08-23 23:25:46 +00005812 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005813 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005814}
Mike Stump1eb44332009-09-09 15:08:12 +00005815
Richard Smithad762fc2011-04-14 22:09:26 +00005816template<typename Derived>
5817StmtResult
5818TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5819 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5820 if (Range.isInvalid())
5821 return StmtError();
5822
5823 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5824 if (BeginEnd.isInvalid())
5825 return StmtError();
5826
5827 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5828 if (Cond.isInvalid())
5829 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005830 if (Cond.get())
5831 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5832 if (Cond.isInvalid())
5833 return StmtError();
5834 if (Cond.get())
5835 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005836
5837 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5838 if (Inc.isInvalid())
5839 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005840 if (Inc.get())
5841 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005842
5843 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5844 if (LoopVar.isInvalid())
5845 return StmtError();
5846
5847 StmtResult NewStmt = S;
5848 if (getDerived().AlwaysRebuild() ||
5849 Range.get() != S->getRangeStmt() ||
5850 BeginEnd.get() != S->getBeginEndStmt() ||
5851 Cond.get() != S->getCond() ||
5852 Inc.get() != S->getInc() ||
5853 LoopVar.get() != S->getLoopVarStmt())
5854 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5855 S->getColonLoc(), Range.get(),
5856 BeginEnd.get(), Cond.get(),
5857 Inc.get(), LoopVar.get(),
5858 S->getRParenLoc());
5859
5860 StmtResult Body = getDerived().TransformStmt(S->getBody());
5861 if (Body.isInvalid())
5862 return StmtError();
5863
5864 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5865 // it now so we have a new statement to attach the body to.
5866 if (Body.get() != S->getBody() && NewStmt.get() == S)
5867 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5868 S->getColonLoc(), Range.get(),
5869 BeginEnd.get(), Cond.get(),
5870 Inc.get(), LoopVar.get(),
5871 S->getRParenLoc());
5872
5873 if (NewStmt.get() == S)
5874 return SemaRef.Owned(S);
5875
5876 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5877}
5878
John Wiegley28bbe4b2011-04-28 01:08:34 +00005879template<typename Derived>
5880StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005881TreeTransform<Derived>::TransformMSDependentExistsStmt(
5882 MSDependentExistsStmt *S) {
5883 // Transform the nested-name-specifier, if any.
5884 NestedNameSpecifierLoc QualifierLoc;
5885 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005886 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005887 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5888 if (!QualifierLoc)
5889 return StmtError();
5890 }
5891
5892 // Transform the declaration name.
5893 DeclarationNameInfo NameInfo = S->getNameInfo();
5894 if (NameInfo.getName()) {
5895 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5896 if (!NameInfo.getName())
5897 return StmtError();
5898 }
5899
5900 // Check whether anything changed.
5901 if (!getDerived().AlwaysRebuild() &&
5902 QualifierLoc == S->getQualifierLoc() &&
5903 NameInfo.getName() == S->getNameInfo().getName())
5904 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005905
Douglas Gregorba0513d2011-10-25 01:33:02 +00005906 // Determine whether this name exists, if we can.
5907 CXXScopeSpec SS;
5908 SS.Adopt(QualifierLoc);
5909 bool Dependent = false;
5910 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5911 case Sema::IER_Exists:
5912 if (S->isIfExists())
5913 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005914
Douglas Gregorba0513d2011-10-25 01:33:02 +00005915 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5916
5917 case Sema::IER_DoesNotExist:
5918 if (S->isIfNotExists())
5919 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005920
Douglas Gregorba0513d2011-10-25 01:33:02 +00005921 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005922
Douglas Gregorba0513d2011-10-25 01:33:02 +00005923 case Sema::IER_Dependent:
5924 Dependent = true;
5925 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005926
Douglas Gregor65019ac2011-10-25 03:44:56 +00005927 case Sema::IER_Error:
5928 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005929 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005930
Douglas Gregorba0513d2011-10-25 01:33:02 +00005931 // We need to continue with the instantiation, so do so now.
5932 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5933 if (SubStmt.isInvalid())
5934 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005935
Douglas Gregorba0513d2011-10-25 01:33:02 +00005936 // If we have resolved the name, just transform to the substatement.
5937 if (!Dependent)
5938 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005939
Douglas Gregorba0513d2011-10-25 01:33:02 +00005940 // The name is still dependent, so build a dependent expression again.
5941 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5942 S->isIfExists(),
5943 QualifierLoc,
5944 NameInfo,
5945 SubStmt.get());
5946}
5947
5948template<typename Derived>
5949StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00005950TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5951 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5952 if(TryBlock.isInvalid()) return StmtError();
5953
5954 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5955 if(!getDerived().AlwaysRebuild() &&
5956 TryBlock.get() == S->getTryBlock() &&
5957 Handler.get() == S->getHandler())
5958 return SemaRef.Owned(S);
5959
5960 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5961 S->getTryLoc(),
5962 TryBlock.take(),
5963 Handler.take());
5964}
5965
5966template<typename Derived>
5967StmtResult
5968TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5969 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5970 if(Block.isInvalid()) return StmtError();
5971
5972 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5973 Block.take());
5974}
5975
5976template<typename Derived>
5977StmtResult
5978TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5979 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5980 if(FilterExpr.isInvalid()) return StmtError();
5981
5982 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5983 if(Block.isInvalid()) return StmtError();
5984
5985 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5986 FilterExpr.take(),
5987 Block.take());
5988}
5989
5990template<typename Derived>
5991StmtResult
5992TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5993 if(isa<SEHFinallyStmt>(Handler))
5994 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5995 else
5996 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5997}
5998
Douglas Gregor43959a92009-08-20 07:17:43 +00005999//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006000// Expression transformation
6001//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006002template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006003ExprResult
John McCall454feb92009-12-08 09:21:05 +00006004TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006005 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006006}
Mike Stump1eb44332009-09-09 15:08:12 +00006007
6008template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006009ExprResult
John McCall454feb92009-12-08 09:21:05 +00006010TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006011 NestedNameSpecifierLoc QualifierLoc;
6012 if (E->getQualifierLoc()) {
6013 QualifierLoc
6014 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6015 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006016 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006017 }
John McCalldbd872f2009-12-08 09:08:17 +00006018
6019 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006020 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6021 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006022 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006023 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006024
John McCallec8045d2010-08-17 21:27:17 +00006025 DeclarationNameInfo NameInfo = E->getNameInfo();
6026 if (NameInfo.getName()) {
6027 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6028 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006029 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006030 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006031
6032 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006033 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006034 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006035 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006036 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006037
6038 // Mark it referenced in the new context regardless.
6039 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006040 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006041
John McCall3fa5cae2010-10-26 07:05:15 +00006042 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006043 }
John McCalldbd872f2009-12-08 09:08:17 +00006044
6045 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006046 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006047 TemplateArgs = &TransArgs;
6048 TransArgs.setLAngleLoc(E->getLAngleLoc());
6049 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006050 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6051 E->getNumTemplateArgs(),
6052 TransArgs))
6053 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006054 }
6055
Chad Rosier4a9d7952012-08-08 18:46:20 +00006056 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006057 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006058}
Mike Stump1eb44332009-09-09 15:08:12 +00006059
Douglas Gregorb98b1992009-08-11 05:31:07 +00006060template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006061ExprResult
John McCall454feb92009-12-08 09:21:05 +00006062TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006063 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006064}
Mike Stump1eb44332009-09-09 15:08:12 +00006065
Douglas Gregorb98b1992009-08-11 05:31:07 +00006066template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006067ExprResult
John McCall454feb92009-12-08 09:21:05 +00006068TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006069 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006070}
Mike Stump1eb44332009-09-09 15:08:12 +00006071
Douglas Gregorb98b1992009-08-11 05:31:07 +00006072template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006073ExprResult
John McCall454feb92009-12-08 09:21:05 +00006074TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006075 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006076}
Mike Stump1eb44332009-09-09 15:08:12 +00006077
Douglas Gregorb98b1992009-08-11 05:31:07 +00006078template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006079ExprResult
John McCall454feb92009-12-08 09:21:05 +00006080TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006081 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006082}
Mike Stump1eb44332009-09-09 15:08:12 +00006083
Douglas Gregorb98b1992009-08-11 05:31:07 +00006084template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006085ExprResult
John McCall454feb92009-12-08 09:21:05 +00006086TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006087 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006088}
6089
6090template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006091ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006092TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6093 return SemaRef.MaybeBindToTemporary(E);
6094}
6095
6096template<typename Derived>
6097ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006098TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6099 ExprResult ControllingExpr =
6100 getDerived().TransformExpr(E->getControllingExpr());
6101 if (ControllingExpr.isInvalid())
6102 return ExprError();
6103
Chris Lattner686775d2011-07-20 06:58:45 +00006104 SmallVector<Expr *, 4> AssocExprs;
6105 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006106 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6107 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6108 if (TS) {
6109 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6110 if (!AssocType)
6111 return ExprError();
6112 AssocTypes.push_back(AssocType);
6113 } else {
6114 AssocTypes.push_back(0);
6115 }
6116
6117 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6118 if (AssocExpr.isInvalid())
6119 return ExprError();
6120 AssocExprs.push_back(AssocExpr.release());
6121 }
6122
6123 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6124 E->getDefaultLoc(),
6125 E->getRParenLoc(),
6126 ControllingExpr.release(),
6127 AssocTypes.data(),
6128 AssocExprs.data(),
6129 E->getNumAssocs());
6130}
6131
6132template<typename Derived>
6133ExprResult
John McCall454feb92009-12-08 09:21:05 +00006134TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006135 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006136 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006137 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006138
Douglas Gregorb98b1992009-08-11 05:31:07 +00006139 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006140 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006141
John McCall9ae2f072010-08-23 23:25:46 +00006142 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006143 E->getRParen());
6144}
6145
Mike Stump1eb44332009-09-09 15:08:12 +00006146template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006147ExprResult
John McCall454feb92009-12-08 09:21:05 +00006148TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smith80ddc312012-10-19 06:32:17 +00006149 ExprResult SubExpr;
6150
6151 if (DependentScopeDeclRefExpr *DRE =
6152 dyn_cast<DependentScopeDeclRefExpr>(E->getSubExpr()))
6153 SubExpr = getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6154 else
6155 SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006156 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006157 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006158
Douglas Gregorb98b1992009-08-11 05:31:07 +00006159 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006160 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006161
Douglas Gregorb98b1992009-08-11 05:31:07 +00006162 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6163 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006164 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006165}
Mike Stump1eb44332009-09-09 15:08:12 +00006166
Douglas Gregorb98b1992009-08-11 05:31:07 +00006167template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006168ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006169TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6170 // Transform the type.
6171 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6172 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006173 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006174
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006175 // Transform all of the components into components similar to what the
6176 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006177 // FIXME: It would be slightly more efficient in the non-dependent case to
6178 // just map FieldDecls, rather than requiring the rebuilder to look for
6179 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006180 // template code that we don't care.
6181 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006182 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006183 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006184 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006185 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6186 const Node &ON = E->getComponent(I);
6187 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006188 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006189 Comp.LocStart = ON.getSourceRange().getBegin();
6190 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006191 switch (ON.getKind()) {
6192 case Node::Array: {
6193 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006194 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006195 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006196 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006197
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006198 ExprChanged = ExprChanged || Index.get() != FromIndex;
6199 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006200 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006201 break;
6202 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006203
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006204 case Node::Field:
6205 case Node::Identifier:
6206 Comp.isBrackets = false;
6207 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006208 if (!Comp.U.IdentInfo)
6209 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006210
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006211 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006212
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006213 case Node::Base:
6214 // Will be recomputed during the rebuild.
6215 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006216 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006217
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006218 Components.push_back(Comp);
6219 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006220
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006221 // If nothing changed, retain the existing expression.
6222 if (!getDerived().AlwaysRebuild() &&
6223 Type == E->getTypeSourceInfo() &&
6224 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006225 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006226
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006227 // Build a new offsetof expression.
6228 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6229 Components.data(), Components.size(),
6230 E->getRParenLoc());
6231}
6232
6233template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006234ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006235TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6236 assert(getDerived().AlreadyTransformed(E->getType()) &&
6237 "opaque value expression requires transformation");
6238 return SemaRef.Owned(E);
6239}
6240
6241template<typename Derived>
6242ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006243TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006244 // Rebuild the syntactic form. The original syntactic form has
6245 // opaque-value expressions in it, so strip those away and rebuild
6246 // the result. This is a really awful way of doing this, but the
6247 // better solution (rebuilding the semantic expressions and
6248 // rebinding OVEs as necessary) doesn't work; we'd need
6249 // TreeTransform to not strip away implicit conversions.
6250 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6251 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006252 if (result.isInvalid()) return ExprError();
6253
6254 // If that gives us a pseudo-object result back, the pseudo-object
6255 // expression must have been an lvalue-to-rvalue conversion which we
6256 // should reapply.
6257 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6258 result = SemaRef.checkPseudoObjectRValue(result.take());
6259
6260 return result;
6261}
6262
6263template<typename Derived>
6264ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006265TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6266 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006267 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006268 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006269
John McCalla93c9342009-12-07 02:54:59 +00006270 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006271 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006272 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006273
John McCall5ab75172009-11-04 07:28:41 +00006274 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006275 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006276
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006277 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6278 E->getKind(),
6279 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006280 }
Mike Stump1eb44332009-09-09 15:08:12 +00006281
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006282 // C++0x [expr.sizeof]p1:
6283 // The operand is either an expression, which is an unevaluated operand
6284 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006285 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6286 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006287
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006288 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6289 if (SubExpr.isInvalid())
6290 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006291
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006292 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6293 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006294
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006295 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6296 E->getOperatorLoc(),
6297 E->getKind(),
6298 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006299}
Mike Stump1eb44332009-09-09 15:08:12 +00006300
Douglas Gregorb98b1992009-08-11 05:31:07 +00006301template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006302ExprResult
John McCall454feb92009-12-08 09:21:05 +00006303TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006304 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006305 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006306 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006307
John McCall60d7b3a2010-08-24 06:29:42 +00006308 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006309 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006310 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006311
6312
Douglas Gregorb98b1992009-08-11 05:31:07 +00006313 if (!getDerived().AlwaysRebuild() &&
6314 LHS.get() == E->getLHS() &&
6315 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006316 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006317
John McCall9ae2f072010-08-23 23:25:46 +00006318 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006319 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006320 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006321 E->getRBracketLoc());
6322}
Mike Stump1eb44332009-09-09 15:08:12 +00006323
6324template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006325ExprResult
John McCall454feb92009-12-08 09:21:05 +00006326TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006327 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006328 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006329 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006330 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006331
6332 // Transform arguments.
6333 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006334 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006335 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006336 &ArgChanged))
6337 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006338
Douglas Gregorb98b1992009-08-11 05:31:07 +00006339 if (!getDerived().AlwaysRebuild() &&
6340 Callee.get() == E->getCallee() &&
6341 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006342 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006343
Douglas Gregorb98b1992009-08-11 05:31:07 +00006344 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006345 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006346 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006347 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006348 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006349 E->getRParenLoc());
6350}
Mike Stump1eb44332009-09-09 15:08:12 +00006351
6352template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006353ExprResult
John McCall454feb92009-12-08 09:21:05 +00006354TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006355 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006356 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006357 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006358
Douglas Gregor40d96a62011-02-28 21:54:11 +00006359 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006360 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006361 QualifierLoc
6362 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006363
Douglas Gregor40d96a62011-02-28 21:54:11 +00006364 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006365 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006366 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006367 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006368
Eli Friedmanf595cc42009-12-04 06:40:45 +00006369 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006370 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6371 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006372 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006373 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006374
John McCall6bb80172010-03-30 21:47:33 +00006375 NamedDecl *FoundDecl = E->getFoundDecl();
6376 if (FoundDecl == E->getMemberDecl()) {
6377 FoundDecl = Member;
6378 } else {
6379 FoundDecl = cast_or_null<NamedDecl>(
6380 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6381 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006382 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006383 }
6384
Douglas Gregorb98b1992009-08-11 05:31:07 +00006385 if (!getDerived().AlwaysRebuild() &&
6386 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006387 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006388 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006389 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006390 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006391
Anders Carlsson1f240322009-12-22 05:24:09 +00006392 // Mark it referenced in the new context regardless.
6393 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006394 SemaRef.MarkMemberReferenced(E);
6395
John McCall3fa5cae2010-10-26 07:05:15 +00006396 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006397 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006398
John McCalld5532b62009-11-23 01:53:49 +00006399 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006400 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006401 TransArgs.setLAngleLoc(E->getLAngleLoc());
6402 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006403 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6404 E->getNumTemplateArgs(),
6405 TransArgs))
6406 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006407 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006408
Douglas Gregorb98b1992009-08-11 05:31:07 +00006409 // FIXME: Bogus source location for the operator
6410 SourceLocation FakeOperatorLoc
6411 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6412
John McCallc2233c52010-01-15 08:34:02 +00006413 // FIXME: to do this check properly, we will need to preserve the
6414 // first-qualifier-in-scope here, just in case we had a dependent
6415 // base (and therefore couldn't do the check) and a
6416 // nested-name-qualifier (and therefore could do the lookup).
6417 NamedDecl *FirstQualifierInScope = 0;
6418
John McCall9ae2f072010-08-23 23:25:46 +00006419 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006420 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006421 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006422 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006423 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006424 Member,
John McCall6bb80172010-03-30 21:47:33 +00006425 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006426 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006427 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006428 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006429}
Mike Stump1eb44332009-09-09 15:08:12 +00006430
Douglas Gregorb98b1992009-08-11 05:31:07 +00006431template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006432ExprResult
John McCall454feb92009-12-08 09:21:05 +00006433TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006434 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006435 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006436 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006437
John McCall60d7b3a2010-08-24 06:29:42 +00006438 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006439 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006440 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006441
Douglas Gregorb98b1992009-08-11 05:31:07 +00006442 if (!getDerived().AlwaysRebuild() &&
6443 LHS.get() == E->getLHS() &&
6444 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006445 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006446
Lang Hamesbe9af122012-10-02 04:45:10 +00006447 Sema::FPContractStateRAII FPContractState(getSema());
6448 getSema().FPFeatures.fp_contract = E->isFPContractable();
6449
Douglas Gregorb98b1992009-08-11 05:31:07 +00006450 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006451 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006452}
6453
Mike Stump1eb44332009-09-09 15:08:12 +00006454template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006455ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006456TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006457 CompoundAssignOperator *E) {
6458 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006459}
Mike Stump1eb44332009-09-09 15:08:12 +00006460
Douglas Gregorb98b1992009-08-11 05:31:07 +00006461template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006462ExprResult TreeTransform<Derived>::
6463TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6464 // Just rebuild the common and RHS expressions and see whether we
6465 // get any changes.
6466
6467 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6468 if (commonExpr.isInvalid())
6469 return ExprError();
6470
6471 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6472 if (rhs.isInvalid())
6473 return ExprError();
6474
6475 if (!getDerived().AlwaysRebuild() &&
6476 commonExpr.get() == e->getCommon() &&
6477 rhs.get() == e->getFalseExpr())
6478 return SemaRef.Owned(e);
6479
6480 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6481 e->getQuestionLoc(),
6482 0,
6483 e->getColonLoc(),
6484 rhs.get());
6485}
6486
6487template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006488ExprResult
John McCall454feb92009-12-08 09:21:05 +00006489TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006490 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006491 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006492 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006493
John McCall60d7b3a2010-08-24 06:29:42 +00006494 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006495 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006496 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006497
John McCall60d7b3a2010-08-24 06:29:42 +00006498 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006499 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006500 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006501
Douglas Gregorb98b1992009-08-11 05:31:07 +00006502 if (!getDerived().AlwaysRebuild() &&
6503 Cond.get() == E->getCond() &&
6504 LHS.get() == E->getLHS() &&
6505 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006506 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006507
John McCall9ae2f072010-08-23 23:25:46 +00006508 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006509 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006510 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006511 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006512 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006513}
Mike Stump1eb44332009-09-09 15:08:12 +00006514
6515template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006516ExprResult
John McCall454feb92009-12-08 09:21:05 +00006517TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006518 // Implicit casts are eliminated during transformation, since they
6519 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006520 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006521}
Mike Stump1eb44332009-09-09 15:08:12 +00006522
Douglas Gregorb98b1992009-08-11 05:31:07 +00006523template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006524ExprResult
John McCall454feb92009-12-08 09:21:05 +00006525TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006526 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6527 if (!Type)
6528 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006529
John McCall60d7b3a2010-08-24 06:29:42 +00006530 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006531 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006532 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006533 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006534
Douglas Gregorb98b1992009-08-11 05:31:07 +00006535 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006536 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006537 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006538 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006539
John McCall9d125032010-01-15 18:39:57 +00006540 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006541 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006542 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006543 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006544}
Mike Stump1eb44332009-09-09 15:08:12 +00006545
Douglas Gregorb98b1992009-08-11 05:31:07 +00006546template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006547ExprResult
John McCall454feb92009-12-08 09:21:05 +00006548TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006549 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6550 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6551 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006552 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006553
John McCall60d7b3a2010-08-24 06:29:42 +00006554 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006555 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006556 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006557
Douglas Gregorb98b1992009-08-11 05:31:07 +00006558 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006559 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006560 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006561 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006562
John McCall1d7d8d62010-01-19 22:33:45 +00006563 // Note: the expression type doesn't necessarily match the
6564 // type-as-written, but that's okay, because it should always be
6565 // derivable from the initializer.
6566
John McCall42f56b52010-01-18 19:35:47 +00006567 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006568 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006569 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006570}
Mike Stump1eb44332009-09-09 15:08:12 +00006571
Douglas Gregorb98b1992009-08-11 05:31:07 +00006572template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006573ExprResult
John McCall454feb92009-12-08 09:21:05 +00006574TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006575 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006576 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006577 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006578
Douglas Gregorb98b1992009-08-11 05:31:07 +00006579 if (!getDerived().AlwaysRebuild() &&
6580 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006581 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006582
Douglas Gregorb98b1992009-08-11 05:31:07 +00006583 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006584 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006585 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006586 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006587 E->getAccessorLoc(),
6588 E->getAccessor());
6589}
Mike Stump1eb44332009-09-09 15:08:12 +00006590
Douglas Gregorb98b1992009-08-11 05:31:07 +00006591template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006592ExprResult
John McCall454feb92009-12-08 09:21:05 +00006593TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006594 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006595
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006596 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006597 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006598 Inits, &InitChanged))
6599 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006600
Douglas Gregorb98b1992009-08-11 05:31:07 +00006601 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006602 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006603
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006604 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006605 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006606}
Mike Stump1eb44332009-09-09 15:08:12 +00006607
Douglas Gregorb98b1992009-08-11 05:31:07 +00006608template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006609ExprResult
John McCall454feb92009-12-08 09:21:05 +00006610TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006611 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006612
Douglas Gregor43959a92009-08-20 07:17:43 +00006613 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006614 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006615 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006616 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006617
Douglas Gregor43959a92009-08-20 07:17:43 +00006618 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006619 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006620 bool ExprChanged = false;
6621 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6622 DEnd = E->designators_end();
6623 D != DEnd; ++D) {
6624 if (D->isFieldDesignator()) {
6625 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6626 D->getDotLoc(),
6627 D->getFieldLoc()));
6628 continue;
6629 }
Mike Stump1eb44332009-09-09 15:08:12 +00006630
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006632 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006634 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006635
6636 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006637 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006638
Douglas Gregorb98b1992009-08-11 05:31:07 +00006639 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6640 ArrayExprs.push_back(Index.release());
6641 continue;
6642 }
Mike Stump1eb44332009-09-09 15:08:12 +00006643
Douglas Gregorb98b1992009-08-11 05:31:07 +00006644 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006645 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6647 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006648 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006649
John McCall60d7b3a2010-08-24 06:29:42 +00006650 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006651 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006652 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006653
6654 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006655 End.get(),
6656 D->getLBracketLoc(),
6657 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006658
Douglas Gregorb98b1992009-08-11 05:31:07 +00006659 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6660 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006661
Douglas Gregorb98b1992009-08-11 05:31:07 +00006662 ArrayExprs.push_back(Start.release());
6663 ArrayExprs.push_back(End.release());
6664 }
Mike Stump1eb44332009-09-09 15:08:12 +00006665
Douglas Gregorb98b1992009-08-11 05:31:07 +00006666 if (!getDerived().AlwaysRebuild() &&
6667 Init.get() == E->getInit() &&
6668 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006669 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006670
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006671 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006672 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006673 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674}
Mike Stump1eb44332009-09-09 15:08:12 +00006675
Douglas Gregorb98b1992009-08-11 05:31:07 +00006676template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006677ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006679 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006680 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006681
Douglas Gregor5557b252009-10-28 00:29:27 +00006682 // FIXME: Will we ever have proper type location here? Will we actually
6683 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006684 QualType T = getDerived().TransformType(E->getType());
6685 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006686 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006687
Douglas Gregorb98b1992009-08-11 05:31:07 +00006688 if (!getDerived().AlwaysRebuild() &&
6689 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006690 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006691
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692 return getDerived().RebuildImplicitValueInitExpr(T);
6693}
Mike Stump1eb44332009-09-09 15:08:12 +00006694
Douglas Gregorb98b1992009-08-11 05:31:07 +00006695template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006696ExprResult
John McCall454feb92009-12-08 09:21:05 +00006697TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006698 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6699 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006700 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006701
John McCall60d7b3a2010-08-24 06:29:42 +00006702 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006703 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006704 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006705
Douglas Gregorb98b1992009-08-11 05:31:07 +00006706 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006707 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006708 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006709 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006710
John McCall9ae2f072010-08-23 23:25:46 +00006711 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006712 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006713}
6714
6715template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006716ExprResult
John McCall454feb92009-12-08 09:21:05 +00006717TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006718 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006719 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006720 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6721 &ArgumentChanged))
6722 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006723
Douglas Gregorb98b1992009-08-11 05:31:07 +00006724 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006725 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726 E->getRParenLoc());
6727}
Mike Stump1eb44332009-09-09 15:08:12 +00006728
Douglas Gregorb98b1992009-08-11 05:31:07 +00006729/// \brief Transform an address-of-label expression.
6730///
6731/// By default, the transformation of an address-of-label expression always
6732/// rebuilds the expression, so that the label identifier can be resolved to
6733/// the corresponding label statement by semantic analysis.
6734template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006735ExprResult
John McCall454feb92009-12-08 09:21:05 +00006736TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006737 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6738 E->getLabel());
6739 if (!LD)
6740 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006741
Douglas Gregorb98b1992009-08-11 05:31:07 +00006742 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006743 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006744}
Mike Stump1eb44332009-09-09 15:08:12 +00006745
6746template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006747ExprResult
John McCall454feb92009-12-08 09:21:05 +00006748TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006749 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006750 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006751 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006752 if (SubStmt.isInvalid()) {
6753 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006754 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006755 }
Mike Stump1eb44332009-09-09 15:08:12 +00006756
Douglas Gregorb98b1992009-08-11 05:31:07 +00006757 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006758 SubStmt.get() == E->getSubStmt()) {
6759 // Calling this an 'error' is unintuitive, but it does the right thing.
6760 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006761 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006762 }
Mike Stump1eb44332009-09-09 15:08:12 +00006763
6764 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006765 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006766 E->getRParenLoc());
6767}
Mike Stump1eb44332009-09-09 15:08:12 +00006768
Douglas Gregorb98b1992009-08-11 05:31:07 +00006769template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006770ExprResult
John McCall454feb92009-12-08 09:21:05 +00006771TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006772 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006773 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006774 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006775
John McCall60d7b3a2010-08-24 06:29:42 +00006776 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006777 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006778 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006779
John McCall60d7b3a2010-08-24 06:29:42 +00006780 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006781 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006782 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006783
Douglas Gregorb98b1992009-08-11 05:31:07 +00006784 if (!getDerived().AlwaysRebuild() &&
6785 Cond.get() == E->getCond() &&
6786 LHS.get() == E->getLHS() &&
6787 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006788 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006789
Douglas Gregorb98b1992009-08-11 05:31:07 +00006790 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006791 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006792 E->getRParenLoc());
6793}
Mike Stump1eb44332009-09-09 15:08:12 +00006794
Douglas Gregorb98b1992009-08-11 05:31:07 +00006795template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006796ExprResult
John McCall454feb92009-12-08 09:21:05 +00006797TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006798 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006799}
6800
6801template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006802ExprResult
John McCall454feb92009-12-08 09:21:05 +00006803TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006804 switch (E->getOperator()) {
6805 case OO_New:
6806 case OO_Delete:
6807 case OO_Array_New:
6808 case OO_Array_Delete:
6809 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006810
Douglas Gregor668d6d92009-12-13 20:44:55 +00006811 case OO_Call: {
6812 // This is a call to an object's operator().
6813 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6814
6815 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006816 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006817 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006818 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006819
6820 // FIXME: Poor location information
6821 SourceLocation FakeLParenLoc
6822 = SemaRef.PP.getLocForEndOfToken(
6823 static_cast<Expr *>(Object.get())->getLocEnd());
6824
6825 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006826 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006827 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006828 Args))
6829 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006830
John McCall9ae2f072010-08-23 23:25:46 +00006831 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006832 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006833 E->getLocEnd());
6834 }
6835
6836#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6837 case OO_##Name:
6838#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6839#include "clang/Basic/OperatorKinds.def"
6840 case OO_Subscript:
6841 // Handled below.
6842 break;
6843
6844 case OO_Conditional:
6845 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006846
6847 case OO_None:
6848 case NUM_OVERLOADED_OPERATORS:
6849 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006850 }
6851
John McCall60d7b3a2010-08-24 06:29:42 +00006852 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006853 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006854 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006855
John McCall60d7b3a2010-08-24 06:29:42 +00006856 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006857 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006858 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006859
John McCall60d7b3a2010-08-24 06:29:42 +00006860 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006861 if (E->getNumArgs() == 2) {
6862 Second = getDerived().TransformExpr(E->getArg(1));
6863 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006864 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006865 }
Mike Stump1eb44332009-09-09 15:08:12 +00006866
Douglas Gregorb98b1992009-08-11 05:31:07 +00006867 if (!getDerived().AlwaysRebuild() &&
6868 Callee.get() == E->getCallee() &&
6869 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006870 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006871 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006872
Lang Hamesbe9af122012-10-02 04:45:10 +00006873 Sema::FPContractStateRAII FPContractState(getSema());
6874 getSema().FPFeatures.fp_contract = E->isFPContractable();
6875
Douglas Gregorb98b1992009-08-11 05:31:07 +00006876 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6877 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006878 Callee.get(),
6879 First.get(),
6880 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006881}
Mike Stump1eb44332009-09-09 15:08:12 +00006882
Douglas Gregorb98b1992009-08-11 05:31:07 +00006883template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006884ExprResult
John McCall454feb92009-12-08 09:21:05 +00006885TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6886 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006887}
Mike Stump1eb44332009-09-09 15:08:12 +00006888
Douglas Gregorb98b1992009-08-11 05:31:07 +00006889template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006890ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006891TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6892 // Transform the callee.
6893 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6894 if (Callee.isInvalid())
6895 return ExprError();
6896
6897 // Transform exec config.
6898 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6899 if (EC.isInvalid())
6900 return ExprError();
6901
6902 // Transform arguments.
6903 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006904 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006905 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006906 &ArgChanged))
6907 return ExprError();
6908
6909 if (!getDerived().AlwaysRebuild() &&
6910 Callee.get() == E->getCallee() &&
6911 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006912 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006913
6914 // FIXME: Wrong source location information for the '('.
6915 SourceLocation FakeLParenLoc
6916 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6917 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006918 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006919 E->getRParenLoc(), EC.get());
6920}
6921
6922template<typename Derived>
6923ExprResult
John McCall454feb92009-12-08 09:21:05 +00006924TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006925 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6926 if (!Type)
6927 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006928
John McCall60d7b3a2010-08-24 06:29:42 +00006929 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006930 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006931 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006932 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006933
Douglas Gregorb98b1992009-08-11 05:31:07 +00006934 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006935 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006936 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006937 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006938
Douglas Gregorb98b1992009-08-11 05:31:07 +00006939 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006940 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006941 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6942 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006943 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006944 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006945 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006946 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006947 FakeRAngleLoc,
6948 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006949 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00006950 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006951}
Mike Stump1eb44332009-09-09 15:08:12 +00006952
Douglas Gregorb98b1992009-08-11 05:31:07 +00006953template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006954ExprResult
John McCall454feb92009-12-08 09:21:05 +00006955TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6956 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006957}
Mike Stump1eb44332009-09-09 15:08:12 +00006958
6959template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006960ExprResult
John McCall454feb92009-12-08 09:21:05 +00006961TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6962 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006963}
6964
Douglas Gregorb98b1992009-08-11 05:31:07 +00006965template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006966ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006967TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006968 CXXReinterpretCastExpr *E) {
6969 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006970}
Mike Stump1eb44332009-09-09 15:08:12 +00006971
Douglas Gregorb98b1992009-08-11 05:31:07 +00006972template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006973ExprResult
John McCall454feb92009-12-08 09:21:05 +00006974TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6975 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006976}
Mike Stump1eb44332009-09-09 15:08:12 +00006977
Douglas Gregorb98b1992009-08-11 05:31:07 +00006978template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006979ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006980TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006981 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006982 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6983 if (!Type)
6984 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006985
John McCall60d7b3a2010-08-24 06:29:42 +00006986 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006987 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006988 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006989 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006990
Douglas Gregorb98b1992009-08-11 05:31:07 +00006991 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006992 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006993 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006994 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006995
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006996 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006997 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006998 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006999 E->getRParenLoc());
7000}
Mike Stump1eb44332009-09-09 15:08:12 +00007001
Douglas Gregorb98b1992009-08-11 05:31:07 +00007002template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007003ExprResult
John McCall454feb92009-12-08 09:21:05 +00007004TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007005 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007006 TypeSourceInfo *TInfo
7007 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7008 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007009 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007010
Douglas Gregorb98b1992009-08-11 05:31:07 +00007011 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007012 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007013 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007014
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007015 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7016 E->getLocStart(),
7017 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007018 E->getLocEnd());
7019 }
Mike Stump1eb44332009-09-09 15:08:12 +00007020
Eli Friedmanef331b72012-01-20 01:26:23 +00007021 // We don't know whether the subexpression is potentially evaluated until
7022 // after we perform semantic analysis. We speculatively assume it is
7023 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007024 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007025 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7026 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007027
John McCall60d7b3a2010-08-24 06:29:42 +00007028 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007029 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007030 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007031
Douglas Gregorb98b1992009-08-11 05:31:07 +00007032 if (!getDerived().AlwaysRebuild() &&
7033 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007034 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007035
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007036 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7037 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007038 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007039 E->getLocEnd());
7040}
7041
7042template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007043ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007044TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7045 if (E->isTypeOperand()) {
7046 TypeSourceInfo *TInfo
7047 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7048 if (!TInfo)
7049 return ExprError();
7050
7051 if (!getDerived().AlwaysRebuild() &&
7052 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007053 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007054
Douglas Gregor3c52a212011-03-06 17:40:41 +00007055 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007056 E->getLocStart(),
7057 TInfo,
7058 E->getLocEnd());
7059 }
7060
Francois Pichet01b7c302010-09-08 12:20:18 +00007061 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7062
7063 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7064 if (SubExpr.isInvalid())
7065 return ExprError();
7066
7067 if (!getDerived().AlwaysRebuild() &&
7068 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007069 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007070
7071 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7072 E->getLocStart(),
7073 SubExpr.get(),
7074 E->getLocEnd());
7075}
7076
7077template<typename Derived>
7078ExprResult
John McCall454feb92009-12-08 09:21:05 +00007079TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007080 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007081}
Mike Stump1eb44332009-09-09 15:08:12 +00007082
Douglas Gregorb98b1992009-08-11 05:31:07 +00007083template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007084ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007085TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007086 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007087 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007088}
Mike Stump1eb44332009-09-09 15:08:12 +00007089
Douglas Gregorb98b1992009-08-11 05:31:07 +00007090template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007091ExprResult
John McCall454feb92009-12-08 09:21:05 +00007092TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007093 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007094 QualType T;
7095 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7096 T = MD->getThisType(getSema().Context);
7097 else
7098 T = getSema().Context.getPointerType(
7099 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007100
Douglas Gregorec79d872012-02-24 17:41:38 +00007101 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7102 // Make sure that we capture 'this'.
7103 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007104 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007105 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007106
Douglas Gregor828a1972010-01-07 23:12:05 +00007107 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007108}
Mike Stump1eb44332009-09-09 15:08:12 +00007109
Douglas Gregorb98b1992009-08-11 05:31:07 +00007110template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007111ExprResult
John McCall454feb92009-12-08 09:21:05 +00007112TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007113 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007114 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007115 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007116
Douglas Gregorb98b1992009-08-11 05:31:07 +00007117 if (!getDerived().AlwaysRebuild() &&
7118 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007119 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007120
Douglas Gregorbca01b42011-07-06 22:04:06 +00007121 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7122 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007123}
Mike Stump1eb44332009-09-09 15:08:12 +00007124
Douglas Gregorb98b1992009-08-11 05:31:07 +00007125template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007126ExprResult
John McCall454feb92009-12-08 09:21:05 +00007127TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007128 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007129 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7130 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007131 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007132 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007133
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007134 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007135 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007136 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007137
Douglas Gregor036aed12009-12-23 23:03:06 +00007138 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007139}
Mike Stump1eb44332009-09-09 15:08:12 +00007140
Douglas Gregorb98b1992009-08-11 05:31:07 +00007141template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007142ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007143TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7144 CXXScalarValueInitExpr *E) {
7145 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7146 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007147 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007148
Douglas Gregorb98b1992009-08-11 05:31:07 +00007149 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007150 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007151 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007152
Chad Rosier4a9d7952012-08-08 18:46:20 +00007153 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007154 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007155 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007156}
Mike Stump1eb44332009-09-09 15:08:12 +00007157
Douglas Gregorb98b1992009-08-11 05:31:07 +00007158template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007159ExprResult
John McCall454feb92009-12-08 09:21:05 +00007160TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007161 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007162 TypeSourceInfo *AllocTypeInfo
7163 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7164 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007165 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007166
Douglas Gregorb98b1992009-08-11 05:31:07 +00007167 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007168 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007169 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007170 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007171
Douglas Gregorb98b1992009-08-11 05:31:07 +00007172 // Transform the placement arguments (if any).
7173 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007174 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007175 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007176 E->getNumPlacementArgs(), true,
7177 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007178 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007179
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007180 // Transform the initializer (if any).
7181 Expr *OldInit = E->getInitializer();
7182 ExprResult NewInit;
7183 if (OldInit)
7184 NewInit = getDerived().TransformExpr(OldInit);
7185 if (NewInit.isInvalid())
7186 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007187
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007188 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007189 FunctionDecl *OperatorNew = 0;
7190 if (E->getOperatorNew()) {
7191 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007192 getDerived().TransformDecl(E->getLocStart(),
7193 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007194 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007195 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007196 }
7197
7198 FunctionDecl *OperatorDelete = 0;
7199 if (E->getOperatorDelete()) {
7200 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007201 getDerived().TransformDecl(E->getLocStart(),
7202 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007203 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007204 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007205 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007206
Douglas Gregorb98b1992009-08-11 05:31:07 +00007207 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007208 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007209 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007210 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007211 OperatorNew == E->getOperatorNew() &&
7212 OperatorDelete == E->getOperatorDelete() &&
7213 !ArgumentChanged) {
7214 // Mark any declarations we need as referenced.
7215 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007216 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007217 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007218 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007219 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007220
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007221 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007222 QualType ElementType
7223 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7224 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7225 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7226 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007227 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007228 }
7229 }
7230 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007231
John McCall3fa5cae2010-10-26 07:05:15 +00007232 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007233 }
Mike Stump1eb44332009-09-09 15:08:12 +00007234
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007235 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007236 if (!ArraySize.get()) {
7237 // If no array size was specified, but the new expression was
7238 // instantiated with an array type (e.g., "new T" where T is
7239 // instantiated with "int[4]"), extract the outer bound from the
7240 // array type as our array size. We do this with constant and
7241 // dependently-sized array types.
7242 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7243 if (!ArrayT) {
7244 // Do nothing
7245 } else if (const ConstantArrayType *ConsArrayT
7246 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007247 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007248 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007249 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007250 SemaRef.Context.getSizeType(),
7251 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007252 AllocType = ConsArrayT->getElementType();
7253 } else if (const DependentSizedArrayType *DepArrayT
7254 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7255 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007256 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007257 AllocType = DepArrayT->getElementType();
7258 }
7259 }
7260 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007261
Douglas Gregorb98b1992009-08-11 05:31:07 +00007262 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7263 E->isGlobalNew(),
7264 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007265 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007266 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007267 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007268 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007269 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007270 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007271 E->getDirectInitRange(),
7272 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007273}
Mike Stump1eb44332009-09-09 15:08:12 +00007274
Douglas Gregorb98b1992009-08-11 05:31:07 +00007275template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007276ExprResult
John McCall454feb92009-12-08 09:21:05 +00007277TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007278 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007279 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007280 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007281
Douglas Gregor1af74512010-02-26 00:38:10 +00007282 // Transform the delete operator, if known.
7283 FunctionDecl *OperatorDelete = 0;
7284 if (E->getOperatorDelete()) {
7285 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007286 getDerived().TransformDecl(E->getLocStart(),
7287 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007288 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007289 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007290 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007291
Douglas Gregorb98b1992009-08-11 05:31:07 +00007292 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007293 Operand.get() == E->getArgument() &&
7294 OperatorDelete == E->getOperatorDelete()) {
7295 // Mark any declarations we need as referenced.
7296 // FIXME: instantiation-specific.
7297 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007298 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007299
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007300 if (!E->getArgument()->isTypeDependent()) {
7301 QualType Destroyed = SemaRef.Context.getBaseElementType(
7302 E->getDestroyedType());
7303 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7304 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007305 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007306 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007307 }
7308 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007309
John McCall3fa5cae2010-10-26 07:05:15 +00007310 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007311 }
Mike Stump1eb44332009-09-09 15:08:12 +00007312
Douglas Gregorb98b1992009-08-11 05:31:07 +00007313 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7314 E->isGlobalDelete(),
7315 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007316 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007317}
Mike Stump1eb44332009-09-09 15:08:12 +00007318
Douglas Gregorb98b1992009-08-11 05:31:07 +00007319template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007320ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007321TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007322 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007323 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007324 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007325 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007326
John McCallb3d87482010-08-24 05:47:05 +00007327 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007328 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007329 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007330 E->getOperatorLoc(),
7331 E->isArrow()? tok::arrow : tok::period,
7332 ObjectTypePtr,
7333 MayBePseudoDestructor);
7334 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007335 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007336
John McCallb3d87482010-08-24 05:47:05 +00007337 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007338 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7339 if (QualifierLoc) {
7340 QualifierLoc
7341 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7342 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007343 return ExprError();
7344 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007345 CXXScopeSpec SS;
7346 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007347
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007348 PseudoDestructorTypeStorage Destroyed;
7349 if (E->getDestroyedTypeInfo()) {
7350 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007351 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007352 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007353 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007354 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007355 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007356 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007357 // We aren't likely to be able to resolve the identifier down to a type
7358 // now anyway, so just retain the identifier.
7359 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7360 E->getDestroyedTypeLoc());
7361 } else {
7362 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007363 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007364 *E->getDestroyedTypeIdentifier(),
7365 E->getDestroyedTypeLoc(),
7366 /*Scope=*/0,
7367 SS, ObjectTypePtr,
7368 false);
7369 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007370 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007371
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007372 Destroyed
7373 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7374 E->getDestroyedTypeLoc());
7375 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007376
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007377 TypeSourceInfo *ScopeTypeInfo = 0;
7378 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007379 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007380 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007381 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007382 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007383
John McCall9ae2f072010-08-23 23:25:46 +00007384 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007385 E->getOperatorLoc(),
7386 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007387 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007388 ScopeTypeInfo,
7389 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007390 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007391 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007392}
Mike Stump1eb44332009-09-09 15:08:12 +00007393
Douglas Gregora71d8192009-09-04 17:36:40 +00007394template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007395ExprResult
John McCallba135432009-11-21 08:51:07 +00007396TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007397 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007398 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7399 Sema::LookupOrdinaryName);
7400
7401 // Transform all the decls.
7402 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7403 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007404 NamedDecl *InstD = static_cast<NamedDecl*>(
7405 getDerived().TransformDecl(Old->getNameLoc(),
7406 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007407 if (!InstD) {
7408 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7409 // This can happen because of dependent hiding.
7410 if (isa<UsingShadowDecl>(*I))
7411 continue;
7412 else
John McCallf312b1e2010-08-26 23:41:50 +00007413 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007414 }
John McCallf7a1a742009-11-24 19:00:30 +00007415
7416 // Expand using declarations.
7417 if (isa<UsingDecl>(InstD)) {
7418 UsingDecl *UD = cast<UsingDecl>(InstD);
7419 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7420 E = UD->shadow_end(); I != E; ++I)
7421 R.addDecl(*I);
7422 continue;
7423 }
7424
7425 R.addDecl(InstD);
7426 }
7427
7428 // Resolve a kind, but don't do any further analysis. If it's
7429 // ambiguous, the callee needs to deal with it.
7430 R.resolveKind();
7431
7432 // Rebuild the nested-name qualifier, if present.
7433 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007434 if (Old->getQualifierLoc()) {
7435 NestedNameSpecifierLoc QualifierLoc
7436 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7437 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007438 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007439
Douglas Gregor4c9be892011-02-28 20:01:57 +00007440 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007441 }
7442
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007443 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007444 CXXRecordDecl *NamingClass
7445 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7446 Old->getNameLoc(),
7447 Old->getNamingClass()));
7448 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007449 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007450
Douglas Gregor66c45152010-04-27 16:10:10 +00007451 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007452 }
7453
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007454 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7455
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007456 // If we have neither explicit template arguments, nor the template keyword,
7457 // it's a normal declaration name.
7458 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007459 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7460
7461 // If we have template arguments, rebuild them, then rebuild the
7462 // templateid expression.
7463 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007464 if (Old->hasExplicitTemplateArgs() &&
7465 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007466 Old->getNumTemplateArgs(),
7467 TransArgs))
7468 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007469
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007470 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007471 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007472}
Mike Stump1eb44332009-09-09 15:08:12 +00007473
Douglas Gregorb98b1992009-08-11 05:31:07 +00007474template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007475ExprResult
John McCall454feb92009-12-08 09:21:05 +00007476TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007477 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7478 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007479 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007480
Douglas Gregorb98b1992009-08-11 05:31:07 +00007481 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007482 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007483 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007484
Mike Stump1eb44332009-09-09 15:08:12 +00007485 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007486 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007487 T,
7488 E->getLocEnd());
7489}
Mike Stump1eb44332009-09-09 15:08:12 +00007490
Douglas Gregorb98b1992009-08-11 05:31:07 +00007491template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007492ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007493TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7494 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7495 if (!LhsT)
7496 return ExprError();
7497
7498 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7499 if (!RhsT)
7500 return ExprError();
7501
7502 if (!getDerived().AlwaysRebuild() &&
7503 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7504 return SemaRef.Owned(E);
7505
7506 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7507 E->getLocStart(),
7508 LhsT, RhsT,
7509 E->getLocEnd());
7510}
7511
7512template<typename Derived>
7513ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007514TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7515 bool ArgChanged = false;
7516 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7517 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7518 TypeSourceInfo *From = E->getArg(I);
7519 TypeLoc FromTL = From->getTypeLoc();
7520 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7521 TypeLocBuilder TLB;
7522 TLB.reserve(FromTL.getFullDataSize());
7523 QualType To = getDerived().TransformType(TLB, FromTL);
7524 if (To.isNull())
7525 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007526
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007527 if (To == From->getType())
7528 Args.push_back(From);
7529 else {
7530 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7531 ArgChanged = true;
7532 }
7533 continue;
7534 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007535
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007536 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007537
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007538 // We have a pack expansion. Instantiate it.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007539 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007540 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7541 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7542 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007543
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007544 // Determine whether the set of unexpanded parameter packs can and should
7545 // be expanded.
7546 bool Expand = true;
7547 bool RetainExpansion = false;
7548 llvm::Optional<unsigned> OrigNumExpansions
7549 = ExpansionTL.getTypePtr()->getNumExpansions();
7550 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7551 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7552 PatternTL.getSourceRange(),
7553 Unexpanded,
7554 Expand, RetainExpansion,
7555 NumExpansions))
7556 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007557
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007558 if (!Expand) {
7559 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007560 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007561 // expansion.
7562 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007563
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007564 TypeLocBuilder TLB;
7565 TLB.reserve(From->getTypeLoc().getFullDataSize());
7566
7567 QualType To = getDerived().TransformType(TLB, PatternTL);
7568 if (To.isNull())
7569 return ExprError();
7570
Chad Rosier4a9d7952012-08-08 18:46:20 +00007571 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007572 PatternTL.getSourceRange(),
7573 ExpansionTL.getEllipsisLoc(),
7574 NumExpansions);
7575 if (To.isNull())
7576 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007577
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007578 PackExpansionTypeLoc ToExpansionTL
7579 = TLB.push<PackExpansionTypeLoc>(To);
7580 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7581 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7582 continue;
7583 }
7584
7585 // Expand the pack expansion by substituting for each argument in the
7586 // pack(s).
7587 for (unsigned I = 0; I != *NumExpansions; ++I) {
7588 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7589 TypeLocBuilder TLB;
7590 TLB.reserve(PatternTL.getFullDataSize());
7591 QualType To = getDerived().TransformType(TLB, PatternTL);
7592 if (To.isNull())
7593 return ExprError();
7594
7595 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7596 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007597
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007598 if (!RetainExpansion)
7599 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007600
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007601 // If we're supposed to retain a pack expansion, do so by temporarily
7602 // forgetting the partially-substituted parameter pack.
7603 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7604
7605 TypeLocBuilder TLB;
7606 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007607
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007608 QualType To = getDerived().TransformType(TLB, PatternTL);
7609 if (To.isNull())
7610 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007611
7612 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007613 PatternTL.getSourceRange(),
7614 ExpansionTL.getEllipsisLoc(),
7615 NumExpansions);
7616 if (To.isNull())
7617 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007618
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007619 PackExpansionTypeLoc ToExpansionTL
7620 = TLB.push<PackExpansionTypeLoc>(To);
7621 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7622 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7623 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007624
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007625 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7626 return SemaRef.Owned(E);
7627
7628 return getDerived().RebuildTypeTrait(E->getTrait(),
7629 E->getLocStart(),
7630 Args,
7631 E->getLocEnd());
7632}
7633
7634template<typename Derived>
7635ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007636TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7637 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7638 if (!T)
7639 return ExprError();
7640
7641 if (!getDerived().AlwaysRebuild() &&
7642 T == E->getQueriedTypeSourceInfo())
7643 return SemaRef.Owned(E);
7644
7645 ExprResult SubExpr;
7646 {
7647 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7648 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7649 if (SubExpr.isInvalid())
7650 return ExprError();
7651
7652 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7653 return SemaRef.Owned(E);
7654 }
7655
7656 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7657 E->getLocStart(),
7658 T,
7659 SubExpr.get(),
7660 E->getLocEnd());
7661}
7662
7663template<typename Derived>
7664ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007665TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7666 ExprResult SubExpr;
7667 {
7668 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7669 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7670 if (SubExpr.isInvalid())
7671 return ExprError();
7672
7673 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7674 return SemaRef.Owned(E);
7675 }
7676
7677 return getDerived().RebuildExpressionTrait(
7678 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7679}
7680
7681template<typename Derived>
7682ExprResult
John McCall865d4472009-11-19 22:55:06 +00007683TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007684 DependentScopeDeclRefExpr *E) {
Richard Smith80ddc312012-10-19 06:32:17 +00007685 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
7686}
7687
7688template<typename Derived>
7689ExprResult
7690TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7691 DependentScopeDeclRefExpr *E,
7692 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007693 NestedNameSpecifierLoc QualifierLoc
7694 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7695 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007696 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007697 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007698
John McCall43fed0d2010-11-12 08:19:04 +00007699 // TODO: If this is a conversion-function-id, verify that the
7700 // destination type name (if present) resolves the same way after
7701 // instantiation as it did in the local scope.
7702
Abramo Bagnara25777432010-08-11 22:01:17 +00007703 DeclarationNameInfo NameInfo
7704 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7705 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007706 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007707
John McCallf7a1a742009-11-24 19:00:30 +00007708 if (!E->hasExplicitTemplateArgs()) {
7709 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007710 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007711 // Note: it is sufficient to compare the Name component of NameInfo:
7712 // if name has not changed, DNLoc has not changed either.
7713 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007714 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007715
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007716 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007717 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007718 NameInfo,
Richard Smith80ddc312012-10-19 06:32:17 +00007719 /*TemplateArgs*/ 0,
7720 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007721 }
John McCalld5532b62009-11-23 01:53:49 +00007722
7723 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007724 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7725 E->getNumTemplateArgs(),
7726 TransArgs))
7727 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007728
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007729 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007730 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007731 NameInfo,
Richard Smith80ddc312012-10-19 06:32:17 +00007732 &TransArgs,
7733 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007734}
7735
7736template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007737ExprResult
John McCall454feb92009-12-08 09:21:05 +00007738TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007739 // CXXConstructExprs are always implicit, so when we have a
7740 // 1-argument construction we just transform that argument.
7741 if (E->getNumArgs() == 1 ||
7742 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7743 return getDerived().TransformExpr(E->getArg(0));
7744
Douglas Gregorb98b1992009-08-11 05:31:07 +00007745 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7746
7747 QualType T = getDerived().TransformType(E->getType());
7748 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007749 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007750
7751 CXXConstructorDecl *Constructor
7752 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007753 getDerived().TransformDecl(E->getLocStart(),
7754 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007755 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007756 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007757
Douglas Gregorb98b1992009-08-11 05:31:07 +00007758 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007759 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007760 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007761 &ArgumentChanged))
7762 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007763
Douglas Gregorb98b1992009-08-11 05:31:07 +00007764 if (!getDerived().AlwaysRebuild() &&
7765 T == E->getType() &&
7766 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007767 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007768 // Mark the constructor as referenced.
7769 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007770 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007771 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007772 }
Mike Stump1eb44332009-09-09 15:08:12 +00007773
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007774 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7775 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007776 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007777 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007778 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007779 E->getConstructionKind(),
7780 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007781}
Mike Stump1eb44332009-09-09 15:08:12 +00007782
Douglas Gregorb98b1992009-08-11 05:31:07 +00007783/// \brief Transform a C++ temporary-binding expression.
7784///
Douglas Gregor51326552009-12-24 18:51:59 +00007785/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7786/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007787template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007788ExprResult
John McCall454feb92009-12-08 09:21:05 +00007789TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007790 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007791}
Mike Stump1eb44332009-09-09 15:08:12 +00007792
John McCall4765fa02010-12-06 08:20:24 +00007793/// \brief Transform a C++ expression that contains cleanups that should
7794/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007795///
John McCall4765fa02010-12-06 08:20:24 +00007796/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007797/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007798template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007799ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007800TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007801 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007802}
Mike Stump1eb44332009-09-09 15:08:12 +00007803
Douglas Gregorb98b1992009-08-11 05:31:07 +00007804template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007805ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007806TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007807 CXXTemporaryObjectExpr *E) {
7808 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7809 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007810 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007811
Douglas Gregorb98b1992009-08-11 05:31:07 +00007812 CXXConstructorDecl *Constructor
7813 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007814 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007815 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007816 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007817 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007818
Douglas Gregorb98b1992009-08-11 05:31:07 +00007819 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007820 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007821 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007822 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007823 &ArgumentChanged))
7824 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007825
Douglas Gregorb98b1992009-08-11 05:31:07 +00007826 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007827 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007828 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007829 !ArgumentChanged) {
7830 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007831 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007832 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007833 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007834
Douglas Gregorab6677e2010-09-08 00:15:04 +00007835 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7836 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007837 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007838 E->getLocEnd());
7839}
Mike Stump1eb44332009-09-09 15:08:12 +00007840
Douglas Gregorb98b1992009-08-11 05:31:07 +00007841template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007842ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007843TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007844 // Transform the type of the lambda parameters and start the definition of
7845 // the lambda itself.
7846 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00007847 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00007848 if (!MethodTy)
7849 return ExprError();
7850
Eli Friedman8da8a662012-09-19 01:18:11 +00007851 // Create the local class that will describe the lambda.
7852 CXXRecordDecl *Class
7853 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7854 MethodTy,
7855 /*KnownDependent=*/false);
7856 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7857
Douglas Gregorc6889e72012-02-14 22:28:59 +00007858 // Transform lambda parameters.
Douglas Gregorc6889e72012-02-14 22:28:59 +00007859 llvm::SmallVector<QualType, 4> ParamTypes;
7860 llvm::SmallVector<ParmVarDecl *, 4> Params;
7861 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7862 E->getCallOperator()->param_begin(),
7863 E->getCallOperator()->param_size(),
7864 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00007865 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00007866
Douglas Gregordfca6f52012-02-13 22:00:16 +00007867 // Build the call operator.
7868 CXXMethodDecl *CallOperator
7869 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007870 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007871 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007872 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007873 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00007874
Richard Smith612409e2012-07-25 03:56:55 +00007875 return getDerived().TransformLambdaScope(E, CallOperator);
7876}
7877
7878template<typename Derived>
7879ExprResult
7880TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
7881 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00007882 // Introduce the context of the call operator.
7883 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7884
Douglas Gregordfca6f52012-02-13 22:00:16 +00007885 // Enter the scope of the lambda.
7886 sema::LambdaScopeInfo *LSI
7887 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7888 E->getCaptureDefault(),
7889 E->hasExplicitParameters(),
7890 E->hasExplicitResultType(),
7891 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007892
Douglas Gregordfca6f52012-02-13 22:00:16 +00007893 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00007894 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00007895 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007896 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007897 CEnd = E->capture_end();
7898 C != CEnd; ++C) {
7899 // When we hit the first implicit capture, tell Sema that we've finished
7900 // the list of explicit captures.
7901 if (!FinishedExplicitCaptures && C->isImplicit()) {
7902 getSema().finishLambdaExplicitCaptures(LSI);
7903 FinishedExplicitCaptures = true;
7904 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007905
Douglas Gregordfca6f52012-02-13 22:00:16 +00007906 // Capturing 'this' is trivial.
7907 if (C->capturesThis()) {
7908 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7909 continue;
7910 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007911
Douglas Gregora7365242012-02-14 19:27:52 +00007912 // Determine the capture kind for Sema.
7913 Sema::TryCaptureKind Kind
7914 = C->isImplicit()? Sema::TryCapture_Implicit
7915 : C->getCaptureKind() == LCK_ByCopy
7916 ? Sema::TryCapture_ExplicitByVal
7917 : Sema::TryCapture_ExplicitByRef;
7918 SourceLocation EllipsisLoc;
7919 if (C->isPackExpansion()) {
7920 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7921 bool ShouldExpand = false;
7922 bool RetainExpansion = false;
7923 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007924 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7925 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00007926 Unexpanded,
7927 ShouldExpand, RetainExpansion,
7928 NumExpansions))
7929 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007930
Douglas Gregora7365242012-02-14 19:27:52 +00007931 if (ShouldExpand) {
7932 // The transform has determined that we should perform an expansion;
7933 // transform and capture each of the arguments.
7934 // expansion of the pattern. Do so.
7935 VarDecl *Pack = C->getCapturedVar();
7936 for (unsigned I = 0; I != *NumExpansions; ++I) {
7937 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7938 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00007939 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00007940 Pack));
7941 if (!CapturedVar) {
7942 Invalid = true;
7943 continue;
7944 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007945
Douglas Gregora7365242012-02-14 19:27:52 +00007946 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007947 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
7948 }
Douglas Gregora7365242012-02-14 19:27:52 +00007949 continue;
7950 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007951
Douglas Gregora7365242012-02-14 19:27:52 +00007952 EllipsisLoc = C->getEllipsisLoc();
7953 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007954
Douglas Gregordfca6f52012-02-13 22:00:16 +00007955 // Transform the captured variable.
7956 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00007957 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007958 C->getCapturedVar()));
7959 if (!CapturedVar) {
7960 Invalid = true;
7961 continue;
7962 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007963
Douglas Gregordfca6f52012-02-13 22:00:16 +00007964 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007965 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007966 }
7967 if (!FinishedExplicitCaptures)
7968 getSema().finishLambdaExplicitCaptures(LSI);
7969
Douglas Gregordfca6f52012-02-13 22:00:16 +00007970
7971 // Enter a new evaluation context to insulate the lambda from any
7972 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007973 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007974
7975 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007976 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00007977 /*IsInstantiation=*/true);
7978 return ExprError();
7979 }
7980
7981 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00007982 StmtResult Body = getDerived().TransformStmt(E->getBody());
7983 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007984 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00007985 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007986 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00007987 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00007988
Chad Rosier4a9d7952012-08-08 18:46:20 +00007989 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00007990 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00007991}
7992
7993template<typename Derived>
7994ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007995TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007996 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007997 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7998 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007999 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008000
Douglas Gregorb98b1992009-08-11 05:31:07 +00008001 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008002 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008003 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008004 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008005 &ArgumentChanged))
8006 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008007
Douglas Gregorb98b1992009-08-11 05:31:07 +00008008 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008009 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008010 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008011 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008012
Douglas Gregorb98b1992009-08-11 05:31:07 +00008013 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008014 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008015 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008016 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008017 E->getRParenLoc());
8018}
Mike Stump1eb44332009-09-09 15:08:12 +00008019
Douglas Gregorb98b1992009-08-11 05:31:07 +00008020template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008021ExprResult
John McCall865d4472009-11-19 22:55:06 +00008022TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008023 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008024 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008025 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008026 Expr *OldBase;
8027 QualType BaseType;
8028 QualType ObjectType;
8029 if (!E->isImplicitAccess()) {
8030 OldBase = E->getBase();
8031 Base = getDerived().TransformExpr(OldBase);
8032 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008033 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008034
John McCallaa81e162009-12-01 22:10:20 +00008035 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008036 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008037 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008038 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008039 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008040 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008041 ObjectTy,
8042 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008043 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008044 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008045
John McCallb3d87482010-08-24 05:47:05 +00008046 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008047 BaseType = ((Expr*) Base.get())->getType();
8048 } else {
8049 OldBase = 0;
8050 BaseType = getDerived().TransformType(E->getBaseType());
8051 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8052 }
Mike Stump1eb44332009-09-09 15:08:12 +00008053
Douglas Gregor6cd21982009-10-20 05:58:46 +00008054 // Transform the first part of the nested-name-specifier that qualifies
8055 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008056 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008057 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008058 E->getFirstQualifierFoundInScope(),
8059 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008060
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008061 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008062 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008063 QualifierLoc
8064 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8065 ObjectType,
8066 FirstQualifierInScope);
8067 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008068 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008069 }
Mike Stump1eb44332009-09-09 15:08:12 +00008070
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008071 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8072
John McCall43fed0d2010-11-12 08:19:04 +00008073 // TODO: If this is a conversion-function-id, verify that the
8074 // destination type name (if present) resolves the same way after
8075 // instantiation as it did in the local scope.
8076
Abramo Bagnara25777432010-08-11 22:01:17 +00008077 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008078 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008079 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008080 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008081
John McCallaa81e162009-12-01 22:10:20 +00008082 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008083 // This is a reference to a member without an explicitly-specified
8084 // template argument list. Optimize for this common case.
8085 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008086 Base.get() == OldBase &&
8087 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008088 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008089 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008090 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008091 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008092
John McCall9ae2f072010-08-23 23:25:46 +00008093 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008094 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008095 E->isArrow(),
8096 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008097 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008098 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008099 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008100 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008101 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008102 }
8103
John McCalld5532b62009-11-23 01:53:49 +00008104 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008105 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8106 E->getNumTemplateArgs(),
8107 TransArgs))
8108 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008109
John McCall9ae2f072010-08-23 23:25:46 +00008110 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008111 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008112 E->isArrow(),
8113 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008114 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008115 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008116 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008117 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008118 &TransArgs);
8119}
8120
8121template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008122ExprResult
John McCall454feb92009-12-08 09:21:05 +00008123TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008124 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008125 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008126 QualType BaseType;
8127 if (!Old->isImplicitAccess()) {
8128 Base = getDerived().TransformExpr(Old->getBase());
8129 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008130 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008131 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8132 Old->isArrow());
8133 if (Base.isInvalid())
8134 return ExprError();
8135 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008136 } else {
8137 BaseType = getDerived().TransformType(Old->getBaseType());
8138 }
John McCall129e2df2009-11-30 22:42:35 +00008139
Douglas Gregor4c9be892011-02-28 20:01:57 +00008140 NestedNameSpecifierLoc QualifierLoc;
8141 if (Old->getQualifierLoc()) {
8142 QualifierLoc
8143 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8144 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008145 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008146 }
8147
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008148 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8149
Abramo Bagnara25777432010-08-11 22:01:17 +00008150 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008151 Sema::LookupOrdinaryName);
8152
8153 // Transform all the decls.
8154 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8155 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008156 NamedDecl *InstD = static_cast<NamedDecl*>(
8157 getDerived().TransformDecl(Old->getMemberLoc(),
8158 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008159 if (!InstD) {
8160 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8161 // This can happen because of dependent hiding.
8162 if (isa<UsingShadowDecl>(*I))
8163 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008164 else {
8165 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008166 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008167 }
John McCall9f54ad42009-12-10 09:41:52 +00008168 }
John McCall129e2df2009-11-30 22:42:35 +00008169
8170 // Expand using declarations.
8171 if (isa<UsingDecl>(InstD)) {
8172 UsingDecl *UD = cast<UsingDecl>(InstD);
8173 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8174 E = UD->shadow_end(); I != E; ++I)
8175 R.addDecl(*I);
8176 continue;
8177 }
8178
8179 R.addDecl(InstD);
8180 }
8181
8182 R.resolveKind();
8183
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008184 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008185 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008186 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008187 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008188 Old->getMemberLoc(),
8189 Old->getNamingClass()));
8190 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008191 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008192
Douglas Gregor66c45152010-04-27 16:10:10 +00008193 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008194 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008195
John McCall129e2df2009-11-30 22:42:35 +00008196 TemplateArgumentListInfo TransArgs;
8197 if (Old->hasExplicitTemplateArgs()) {
8198 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8199 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008200 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8201 Old->getNumTemplateArgs(),
8202 TransArgs))
8203 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008204 }
John McCallc2233c52010-01-15 08:34:02 +00008205
8206 // FIXME: to do this check properly, we will need to preserve the
8207 // first-qualifier-in-scope here, just in case we had a dependent
8208 // base (and therefore couldn't do the check) and a
8209 // nested-name-qualifier (and therefore could do the lookup).
8210 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008211
John McCall9ae2f072010-08-23 23:25:46 +00008212 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008213 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008214 Old->getOperatorLoc(),
8215 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008216 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008217 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008218 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008219 R,
8220 (Old->hasExplicitTemplateArgs()
8221 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008222}
8223
8224template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008225ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008226TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008227 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008228 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8229 if (SubExpr.isInvalid())
8230 return ExprError();
8231
8232 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008233 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008234
8235 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8236}
8237
8238template<typename Derived>
8239ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008240TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008241 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8242 if (Pattern.isInvalid())
8243 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008244
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008245 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8246 return SemaRef.Owned(E);
8247
Douglas Gregor67fd1252011-01-14 21:20:45 +00008248 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8249 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008250}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008251
8252template<typename Derived>
8253ExprResult
8254TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8255 // If E is not value-dependent, then nothing will change when we transform it.
8256 // Note: This is an instantiation-centric view.
8257 if (!E->isValueDependent())
8258 return SemaRef.Owned(E);
8259
8260 // Note: None of the implementations of TryExpandParameterPacks can ever
8261 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008262 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008263 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8264 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008265 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008266 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008267 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008268 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008269 ShouldExpand, RetainExpansion,
8270 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008271 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008272
Douglas Gregor089e8932011-10-10 18:59:29 +00008273 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008274 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008275
Douglas Gregor089e8932011-10-10 18:59:29 +00008276 NamedDecl *Pack = E->getPack();
8277 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008278 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008279 Pack));
8280 if (!Pack)
8281 return ExprError();
8282 }
8283
Chad Rosier4a9d7952012-08-08 18:46:20 +00008284
Douglas Gregoree8aff02011-01-04 17:33:58 +00008285 // We now know the length of the parameter pack, so build a new expression
8286 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008287 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8288 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008289 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008290}
8291
Douglas Gregorbe230c32011-01-03 17:17:50 +00008292template<typename Derived>
8293ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008294TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8295 SubstNonTypeTemplateParmPackExpr *E) {
8296 // Default behavior is to do nothing with this transformation.
8297 return SemaRef.Owned(E);
8298}
8299
8300template<typename Derived>
8301ExprResult
John McCall91a57552011-07-15 05:09:51 +00008302TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8303 SubstNonTypeTemplateParmExpr *E) {
8304 // Default behavior is to do nothing with this transformation.
8305 return SemaRef.Owned(E);
8306}
8307
8308template<typename Derived>
8309ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008310TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8311 // Default behavior is to do nothing with this transformation.
8312 return SemaRef.Owned(E);
8313}
8314
8315template<typename Derived>
8316ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008317TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8318 MaterializeTemporaryExpr *E) {
8319 return getDerived().TransformExpr(E->GetTemporaryExpr());
8320}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008321
Douglas Gregor03e80032011-06-21 17:03:29 +00008322template<typename Derived>
8323ExprResult
John McCall454feb92009-12-08 09:21:05 +00008324TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008325 return SemaRef.MaybeBindToTemporary(E);
8326}
8327
8328template<typename Derived>
8329ExprResult
8330TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008331 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008332}
8333
8334template<typename Derived>
8335ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008336TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8337 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8338 if (SubExpr.isInvalid())
8339 return ExprError();
8340
8341 if (!getDerived().AlwaysRebuild() &&
8342 SubExpr.get() == E->getSubExpr())
8343 return SemaRef.Owned(E);
8344
8345 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008346}
8347
8348template<typename Derived>
8349ExprResult
8350TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8351 // Transform each of the elements.
8352 llvm::SmallVector<Expr *, 8> Elements;
8353 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008354 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008355 /*IsCall=*/false, Elements, &ArgChanged))
8356 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008357
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008358 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8359 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008360
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008361 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8362 Elements.data(),
8363 Elements.size());
8364}
8365
8366template<typename Derived>
8367ExprResult
8368TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008369 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008370 // Transform each of the elements.
8371 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8372 bool ArgChanged = false;
8373 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8374 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008375
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008376 if (OrigElement.isPackExpansion()) {
8377 // This key/value element is a pack expansion.
8378 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8379 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8380 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8381 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8382
8383 // Determine whether the set of unexpanded parameter packs can
8384 // and should be expanded.
8385 bool Expand = true;
8386 bool RetainExpansion = false;
8387 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8388 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8389 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8390 OrigElement.Value->getLocEnd());
8391 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8392 PatternRange,
8393 Unexpanded,
8394 Expand, RetainExpansion,
8395 NumExpansions))
8396 return ExprError();
8397
8398 if (!Expand) {
8399 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008400 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008401 // expansion.
8402 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8403 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8404 if (Key.isInvalid())
8405 return ExprError();
8406
8407 if (Key.get() != OrigElement.Key)
8408 ArgChanged = true;
8409
8410 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8411 if (Value.isInvalid())
8412 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008413
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008414 if (Value.get() != OrigElement.Value)
8415 ArgChanged = true;
8416
Chad Rosier4a9d7952012-08-08 18:46:20 +00008417 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008418 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8419 };
8420 Elements.push_back(Expansion);
8421 continue;
8422 }
8423
8424 // Record right away that the argument was changed. This needs
8425 // to happen even if the array expands to nothing.
8426 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008427
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008428 // The transform has determined that we should perform an elementwise
8429 // expansion of the pattern. Do so.
8430 for (unsigned I = 0; I != *NumExpansions; ++I) {
8431 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8432 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8433 if (Key.isInvalid())
8434 return ExprError();
8435
8436 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8437 if (Value.isInvalid())
8438 return ExprError();
8439
Chad Rosier4a9d7952012-08-08 18:46:20 +00008440 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008441 Key.get(), Value.get(), SourceLocation(), NumExpansions
8442 };
8443
8444 // If any unexpanded parameter packs remain, we still have a
8445 // pack expansion.
8446 if (Key.get()->containsUnexpandedParameterPack() ||
8447 Value.get()->containsUnexpandedParameterPack())
8448 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008449
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008450 Elements.push_back(Element);
8451 }
8452
8453 // We've finished with this pack expansion.
8454 continue;
8455 }
8456
8457 // Transform and check key.
8458 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8459 if (Key.isInvalid())
8460 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008461
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008462 if (Key.get() != OrigElement.Key)
8463 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008464
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008465 // Transform and check value.
8466 ExprResult Value
8467 = getDerived().TransformExpr(OrigElement.Value);
8468 if (Value.isInvalid())
8469 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008470
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008471 if (Value.get() != OrigElement.Value)
8472 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008473
8474 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008475 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8476 };
8477 Elements.push_back(Element);
8478 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008479
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008480 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8481 return SemaRef.MaybeBindToTemporary(E);
8482
8483 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8484 Elements.data(),
8485 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008486}
8487
Mike Stump1eb44332009-09-09 15:08:12 +00008488template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008489ExprResult
John McCall454feb92009-12-08 09:21:05 +00008490TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008491 TypeSourceInfo *EncodedTypeInfo
8492 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8493 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008494 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008495
Douglas Gregorb98b1992009-08-11 05:31:07 +00008496 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008497 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008498 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008499
8500 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008501 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008502 E->getRParenLoc());
8503}
Mike Stump1eb44332009-09-09 15:08:12 +00008504
Douglas Gregorb98b1992009-08-11 05:31:07 +00008505template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008506ExprResult TreeTransform<Derived>::
8507TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8508 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8509 if (result.isInvalid()) return ExprError();
8510 Expr *subExpr = result.take();
8511
8512 if (!getDerived().AlwaysRebuild() &&
8513 subExpr == E->getSubExpr())
8514 return SemaRef.Owned(E);
8515
8516 return SemaRef.Owned(new(SemaRef.Context)
8517 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8518}
8519
8520template<typename Derived>
8521ExprResult TreeTransform<Derived>::
8522TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008523 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008524 = getDerived().TransformType(E->getTypeInfoAsWritten());
8525 if (!TSInfo)
8526 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008527
John McCallf85e1932011-06-15 23:02:42 +00008528 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008529 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008530 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008531
John McCallf85e1932011-06-15 23:02:42 +00008532 if (!getDerived().AlwaysRebuild() &&
8533 TSInfo == E->getTypeInfoAsWritten() &&
8534 Result.get() == E->getSubExpr())
8535 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008536
John McCallf85e1932011-06-15 23:02:42 +00008537 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008538 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008539 Result.get());
8540}
8541
8542template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008543ExprResult
John McCall454feb92009-12-08 09:21:05 +00008544TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008545 // Transform arguments.
8546 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008547 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008548 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008549 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008550 &ArgChanged))
8551 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008552
Douglas Gregor92e986e2010-04-22 16:44:27 +00008553 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8554 // Class message: transform the receiver type.
8555 TypeSourceInfo *ReceiverTypeInfo
8556 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8557 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008558 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008559
Douglas Gregor92e986e2010-04-22 16:44:27 +00008560 // If nothing changed, just retain the existing message send.
8561 if (!getDerived().AlwaysRebuild() &&
8562 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008563 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008564
8565 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008566 SmallVector<SourceLocation, 16> SelLocs;
8567 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008568 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8569 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008570 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008571 E->getMethodDecl(),
8572 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008573 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008574 E->getRightLoc());
8575 }
8576
8577 // Instance message: transform the receiver
8578 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8579 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008580 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008581 = getDerived().TransformExpr(E->getInstanceReceiver());
8582 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008583 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008584
8585 // If nothing changed, just retain the existing message send.
8586 if (!getDerived().AlwaysRebuild() &&
8587 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008588 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008589
Douglas Gregor92e986e2010-04-22 16:44:27 +00008590 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008591 SmallVector<SourceLocation, 16> SelLocs;
8592 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008593 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008594 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008595 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008596 E->getMethodDecl(),
8597 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008598 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008599 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008600}
8601
Mike Stump1eb44332009-09-09 15:08:12 +00008602template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008603ExprResult
John McCall454feb92009-12-08 09:21:05 +00008604TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008605 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008606}
8607
Mike Stump1eb44332009-09-09 15:08:12 +00008608template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008609ExprResult
John McCall454feb92009-12-08 09:21:05 +00008610TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008611 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008612}
8613
Mike Stump1eb44332009-09-09 15:08:12 +00008614template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008615ExprResult
John McCall454feb92009-12-08 09:21:05 +00008616TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008617 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008618 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008619 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008620 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008621
8622 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008623
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008624 // If nothing changed, just retain the existing expression.
8625 if (!getDerived().AlwaysRebuild() &&
8626 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008627 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008628
John McCall9ae2f072010-08-23 23:25:46 +00008629 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008630 E->getLocation(),
8631 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008632}
8633
Mike Stump1eb44332009-09-09 15:08:12 +00008634template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008635ExprResult
John McCall454feb92009-12-08 09:21:05 +00008636TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008637 // 'super' and types never change. Property never changes. Just
8638 // retain the existing expression.
8639 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008640 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008641
Douglas Gregore3303542010-04-26 20:47:02 +00008642 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008643 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008644 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008645 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008646
Douglas Gregore3303542010-04-26 20:47:02 +00008647 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008648
Douglas Gregore3303542010-04-26 20:47:02 +00008649 // If nothing changed, just retain the existing expression.
8650 if (!getDerived().AlwaysRebuild() &&
8651 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008652 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008653
John McCall12f78a62010-12-02 01:19:52 +00008654 if (E->isExplicitProperty())
8655 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8656 E->getExplicitProperty(),
8657 E->getLocation());
8658
8659 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008660 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008661 E->getImplicitPropertyGetter(),
8662 E->getImplicitPropertySetter(),
8663 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008664}
8665
Mike Stump1eb44332009-09-09 15:08:12 +00008666template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008667ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008668TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8669 // Transform the base expression.
8670 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8671 if (Base.isInvalid())
8672 return ExprError();
8673
8674 // Transform the key expression.
8675 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8676 if (Key.isInvalid())
8677 return ExprError();
8678
8679 // If nothing changed, just retain the existing expression.
8680 if (!getDerived().AlwaysRebuild() &&
8681 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8682 return SemaRef.Owned(E);
8683
Chad Rosier4a9d7952012-08-08 18:46:20 +00008684 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008685 Base.get(), Key.get(),
8686 E->getAtIndexMethodDecl(),
8687 E->setAtIndexMethodDecl());
8688}
8689
8690template<typename Derived>
8691ExprResult
John McCall454feb92009-12-08 09:21:05 +00008692TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008693 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008694 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008695 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008696 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008697
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008698 // If nothing changed, just retain the existing expression.
8699 if (!getDerived().AlwaysRebuild() &&
8700 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008701 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008702
John McCall9ae2f072010-08-23 23:25:46 +00008703 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008704 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008705}
8706
Mike Stump1eb44332009-09-09 15:08:12 +00008707template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008708ExprResult
John McCall454feb92009-12-08 09:21:05 +00008709TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008710 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008711 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008712 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008713 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008714 SubExprs, &ArgumentChanged))
8715 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008716
Douglas Gregorb98b1992009-08-11 05:31:07 +00008717 if (!getDerived().AlwaysRebuild() &&
8718 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008719 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008720
Douglas Gregorb98b1992009-08-11 05:31:07 +00008721 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008722 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008723 E->getRParenLoc());
8724}
8725
Mike Stump1eb44332009-09-09 15:08:12 +00008726template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008727ExprResult
John McCall454feb92009-12-08 09:21:05 +00008728TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008729 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008730
John McCallc6ac9c32011-02-04 18:33:18 +00008731 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8732 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8733
8734 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008735 blockScope->TheDecl->setBlockMissingReturnType(
8736 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008737
Chris Lattner686775d2011-07-20 06:58:45 +00008738 SmallVector<ParmVarDecl*, 4> params;
8739 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008740
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008741 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008742 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8743 oldBlock->param_begin(),
8744 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008745 0, paramTypes, &params)) {
8746 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008747 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008748 }
John McCallc6ac9c32011-02-04 18:33:18 +00008749
8750 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008751 QualType exprResultType =
8752 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008753
8754 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008755 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008756 getSema().Diag(E->getCaretLocation(),
8757 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008758 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008759 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008760 return ExprError();
8761 }
John McCall711c52b2011-01-05 12:14:39 +00008762
John McCallc6ac9c32011-02-04 18:33:18 +00008763 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008764 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008765 paramTypes.data(),
8766 paramTypes.size(),
8767 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008768 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008769 exprFunctionType->getExtInfo());
8770 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008771
8772 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008773 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008774 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008775
8776 if (!oldBlock->blockMissingReturnType()) {
8777 blockScope->HasImplicitReturnType = false;
8778 blockScope->ReturnType = exprResultType;
8779 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008780
John McCall711c52b2011-01-05 12:14:39 +00008781 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008782 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008783 if (body.isInvalid()) {
8784 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008785 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008786 }
John McCall711c52b2011-01-05 12:14:39 +00008787
John McCallc6ac9c32011-02-04 18:33:18 +00008788#ifndef NDEBUG
8789 // In builds with assertions, make sure that we captured everything we
8790 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008791 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8792 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8793 e = oldBlock->capture_end(); i != e; ++i) {
8794 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008795
Douglas Gregorfc921372011-05-20 15:32:55 +00008796 // Ignore parameter packs.
8797 if (isa<ParmVarDecl>(oldCapture) &&
8798 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8799 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008800
Douglas Gregorfc921372011-05-20 15:32:55 +00008801 VarDecl *newCapture =
8802 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8803 oldCapture));
8804 assert(blockScope->CaptureMap.count(newCapture));
8805 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008806 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008807 }
8808#endif
8809
8810 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8811 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008812}
8813
Mike Stump1eb44332009-09-09 15:08:12 +00008814template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008815ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008816TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008817 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008818}
Eli Friedman276b0612011-10-11 02:20:01 +00008819
8820template<typename Derived>
8821ExprResult
8822TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008823 QualType RetTy = getDerived().TransformType(E->getType());
8824 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008825 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008826 SubExprs.reserve(E->getNumSubExprs());
8827 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8828 SubExprs, &ArgumentChanged))
8829 return ExprError();
8830
8831 if (!getDerived().AlwaysRebuild() &&
8832 !ArgumentChanged)
8833 return SemaRef.Owned(E);
8834
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008835 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008836 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008837}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008838
Douglas Gregorb98b1992009-08-11 05:31:07 +00008839//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008840// Type reconstruction
8841//===----------------------------------------------------------------------===//
8842
Mike Stump1eb44332009-09-09 15:08:12 +00008843template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008844QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8845 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008846 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008847 getDerived().getBaseEntity());
8848}
8849
Mike Stump1eb44332009-09-09 15:08:12 +00008850template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008851QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8852 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008853 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008854 getDerived().getBaseEntity());
8855}
8856
Mike Stump1eb44332009-09-09 15:08:12 +00008857template<typename Derived>
8858QualType
John McCall85737a72009-10-30 00:06:24 +00008859TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8860 bool WrittenAsLValue,
8861 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008862 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008863 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008864}
8865
8866template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008867QualType
John McCall85737a72009-10-30 00:06:24 +00008868TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8869 QualType ClassType,
8870 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008871 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008872 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008873}
8874
8875template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008876QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008877TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8878 ArrayType::ArraySizeModifier SizeMod,
8879 const llvm::APInt *Size,
8880 Expr *SizeExpr,
8881 unsigned IndexTypeQuals,
8882 SourceRange BracketsRange) {
8883 if (SizeExpr || !Size)
8884 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8885 IndexTypeQuals, BracketsRange,
8886 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008887
8888 QualType Types[] = {
8889 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8890 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8891 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008892 };
8893 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8894 QualType SizeType;
8895 for (unsigned I = 0; I != NumTypes; ++I)
8896 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8897 SizeType = Types[I];
8898 break;
8899 }
Mike Stump1eb44332009-09-09 15:08:12 +00008900
Eli Friedman01f276d2012-01-25 23:20:27 +00008901 // Note that we can return a VariableArrayType here in the case where
8902 // the element type was a dependent VariableArrayType.
8903 IntegerLiteral *ArraySize
8904 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8905 /*FIXME*/BracketsRange.getBegin());
8906 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008907 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008908 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008909}
Mike Stump1eb44332009-09-09 15:08:12 +00008910
Douglas Gregor577f75a2009-08-04 16:50:30 +00008911template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008912QualType
8913TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008914 ArrayType::ArraySizeModifier SizeMod,
8915 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008916 unsigned IndexTypeQuals,
8917 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008918 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008919 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008920}
8921
8922template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008923QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008924TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008925 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008926 unsigned IndexTypeQuals,
8927 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008928 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008929 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008930}
Mike Stump1eb44332009-09-09 15:08:12 +00008931
Douglas Gregor577f75a2009-08-04 16:50:30 +00008932template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008933QualType
8934TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008935 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008936 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008937 unsigned IndexTypeQuals,
8938 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008939 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008940 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008941 IndexTypeQuals, BracketsRange);
8942}
8943
8944template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008945QualType
8946TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008947 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008948 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008949 unsigned IndexTypeQuals,
8950 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008951 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008952 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008953 IndexTypeQuals, BracketsRange);
8954}
8955
8956template<typename Derived>
8957QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008958 unsigned NumElements,
8959 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008960 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008961 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008962}
Mike Stump1eb44332009-09-09 15:08:12 +00008963
Douglas Gregor577f75a2009-08-04 16:50:30 +00008964template<typename Derived>
8965QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8966 unsigned NumElements,
8967 SourceLocation AttributeLoc) {
8968 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8969 NumElements, true);
8970 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008971 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8972 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008973 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008974}
Mike Stump1eb44332009-09-09 15:08:12 +00008975
Douglas Gregor577f75a2009-08-04 16:50:30 +00008976template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008977QualType
8978TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008979 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008980 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008981 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008982}
Mike Stump1eb44332009-09-09 15:08:12 +00008983
Douglas Gregor577f75a2009-08-04 16:50:30 +00008984template<typename Derived>
8985QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008986 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008987 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008988 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008989 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00008990 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008991 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008992 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008993 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008994 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008995 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008996 getDerived().getBaseEntity(),
8997 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008998}
Mike Stump1eb44332009-09-09 15:08:12 +00008999
Douglas Gregor577f75a2009-08-04 16:50:30 +00009000template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009001QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9002 return SemaRef.Context.getFunctionNoProtoType(T);
9003}
9004
9005template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009006QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9007 assert(D && "no decl found");
9008 if (D->isInvalidDecl()) return QualType();
9009
Douglas Gregor92e986e2010-04-22 16:44:27 +00009010 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009011 TypeDecl *Ty;
9012 if (isa<UsingDecl>(D)) {
9013 UsingDecl *Using = cast<UsingDecl>(D);
9014 assert(Using->isTypeName() &&
9015 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9016
9017 // A valid resolved using typename decl points to exactly one type decl.
9018 assert(++Using->shadow_begin() == Using->shadow_end());
9019 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009020
John McCalled976492009-12-04 22:46:56 +00009021 } else {
9022 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9023 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9024 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9025 }
9026
9027 return SemaRef.Context.getTypeDeclType(Ty);
9028}
9029
9030template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009031QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9032 SourceLocation Loc) {
9033 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009034}
9035
9036template<typename Derived>
9037QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9038 return SemaRef.Context.getTypeOfType(Underlying);
9039}
9040
9041template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009042QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9043 SourceLocation Loc) {
9044 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009045}
9046
9047template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009048QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9049 UnaryTransformType::UTTKind UKind,
9050 SourceLocation Loc) {
9051 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9052}
9053
9054template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009055QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009056 TemplateName Template,
9057 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009058 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009059 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009060}
Mike Stump1eb44332009-09-09 15:08:12 +00009061
Douglas Gregordcee1a12009-08-06 05:28:30 +00009062template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009063QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9064 SourceLocation KWLoc) {
9065 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9066}
9067
9068template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009069TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009070TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009071 bool TemplateKW,
9072 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009073 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009074 Template);
9075}
9076
9077template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009078TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009079TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9080 const IdentifierInfo &Name,
9081 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009082 QualType ObjectType,
9083 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009084 UnqualifiedId TemplateName;
9085 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009086 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009087 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009088 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009089 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009090 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009091 /*EnteringContext=*/false,
9092 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009093 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009094}
Mike Stump1eb44332009-09-09 15:08:12 +00009095
Douglas Gregorb98b1992009-08-11 05:31:07 +00009096template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009097TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009098TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009099 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009100 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009101 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009102 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009103 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009104 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009105 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009106 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009107 Sema::TemplateTy Template;
9108 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009109 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009110 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009111 /*EnteringContext=*/false,
9112 Template);
9113 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009114}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009115
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009116template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009117ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009118TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9119 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009120 Expr *OrigCallee,
9121 Expr *First,
9122 Expr *Second) {
9123 Expr *Callee = OrigCallee->IgnoreParenCasts();
9124 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009125
Douglas Gregorb98b1992009-08-11 05:31:07 +00009126 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009127 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009128 if (!First->getType()->isOverloadableType() &&
9129 !Second->getType()->isOverloadableType())
9130 return getSema().CreateBuiltinArraySubscriptExpr(First,
9131 Callee->getLocStart(),
9132 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009133 } else if (Op == OO_Arrow) {
9134 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009135 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9136 } else if (Second == 0 || isPostIncDec) {
9137 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009138 // The argument is not of overloadable type, so try to create a
9139 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009140 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009141 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009142
John McCall9ae2f072010-08-23 23:25:46 +00009143 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009144 }
9145 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009146 if (!First->getType()->isOverloadableType() &&
9147 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009148 // Neither of the arguments is an overloadable type, so try to
9149 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009150 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009151 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009152 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009153 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009154 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009155
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009156 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009157 }
9158 }
Mike Stump1eb44332009-09-09 15:08:12 +00009159
9160 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009161 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009162 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009163
John McCall9ae2f072010-08-23 23:25:46 +00009164 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009165 assert(ULE->requiresADL());
9166
9167 // FIXME: Do we have to check
9168 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009169 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009170 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009171 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00009172 }
Mike Stump1eb44332009-09-09 15:08:12 +00009173
Douglas Gregorb98b1992009-08-11 05:31:07 +00009174 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009175 Expr *Args[2] = { First, Second };
9176 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009177
Douglas Gregorb98b1992009-08-11 05:31:07 +00009178 // Create the overloaded operator invocation for unary operators.
9179 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009180 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009181 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009182 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009183 }
Mike Stump1eb44332009-09-09 15:08:12 +00009184
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009185 if (Op == OO_Subscript) {
9186 SourceLocation LBrace;
9187 SourceLocation RBrace;
9188
9189 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9190 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9191 LBrace = SourceLocation::getFromRawEncoding(
9192 NameLoc.CXXOperatorName.BeginOpNameLoc);
9193 RBrace = SourceLocation::getFromRawEncoding(
9194 NameLoc.CXXOperatorName.EndOpNameLoc);
9195 } else {
9196 LBrace = Callee->getLocStart();
9197 RBrace = OpLoc;
9198 }
9199
9200 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9201 First, Second);
9202 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009203
Douglas Gregorb98b1992009-08-11 05:31:07 +00009204 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009205 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009206 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009207 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9208 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009209 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009210
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009211 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009212}
Mike Stump1eb44332009-09-09 15:08:12 +00009213
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009214template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009215ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009216TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009217 SourceLocation OperatorLoc,
9218 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009219 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009220 TypeSourceInfo *ScopeType,
9221 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009222 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009223 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009224 QualType BaseType = Base->getType();
9225 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009226 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009227 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009228 !BaseType->getAs<PointerType>()->getPointeeType()
9229 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009230 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009231 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009232 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009233 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009234 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009235 /*FIXME?*/true);
9236 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009237
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009238 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009239 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9240 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9241 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9242 NameInfo.setNamedTypeInfo(DestroyedType);
9243
Richard Smith6314db92012-05-15 06:15:11 +00009244 // The scope type is now known to be a valid nested name specifier
9245 // component. Tack it on to the end of the nested name specifier.
9246 if (ScopeType)
9247 SS.Extend(SemaRef.Context, SourceLocation(),
9248 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009249
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009250 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009251 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009252 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009253 SS, TemplateKWLoc,
9254 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009255 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009256 /*TemplateArgs*/ 0);
9257}
9258
Douglas Gregor577f75a2009-08-04 16:50:30 +00009259} // end namespace clang
9260
9261#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H