blob: 4b780f6bc0fdab3d2bfe795d42ce9a620f7915b4 [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
Douglas Gregor43959a92009-08-20 07:17:43 +0000577#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000578 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000579#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000580 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000581#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000582#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000583
Douglas Gregor577f75a2009-08-04 16:50:30 +0000584 /// \brief Build a new pointer type given its pointee type.
585 ///
586 /// By default, performs semantic analysis when building the pointer type.
587 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000588 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000589
590 /// \brief Build a new block pointer type given its pointee type.
591 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000592 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000593 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000594 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000595
John McCall85737a72009-10-30 00:06:24 +0000596 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000597 ///
John McCall85737a72009-10-30 00:06:24 +0000598 /// By default, performs semantic analysis when building the
599 /// reference type. Subclasses may override this routine to provide
600 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000601 ///
John McCall85737a72009-10-30 00:06:24 +0000602 /// \param LValue whether the type was written with an lvalue sigil
603 /// or an rvalue sigil.
604 QualType RebuildReferenceType(QualType ReferentType,
605 bool LValue,
606 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000607
Douglas Gregor577f75a2009-08-04 16:50:30 +0000608 /// \brief Build a new member pointer type given the pointee type and the
609 /// class type it refers into.
610 ///
611 /// By default, performs semantic analysis when building the member pointer
612 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000613 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
614 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000615
Douglas Gregor577f75a2009-08-04 16:50:30 +0000616 /// \brief Build a new array type given the element type, size
617 /// modifier, size of the array (if known), size expression, and index type
618 /// qualifiers.
619 ///
620 /// By default, performs semantic analysis when building the array type.
621 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000622 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000623 QualType RebuildArrayType(QualType ElementType,
624 ArrayType::ArraySizeModifier SizeMod,
625 const llvm::APInt *Size,
626 Expr *SizeExpr,
627 unsigned IndexTypeQuals,
628 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000629
Douglas Gregor577f75a2009-08-04 16:50:30 +0000630 /// \brief Build a new constant array type given the element type, size
631 /// modifier, (known) size of the array, and index type qualifiers.
632 ///
633 /// By default, performs semantic analysis when building the array type.
634 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000635 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636 ArrayType::ArraySizeModifier SizeMod,
637 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000638 unsigned IndexTypeQuals,
639 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000640
Douglas Gregor577f75a2009-08-04 16:50:30 +0000641 /// \brief Build a new incomplete array type given the element type, size
642 /// modifier, and index type qualifiers.
643 ///
644 /// By default, performs semantic analysis when building the array type.
645 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000646 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000647 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000648 unsigned IndexTypeQuals,
649 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000650
Mike Stump1eb44332009-09-09 15:08:12 +0000651 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000652 /// size modifier, size expression, and index type qualifiers.
653 ///
654 /// By default, performs semantic analysis when building the array type.
655 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000656 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000657 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000658 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000659 unsigned IndexTypeQuals,
660 SourceRange BracketsRange);
661
Mike Stump1eb44332009-09-09 15:08:12 +0000662 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663 /// size modifier, size expression, and index type qualifiers.
664 ///
665 /// By default, performs semantic analysis when building the array type.
666 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000667 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000668 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000669 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000670 unsigned IndexTypeQuals,
671 SourceRange BracketsRange);
672
673 /// \brief Build a new vector type given the element type and
674 /// number of elements.
675 ///
676 /// By default, performs semantic analysis when building the vector type.
677 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000678 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000679 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000680
Douglas Gregor577f75a2009-08-04 16:50:30 +0000681 /// \brief Build a new extended vector type given the element type and
682 /// number of elements.
683 ///
684 /// By default, performs semantic analysis when building the vector type.
685 /// Subclasses may override this routine to provide different behavior.
686 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
687 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000688
689 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000690 /// given the element type and number of elements.
691 ///
692 /// By default, performs semantic analysis when building the vector type.
693 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000694 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000695 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000696 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000697
Douglas Gregor577f75a2009-08-04 16:50:30 +0000698 /// \brief Build a new function type.
699 ///
700 /// By default, performs semantic analysis when building the function type.
701 /// Subclasses may override this routine to provide different behavior.
702 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000703 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000704 unsigned NumParamTypes,
Richard Smitheefb3d52012-02-10 09:58:53 +0000705 bool Variadic, bool HasTrailingReturn,
706 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000707 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000708 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000709
John McCalla2becad2009-10-21 00:40:46 +0000710 /// \brief Build a new unprototyped function type.
711 QualType RebuildFunctionNoProtoType(QualType ResultType);
712
John McCalled976492009-12-04 22:46:56 +0000713 /// \brief Rebuild an unresolved typename type, given the decl that
714 /// the UnresolvedUsingTypenameDecl was transformed to.
715 QualType RebuildUnresolvedUsingType(Decl *D);
716
Douglas Gregor577f75a2009-08-04 16:50:30 +0000717 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000718 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000719 return SemaRef.Context.getTypeDeclType(Typedef);
720 }
721
722 /// \brief Build a new class/struct/union type.
723 QualType RebuildRecordType(RecordDecl *Record) {
724 return SemaRef.Context.getTypeDeclType(Record);
725 }
726
727 /// \brief Build a new Enum type.
728 QualType RebuildEnumType(EnumDecl *Enum) {
729 return SemaRef.Context.getTypeDeclType(Enum);
730 }
John McCall7da24312009-09-05 00:15:47 +0000731
Mike Stump1eb44332009-09-09 15:08:12 +0000732 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000733 ///
734 /// By default, performs semantic analysis when building the typeof type.
735 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000736 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000737
Mike Stump1eb44332009-09-09 15:08:12 +0000738 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000739 ///
740 /// By default, builds a new TypeOfType with the given underlying type.
741 QualType RebuildTypeOfType(QualType Underlying);
742
Sean Huntca63c202011-05-24 22:41:36 +0000743 /// \brief Build a new unary transform type.
744 QualType RebuildUnaryTransformType(QualType BaseType,
745 UnaryTransformType::UTTKind UKind,
746 SourceLocation Loc);
747
Mike Stump1eb44332009-09-09 15:08:12 +0000748 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000749 ///
750 /// By default, performs semantic analysis when building the decltype type.
751 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000752 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000753
Richard Smith34b41d92011-02-20 03:19:35 +0000754 /// \brief Build a new C++0x auto type.
755 ///
756 /// By default, builds a new AutoType with the given deduced type.
757 QualType RebuildAutoType(QualType Deduced) {
758 return SemaRef.Context.getAutoType(Deduced);
759 }
760
Douglas Gregor577f75a2009-08-04 16:50:30 +0000761 /// \brief Build a new template specialization type.
762 ///
763 /// By default, performs semantic analysis when building the template
764 /// specialization type. Subclasses may override this routine to provide
765 /// different behavior.
766 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000767 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000768 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000769
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000770 /// \brief Build a new parenthesized type.
771 ///
772 /// By default, builds a new ParenType type from the inner type.
773 /// Subclasses may override this routine to provide different behavior.
774 QualType RebuildParenType(QualType InnerType) {
775 return SemaRef.Context.getParenType(InnerType);
776 }
777
Douglas Gregor577f75a2009-08-04 16:50:30 +0000778 /// \brief Build a new qualified name type.
779 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000780 /// By default, builds a new ElaboratedType type from the keyword,
781 /// the nested-name-specifier and the named type.
782 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000783 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
784 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000785 NestedNameSpecifierLoc QualifierLoc,
786 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000787 return SemaRef.Context.getElaboratedType(Keyword,
788 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000789 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000790 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000791
792 /// \brief Build a new typename type that refers to a template-id.
793 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000794 /// By default, builds a new DependentNameType type from the
795 /// nested-name-specifier and the given type. Subclasses may override
796 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000797 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000798 ElaboratedTypeKeyword Keyword,
799 NestedNameSpecifierLoc QualifierLoc,
800 const IdentifierInfo *Name,
801 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000802 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000803 // Rebuild the template name.
804 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000805 CXXScopeSpec SS;
806 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000807 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000808 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000809
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000810 if (InstName.isNull())
811 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000812
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000813 // If it's still dependent, make a dependent specialization.
814 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000815 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
816 QualifierLoc.getNestedNameSpecifier(),
817 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000818 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000819
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000820 // Otherwise, make an elaborated type wrapping a non-dependent
821 // specialization.
822 QualType T =
823 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
824 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000825
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000826 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
827 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000828
829 return SemaRef.Context.getElaboratedType(Keyword,
830 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000831 T);
832 }
833
Douglas Gregor577f75a2009-08-04 16:50:30 +0000834 /// \brief Build a new typename type that refers to an identifier.
835 ///
836 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000837 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000838 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000839 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000840 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000841 NestedNameSpecifierLoc QualifierLoc,
842 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000843 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000844 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000845 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000846
Douglas Gregor2494dd02011-03-01 01:34:45 +0000847 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000848 // If the name is still dependent, just build a new dependent name type.
849 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000850 return SemaRef.Context.getDependentNameType(Keyword,
851 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000852 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000853 }
854
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000855 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000856 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000857 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000858
859 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
860
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000861 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000862 // into a non-dependent elaborated-type-specifier. Find the tag we're
863 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000864 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000865 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
866 if (!DC)
867 return QualType();
868
John McCall56138762010-05-27 06:40:31 +0000869 if (SemaRef.RequireCompleteDeclContext(SS, DC))
870 return QualType();
871
Douglas Gregor40336422010-03-31 22:19:08 +0000872 TagDecl *Tag = 0;
873 SemaRef.LookupQualifiedName(Result, DC);
874 switch (Result.getResultKind()) {
875 case LookupResult::NotFound:
876 case LookupResult::NotFoundInCurrentInstantiation:
877 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000878
Douglas Gregor40336422010-03-31 22:19:08 +0000879 case LookupResult::Found:
880 Tag = Result.getAsSingle<TagDecl>();
881 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000882
Douglas Gregor40336422010-03-31 22:19:08 +0000883 case LookupResult::FoundOverloaded:
884 case LookupResult::FoundUnresolvedValue:
885 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000886
Douglas Gregor40336422010-03-31 22:19:08 +0000887 case LookupResult::Ambiguous:
888 // Let the LookupResult structure handle ambiguities.
889 return QualType();
890 }
891
892 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000893 // Check where the name exists but isn't a tag type and use that to emit
894 // better diagnostics.
895 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
896 SemaRef.LookupQualifiedName(Result, DC);
897 switch (Result.getResultKind()) {
898 case LookupResult::Found:
899 case LookupResult::FoundOverloaded:
900 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000901 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000902 unsigned Kind = 0;
903 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000904 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
905 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000906 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
907 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
908 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000909 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000910 default:
911 // FIXME: Would be nice to highlight just the source range.
912 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
913 << Kind << Id << DC;
914 break;
915 }
Douglas Gregor40336422010-03-31 22:19:08 +0000916 return QualType();
917 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000918
Richard Trieubbf34c02011-06-10 03:11:26 +0000919 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
920 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000921 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000922 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
923 return QualType();
924 }
925
926 // Build the elaborated-type-specifier type.
927 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000928 return SemaRef.Context.getElaboratedType(Keyword,
929 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000930 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000931 }
Mike Stump1eb44332009-09-09 15:08:12 +0000932
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000933 /// \brief Build a new pack expansion type.
934 ///
935 /// By default, builds a new PackExpansionType type from the given pattern.
936 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000937 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000938 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000939 SourceLocation EllipsisLoc,
940 llvm::Optional<unsigned> NumExpansions) {
941 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
942 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000943 }
944
Eli Friedmanb001de72011-10-06 23:00:33 +0000945 /// \brief Build a new atomic type given its value type.
946 ///
947 /// By default, performs semantic analysis when building the atomic type.
948 /// Subclasses may override this routine to provide different behavior.
949 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
950
Douglas Gregord1067e52009-08-06 06:41:21 +0000951 /// \brief Build a new template name given a nested name specifier, a flag
952 /// indicating whether the "template" keyword was provided, and the template
953 /// that the template name refers to.
954 ///
955 /// By default, builds the new template name directly. Subclasses may override
956 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000957 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000958 bool TemplateKW,
959 TemplateDecl *Template);
960
Douglas Gregord1067e52009-08-06 06:41:21 +0000961 /// \brief Build a new template name given a nested name specifier and the
962 /// name that is referred to as a template.
963 ///
964 /// By default, performs semantic analysis to determine whether the name can
965 /// be resolved to a specific template, then builds the appropriate kind of
966 /// template name. Subclasses may override this routine to provide different
967 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000968 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
969 const IdentifierInfo &Name,
970 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000971 QualType ObjectType,
972 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000973
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000974 /// \brief Build a new template name given a nested name specifier and the
975 /// overloaded operator name that is referred to as a template.
976 ///
977 /// By default, performs semantic analysis to determine whether the name can
978 /// be resolved to a specific template, then builds the appropriate kind of
979 /// template name. Subclasses may override this routine to provide different
980 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000981 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000982 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000983 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000984 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000985
986 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +0000987 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000988 ///
989 /// By default, performs semantic analysis to determine whether the name can
990 /// be resolved to a specific template, then builds the appropriate kind of
991 /// template name. Subclasses may override this routine to provide different
992 /// behavior.
993 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
994 const TemplateArgument &ArgPack) {
995 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
996 }
997
Douglas Gregor43959a92009-08-20 07:17:43 +0000998 /// \brief Build a new compound statement.
999 ///
1000 /// By default, performs semantic analysis to build the new statement.
1001 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001002 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001003 MultiStmtArg Statements,
1004 SourceLocation RBraceLoc,
1005 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001006 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001007 IsStmtExpr);
1008 }
1009
1010 /// \brief Build a new case statement.
1011 ///
1012 /// By default, performs semantic analysis to build the new statement.
1013 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001014 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001015 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001016 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001017 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001018 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001019 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001020 ColonLoc);
1021 }
Mike Stump1eb44332009-09-09 15:08:12 +00001022
Douglas Gregor43959a92009-08-20 07:17:43 +00001023 /// \brief Attach the body to a new case statement.
1024 ///
1025 /// By default, performs semantic analysis to build the new statement.
1026 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001027 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001028 getSema().ActOnCaseStmtBody(S, Body);
1029 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001030 }
Mike Stump1eb44332009-09-09 15:08:12 +00001031
Douglas Gregor43959a92009-08-20 07:17:43 +00001032 /// \brief Build a new default statement.
1033 ///
1034 /// By default, performs semantic analysis to build the new statement.
1035 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001036 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001037 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001038 Stmt *SubStmt) {
1039 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001040 /*CurScope=*/0);
1041 }
Mike Stump1eb44332009-09-09 15:08:12 +00001042
Douglas Gregor43959a92009-08-20 07:17:43 +00001043 /// \brief Build a new label statement.
1044 ///
1045 /// By default, performs semantic analysis to build the new statement.
1046 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001047 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1048 SourceLocation ColonLoc, Stmt *SubStmt) {
1049 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001050 }
Mike Stump1eb44332009-09-09 15:08:12 +00001051
Richard Smith534986f2012-04-14 00:33:13 +00001052 /// \brief Build a new label statement.
1053 ///
1054 /// By default, performs semantic analysis to build the new statement.
1055 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001056 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1057 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001058 Stmt *SubStmt) {
1059 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1060 }
1061
Douglas Gregor43959a92009-08-20 07:17:43 +00001062 /// \brief Build a new "if" statement.
1063 ///
1064 /// By default, performs semantic analysis to build the new statement.
1065 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001066 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001067 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001068 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001069 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001070 }
Mike Stump1eb44332009-09-09 15:08:12 +00001071
Douglas Gregor43959a92009-08-20 07:17:43 +00001072 /// \brief Start building a new switch statement.
1073 ///
1074 /// By default, performs semantic analysis to build the new statement.
1075 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001076 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001077 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001078 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001079 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001080 }
Mike Stump1eb44332009-09-09 15:08:12 +00001081
Douglas Gregor43959a92009-08-20 07:17:43 +00001082 /// \brief Attach the body to the switch statement.
1083 ///
1084 /// By default, performs semantic analysis to build the new statement.
1085 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001086 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001087 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001088 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001089 }
1090
1091 /// \brief Build a new while statement.
1092 ///
1093 /// By default, performs semantic analysis to build the new statement.
1094 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001095 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1096 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001097 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001098 }
Mike Stump1eb44332009-09-09 15:08:12 +00001099
Douglas Gregor43959a92009-08-20 07:17:43 +00001100 /// \brief Build a new do-while statement.
1101 ///
1102 /// By default, performs semantic analysis to build the new statement.
1103 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001104 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001105 SourceLocation WhileLoc, SourceLocation LParenLoc,
1106 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001107 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1108 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001109 }
1110
1111 /// \brief Build a new for statement.
1112 ///
1113 /// By default, performs semantic analysis to build the new statement.
1114 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001115 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001116 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001117 VarDecl *CondVar, Sema::FullExprArg Inc,
1118 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001119 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001120 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001121 }
Mike Stump1eb44332009-09-09 15:08:12 +00001122
Douglas Gregor43959a92009-08-20 07:17:43 +00001123 /// \brief Build a new goto statement.
1124 ///
1125 /// By default, performs semantic analysis to build the new statement.
1126 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001127 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1128 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001129 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001130 }
1131
1132 /// \brief Build a new indirect goto statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001136 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001137 SourceLocation StarLoc,
1138 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001139 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001140 }
Mike Stump1eb44332009-09-09 15:08:12 +00001141
Douglas Gregor43959a92009-08-20 07:17:43 +00001142 /// \brief Build a new return statement.
1143 ///
1144 /// By default, performs semantic analysis to build the new statement.
1145 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001146 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001147 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001148 }
Mike Stump1eb44332009-09-09 15:08:12 +00001149
Douglas Gregor43959a92009-08-20 07:17:43 +00001150 /// \brief Build a new declaration statement.
1151 ///
1152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001154 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001155 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001156 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001157 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1158 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001159 }
Mike Stump1eb44332009-09-09 15:08:12 +00001160
Anders Carlsson703e3942010-01-24 05:50:09 +00001161 /// \brief Build a new inline asm statement.
1162 ///
1163 /// By default, performs semantic analysis to build the new statement.
1164 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001165 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1166 bool IsVolatile, unsigned NumOutputs,
1167 unsigned NumInputs, IdentifierInfo **Names,
1168 MultiExprArg Constraints, MultiExprArg Exprs,
1169 Expr *AsmString, MultiExprArg Clobbers,
1170 SourceLocation RParenLoc) {
1171 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1172 NumInputs, Names, Constraints, Exprs,
1173 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001174 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001175
Chad Rosier8cd64b42012-06-11 20:47:18 +00001176 /// \brief Build a new MS style inline asm statement.
1177 ///
1178 /// By default, performs semantic analysis to build the new statement.
1179 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001180 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
1181 ArrayRef<Token> AsmToks, SourceLocation EndLoc) {
Chad Rosier7bd092b2012-08-15 16:53:30 +00001182 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001183 }
1184
James Dennett699c9042012-06-15 07:13:21 +00001185 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001186 ///
1187 /// By default, performs semantic analysis to build the new statement.
1188 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001189 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001190 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001191 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001192 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001193 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001194 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001195 }
1196
Douglas Gregorbe270a02010-04-26 17:57:08 +00001197 /// \brief Rebuild an Objective-C exception declaration.
1198 ///
1199 /// By default, performs semantic analysis to build the new declaration.
1200 /// Subclasses may override this routine to provide different behavior.
1201 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1202 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001203 return getSema().BuildObjCExceptionDecl(TInfo, T,
1204 ExceptionDecl->getInnerLocStart(),
1205 ExceptionDecl->getLocation(),
1206 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001207 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001208
James Dennett699c9042012-06-15 07:13:21 +00001209 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001210 ///
1211 /// By default, performs semantic analysis to build the new statement.
1212 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001213 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001214 SourceLocation RParenLoc,
1215 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001216 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001217 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001218 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001219 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001220
James Dennett699c9042012-06-15 07:13:21 +00001221 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001225 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001226 Stmt *Body) {
1227 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001228 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001229
James Dennett699c9042012-06-15 07:13:21 +00001230 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001231 ///
1232 /// By default, performs semantic analysis to build the new statement.
1233 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001234 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001235 Expr *Operand) {
1236 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001237 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001238
James Dennett699c9042012-06-15 07:13:21 +00001239 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001240 ///
1241 /// By default, performs semantic analysis to build the new statement.
1242 /// Subclasses may override this routine to provide different behavior.
1243 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1244 Expr *object) {
1245 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1246 }
1247
James Dennett699c9042012-06-15 07:13:21 +00001248 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001249 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001250 /// By default, performs semantic analysis to build the new statement.
1251 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001252 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001253 Expr *Object, Stmt *Body) {
1254 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001255 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001256
James Dennett699c9042012-06-15 07:13:21 +00001257 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001258 ///
1259 /// By default, performs semantic analysis to build the new statement.
1260 /// Subclasses may override this routine to provide different behavior.
1261 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1262 Stmt *Body) {
1263 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1264 }
John McCall990567c2011-07-27 01:07:15 +00001265
Douglas Gregorc3203e72010-04-22 23:10:45 +00001266 /// \brief Build a new Objective-C fast enumeration statement.
1267 ///
1268 /// By default, performs semantic analysis to build the new statement.
1269 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001270 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001271 Stmt *Element,
1272 Expr *Collection,
1273 SourceLocation RParenLoc,
1274 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001275 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001276 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001277 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001278 RParenLoc);
1279 if (ForEachStmt.isInvalid())
1280 return StmtError();
1281
1282 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001283 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001284
Douglas Gregor43959a92009-08-20 07:17:43 +00001285 /// \brief Build a new C++ exception declaration.
1286 ///
1287 /// By default, performs semantic analysis to build the new decaration.
1288 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001289 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001290 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001291 SourceLocation StartLoc,
1292 SourceLocation IdLoc,
1293 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001294 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1295 StartLoc, IdLoc, Id);
1296 if (Var)
1297 getSema().CurContext->addDecl(Var);
1298 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001299 }
1300
1301 /// \brief Build a new C++ catch statement.
1302 ///
1303 /// By default, performs semantic analysis to build the new statement.
1304 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001305 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001306 VarDecl *ExceptionDecl,
1307 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001308 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1309 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001310 }
Mike Stump1eb44332009-09-09 15:08:12 +00001311
Douglas Gregor43959a92009-08-20 07:17:43 +00001312 /// \brief Build a new C++ try statement.
1313 ///
1314 /// By default, performs semantic analysis to build the new statement.
1315 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001316 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001317 Stmt *TryBlock,
1318 MultiStmtArg Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001319 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001320 }
Mike Stump1eb44332009-09-09 15:08:12 +00001321
Richard Smithad762fc2011-04-14 22:09:26 +00001322 /// \brief Build a new C++0x range-based for statement.
1323 ///
1324 /// By default, performs semantic analysis to build the new statement.
1325 /// Subclasses may override this routine to provide different behavior.
1326 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1327 SourceLocation ColonLoc,
1328 Stmt *Range, Stmt *BeginEnd,
1329 Expr *Cond, Expr *Inc,
1330 Stmt *LoopVar,
1331 SourceLocation RParenLoc) {
1332 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Sam Panzere1715b62012-08-21 00:52:01 +00001333 Cond, Inc, LoopVar, RParenLoc, false);
Richard Smithad762fc2011-04-14 22:09:26 +00001334 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001335
1336 /// \brief Build a new C++0x range-based for statement.
1337 ///
1338 /// By default, performs semantic analysis to build the new statement.
1339 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001340 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001341 bool IsIfExists,
1342 NestedNameSpecifierLoc QualifierLoc,
1343 DeclarationNameInfo NameInfo,
1344 Stmt *Nested) {
1345 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1346 QualifierLoc, NameInfo, Nested);
1347 }
1348
Richard Smithad762fc2011-04-14 22:09:26 +00001349 /// \brief Attach body to a C++0x range-based for statement.
1350 ///
1351 /// By default, performs semantic analysis to finish the new statement.
1352 /// Subclasses may override this routine to provide different behavior.
1353 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1354 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1355 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001356
John Wiegley28bbe4b2011-04-28 01:08:34 +00001357 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1358 SourceLocation TryLoc,
1359 Stmt *TryBlock,
1360 Stmt *Handler) {
1361 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1362 }
1363
1364 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1365 Expr *FilterExpr,
1366 Stmt *Block) {
1367 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1368 }
1369
1370 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1371 Stmt *Block) {
1372 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1373 }
1374
Douglas Gregorb98b1992009-08-11 05:31:07 +00001375 /// \brief Build a new expression that references a declaration.
1376 ///
1377 /// By default, performs semantic analysis to build the new expression.
1378 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001379 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001380 LookupResult &R,
1381 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001382 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1383 }
1384
1385
1386 /// \brief Build a new expression that references a declaration.
1387 ///
1388 /// By default, performs semantic analysis to build the new expression.
1389 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001390 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001391 ValueDecl *VD,
1392 const DeclarationNameInfo &NameInfo,
1393 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001394 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001395 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001396
1397 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001398
1399 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001400 }
Mike Stump1eb44332009-09-09 15:08:12 +00001401
Douglas Gregorb98b1992009-08-11 05:31:07 +00001402 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001403 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001404 /// By default, performs semantic analysis to build the new expression.
1405 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001406 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001407 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001408 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 }
1410
Douglas Gregora71d8192009-09-04 17:36:40 +00001411 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001412 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001413 /// By default, performs semantic analysis to build the new expression.
1414 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001415 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001416 SourceLocation OperatorLoc,
1417 bool isArrow,
1418 CXXScopeSpec &SS,
1419 TypeSourceInfo *ScopeType,
1420 SourceLocation CCLoc,
1421 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001422 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001423
Douglas Gregorb98b1992009-08-11 05:31:07 +00001424 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001425 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001426 /// By default, performs semantic analysis to build the new expression.
1427 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001428 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001429 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001430 Expr *SubExpr) {
1431 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001432 }
Mike Stump1eb44332009-09-09 15:08:12 +00001433
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001434 /// \brief Build a new builtin offsetof expression.
1435 ///
1436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001438 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001439 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001440 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001441 unsigned NumComponents,
1442 SourceLocation RParenLoc) {
1443 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1444 NumComponents, RParenLoc);
1445 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001446
1447 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001448 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001449 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001450 /// By default, performs semantic analysis to build the new expression.
1451 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001452 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1453 SourceLocation OpLoc,
1454 UnaryExprOrTypeTrait ExprKind,
1455 SourceRange R) {
1456 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001457 }
1458
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001459 /// \brief Build a new sizeof, alignof or vec step expression with an
1460 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001461 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001462 /// By default, performs semantic analysis to build the new expression.
1463 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001464 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1465 UnaryExprOrTypeTrait ExprKind,
1466 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001467 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001468 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001469 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001470 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001471
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001472 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001473 }
Mike Stump1eb44332009-09-09 15:08:12 +00001474
Douglas Gregorb98b1992009-08-11 05:31:07 +00001475 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001476 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001477 /// By default, performs semantic analysis to build the new expression.
1478 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001479 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001481 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001482 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001483 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1484 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001485 RBracketLoc);
1486 }
1487
1488 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001489 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 /// By default, performs semantic analysis to build the new expression.
1491 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001492 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001494 SourceLocation RParenLoc,
1495 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001496 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001497 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 }
1499
1500 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001501 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001502 /// By default, performs semantic analysis to build the new expression.
1503 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001504 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001505 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001506 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001507 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001508 const DeclarationNameInfo &MemberNameInfo,
1509 ValueDecl *Member,
1510 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001511 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001512 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001513 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1514 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001515 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001516 // We have a reference to an unnamed field. This is always the
1517 // base of an anonymous struct/union member access, i.e. the
1518 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001519 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001520 assert(Member->getType()->isRecordType() &&
1521 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001522
Richard Smith9138b4e2011-10-26 19:06:56 +00001523 BaseResult =
1524 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001525 QualifierLoc.getNestedNameSpecifier(),
1526 FoundDecl, Member);
1527 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001528 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001529 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001530 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001531 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001532 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001533 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001534 cast<FieldDecl>(Member)->getType(),
1535 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001536 return getSema().Owned(ME);
1537 }
Mike Stump1eb44332009-09-09 15:08:12 +00001538
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001539 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001540 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001541
John Wiegley429bb272011-04-08 18:41:53 +00001542 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001543 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001544
John McCall6bb80172010-03-30 21:47:33 +00001545 // FIXME: this involves duplicating earlier analysis in a lot of
1546 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001547 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001548 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001549 R.resolveKind();
1550
John McCall9ae2f072010-08-23 23:25:46 +00001551 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001552 SS, TemplateKWLoc,
1553 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001554 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001555 }
Mike Stump1eb44332009-09-09 15:08:12 +00001556
Douglas Gregorb98b1992009-08-11 05:31:07 +00001557 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001558 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001559 /// By default, performs semantic analysis to build the new expression.
1560 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001561 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001562 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001563 Expr *LHS, Expr *RHS) {
1564 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 }
1566
1567 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001568 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001571 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001572 SourceLocation QuestionLoc,
1573 Expr *LHS,
1574 SourceLocation ColonLoc,
1575 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001576 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1577 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001578 }
1579
Douglas Gregorb98b1992009-08-11 05:31:07 +00001580 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001581 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 /// By default, performs semantic analysis to build the new expression.
1583 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001584 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001585 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001587 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001588 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001589 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 }
Mike Stump1eb44332009-09-09 15:08:12 +00001591
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001593 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 /// By default, performs semantic analysis to build the new expression.
1595 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001596 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001597 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001598 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001599 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001600 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001601 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 }
Mike Stump1eb44332009-09-09 15:08:12 +00001603
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001605 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001606 /// By default, performs semantic analysis to build the new expression.
1607 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001608 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001609 SourceLocation OpLoc,
1610 SourceLocation AccessorLoc,
1611 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001612
John McCall129e2df2009-11-30 22:42:35 +00001613 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001614 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001615 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001616 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001617 SS, SourceLocation(),
1618 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001619 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001620 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001621 }
Mike Stump1eb44332009-09-09 15:08:12 +00001622
Douglas Gregorb98b1992009-08-11 05:31:07 +00001623 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001624 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001625 /// By default, performs semantic analysis to build the new expression.
1626 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001627 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001628 MultiExprArg Inits,
1629 SourceLocation RBraceLoc,
1630 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001631 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001632 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001633 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001634 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001635
Douglas Gregore48319a2009-11-09 17:16:50 +00001636 // Patch in the result type we were given, which may have been computed
1637 // when the initial InitListExpr was built.
1638 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1639 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001640 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001641 }
Mike Stump1eb44332009-09-09 15:08:12 +00001642
Douglas Gregorb98b1992009-08-11 05:31:07 +00001643 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001644 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001645 /// By default, performs semantic analysis to build the new expression.
1646 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001647 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648 MultiExprArg ArrayExprs,
1649 SourceLocation EqualOrColonLoc,
1650 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001651 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001652 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001654 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001656 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001657
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001658 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 }
Mike Stump1eb44332009-09-09 15:08:12 +00001660
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001662 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 /// By default, builds the implicit value initialization without performing
1664 /// any semantic analysis. Subclasses may override this routine to provide
1665 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001666 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1668 }
Mike Stump1eb44332009-09-09 15:08:12 +00001669
Douglas Gregorb98b1992009-08-11 05:31:07 +00001670 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001671 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001672 /// By default, performs semantic analysis to build the new expression.
1673 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001674 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001675 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001676 SourceLocation RParenLoc) {
1677 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001678 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001679 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001680 }
1681
1682 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001683 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001684 /// By default, performs semantic analysis to build the new expression.
1685 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001686 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001687 MultiExprArg SubExprs,
1688 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001689 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001690 }
Mike Stump1eb44332009-09-09 15:08:12 +00001691
Douglas Gregorb98b1992009-08-11 05:31:07 +00001692 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001693 ///
1694 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001695 /// rather than attempting to map the label statement itself.
1696 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001697 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001698 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001699 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 }
Mike Stump1eb44332009-09-09 15:08:12 +00001701
Douglas Gregorb98b1992009-08-11 05:31:07 +00001702 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001703 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 /// By default, performs semantic analysis to build the new expression.
1705 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001706 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001707 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001709 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 }
Mike Stump1eb44332009-09-09 15:08:12 +00001711
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 /// \brief Build a new __builtin_choose_expr expression.
1713 ///
1714 /// By default, performs semantic analysis to build the new expression.
1715 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001716 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001717 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 SourceLocation RParenLoc) {
1719 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001720 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001721 RParenLoc);
1722 }
Mike Stump1eb44332009-09-09 15:08:12 +00001723
Peter Collingbournef111d932011-04-15 00:35:48 +00001724 /// \brief Build a new generic selection expression.
1725 ///
1726 /// By default, performs semantic analysis to build the new expression.
1727 /// Subclasses may override this routine to provide different behavior.
1728 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1729 SourceLocation DefaultLoc,
1730 SourceLocation RParenLoc,
1731 Expr *ControllingExpr,
1732 TypeSourceInfo **Types,
1733 Expr **Exprs,
1734 unsigned NumAssocs) {
1735 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1736 ControllingExpr, Types, Exprs,
1737 NumAssocs);
1738 }
1739
Douglas Gregorb98b1992009-08-11 05:31:07 +00001740 /// \brief Build a new overloaded operator call expression.
1741 ///
1742 /// By default, performs semantic analysis to build the new expression.
1743 /// The semantic analysis provides the behavior of template instantiation,
1744 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001745 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001746 /// argument-dependent lookup, etc. Subclasses may override this routine to
1747 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001748 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001749 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001750 Expr *Callee,
1751 Expr *First,
1752 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001753
1754 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 /// reinterpret_cast.
1756 ///
1757 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001758 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001760 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001761 Stmt::StmtClass Class,
1762 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001763 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001764 SourceLocation RAngleLoc,
1765 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001766 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001767 SourceLocation RParenLoc) {
1768 switch (Class) {
1769 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001770 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001771 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001772 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001773
1774 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001775 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001776 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001777 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001778
Douglas Gregorb98b1992009-08-11 05:31:07 +00001779 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001780 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001781 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001782 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001783 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001784
Douglas Gregorb98b1992009-08-11 05:31:07 +00001785 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001786 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001787 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001788 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001789
Douglas Gregorb98b1992009-08-11 05:31:07 +00001790 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001791 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001792 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793 }
Mike Stump1eb44332009-09-09 15:08:12 +00001794
Douglas Gregorb98b1992009-08-11 05:31:07 +00001795 /// \brief Build a new C++ static_cast expression.
1796 ///
1797 /// By default, performs semantic analysis to build the new expression.
1798 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001799 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001801 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001802 SourceLocation RAngleLoc,
1803 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001804 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001805 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001806 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001807 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001808 SourceRange(LAngleLoc, RAngleLoc),
1809 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001810 }
1811
1812 /// \brief Build a new C++ dynamic_cast expression.
1813 ///
1814 /// By default, performs semantic analysis to build the new expression.
1815 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001816 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001817 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001818 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001819 SourceLocation RAngleLoc,
1820 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001821 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001822 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001823 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001824 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001825 SourceRange(LAngleLoc, RAngleLoc),
1826 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001827 }
1828
1829 /// \brief Build a new C++ reinterpret_cast expression.
1830 ///
1831 /// By default, performs semantic analysis to build the new expression.
1832 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001833 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001834 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001835 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001836 SourceLocation RAngleLoc,
1837 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001838 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001839 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001840 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001841 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001842 SourceRange(LAngleLoc, RAngleLoc),
1843 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001844 }
1845
1846 /// \brief Build a new C++ const_cast expression.
1847 ///
1848 /// By default, performs semantic analysis to build the new expression.
1849 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001850 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001851 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001852 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001853 SourceLocation RAngleLoc,
1854 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001855 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001856 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001857 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001858 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001859 SourceRange(LAngleLoc, RAngleLoc),
1860 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001861 }
Mike Stump1eb44332009-09-09 15:08:12 +00001862
Douglas Gregorb98b1992009-08-11 05:31:07 +00001863 /// \brief Build a new C++ functional-style cast expression.
1864 ///
1865 /// By default, performs semantic analysis to build the new expression.
1866 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001867 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1868 SourceLocation LParenLoc,
1869 Expr *Sub,
1870 SourceLocation RParenLoc) {
1871 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001872 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001873 RParenLoc);
1874 }
Mike Stump1eb44332009-09-09 15:08:12 +00001875
Douglas Gregorb98b1992009-08-11 05:31:07 +00001876 /// \brief Build a new C++ typeid(type) expression.
1877 ///
1878 /// By default, performs semantic analysis to build the new expression.
1879 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001880 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001881 SourceLocation TypeidLoc,
1882 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001883 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001884 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001885 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001886 }
Mike Stump1eb44332009-09-09 15:08:12 +00001887
Francois Pichet01b7c302010-09-08 12:20:18 +00001888
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 /// \brief Build a new C++ typeid(expr) expression.
1890 ///
1891 /// By default, performs semantic analysis to build the new expression.
1892 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001893 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001894 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001895 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001896 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001897 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001898 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001899 }
1900
Francois Pichet01b7c302010-09-08 12:20:18 +00001901 /// \brief Build a new C++ __uuidof(type) expression.
1902 ///
1903 /// By default, performs semantic analysis to build the new expression.
1904 /// Subclasses may override this routine to provide different behavior.
1905 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1906 SourceLocation TypeidLoc,
1907 TypeSourceInfo *Operand,
1908 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001909 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001910 RParenLoc);
1911 }
1912
1913 /// \brief Build a new C++ __uuidof(expr) expression.
1914 ///
1915 /// By default, performs semantic analysis to build the new expression.
1916 /// Subclasses may override this routine to provide different behavior.
1917 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1918 SourceLocation TypeidLoc,
1919 Expr *Operand,
1920 SourceLocation RParenLoc) {
1921 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1922 RParenLoc);
1923 }
1924
Douglas Gregorb98b1992009-08-11 05:31:07 +00001925 /// \brief Build a new C++ "this" expression.
1926 ///
1927 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001928 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001929 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001930 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001931 QualType ThisType,
1932 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001933 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001934 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001935 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1936 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001937 }
1938
1939 /// \brief Build a new C++ throw expression.
1940 ///
1941 /// By default, performs semantic analysis to build the new expression.
1942 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001943 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1944 bool IsThrownVariableInScope) {
1945 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001946 }
1947
1948 /// \brief Build a new C++ default-argument expression.
1949 ///
1950 /// By default, builds a new default-argument expression, which does not
1951 /// require any semantic analysis. Subclasses may override this routine to
1952 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001953 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001954 ParmVarDecl *Param) {
1955 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1956 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001957 }
1958
1959 /// \brief Build a new C++ zero-initialization expression.
1960 ///
1961 /// By default, performs semantic analysis to build the new expression.
1962 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001963 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1964 SourceLocation LParenLoc,
1965 SourceLocation RParenLoc) {
1966 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Benjamin Kramer5354e772012-08-23 23:38:35 +00001967 MultiExprArg(), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001968 }
Mike Stump1eb44332009-09-09 15:08:12 +00001969
Douglas Gregorb98b1992009-08-11 05:31:07 +00001970 /// \brief Build a new C++ "new" expression.
1971 ///
1972 /// By default, performs semantic analysis to build the new expression.
1973 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001974 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001975 bool UseGlobal,
1976 SourceLocation PlacementLParen,
1977 MultiExprArg PlacementArgs,
1978 SourceLocation PlacementRParen,
1979 SourceRange TypeIdParens,
1980 QualType AllocatedType,
1981 TypeSourceInfo *AllocatedTypeInfo,
1982 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001983 SourceRange DirectInitRange,
1984 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001985 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001986 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001987 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001988 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001989 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001990 AllocatedType,
1991 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001992 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001993 DirectInitRange,
1994 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001995 }
Mike Stump1eb44332009-09-09 15:08:12 +00001996
Douglas Gregorb98b1992009-08-11 05:31:07 +00001997 /// \brief Build a new C++ "delete" expression.
1998 ///
1999 /// By default, performs semantic analysis to build the new expression.
2000 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002001 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002002 bool IsGlobalDelete,
2003 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002004 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002005 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002006 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002007 }
Mike Stump1eb44332009-09-09 15:08:12 +00002008
Douglas Gregorb98b1992009-08-11 05:31:07 +00002009 /// \brief Build a new unary type trait expression.
2010 ///
2011 /// By default, performs semantic analysis to build the new expression.
2012 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002013 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002014 SourceLocation StartLoc,
2015 TypeSourceInfo *T,
2016 SourceLocation RParenLoc) {
2017 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002018 }
2019
Francois Pichet6ad6f282010-12-07 00:08:36 +00002020 /// \brief Build a new binary type trait expression.
2021 ///
2022 /// By default, performs semantic analysis to build the new expression.
2023 /// Subclasses may override this routine to provide different behavior.
2024 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2025 SourceLocation StartLoc,
2026 TypeSourceInfo *LhsT,
2027 TypeSourceInfo *RhsT,
2028 SourceLocation RParenLoc) {
2029 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2030 }
2031
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002032 /// \brief Build a new type trait expression.
2033 ///
2034 /// By default, performs semantic analysis to build the new expression.
2035 /// Subclasses may override this routine to provide different behavior.
2036 ExprResult RebuildTypeTrait(TypeTrait Trait,
2037 SourceLocation StartLoc,
2038 ArrayRef<TypeSourceInfo *> Args,
2039 SourceLocation RParenLoc) {
2040 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2041 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002042
John Wiegley21ff2e52011-04-28 00:16:57 +00002043 /// \brief Build a new array type trait expression.
2044 ///
2045 /// By default, performs semantic analysis to build the new expression.
2046 /// Subclasses may override this routine to provide different behavior.
2047 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2048 SourceLocation StartLoc,
2049 TypeSourceInfo *TSInfo,
2050 Expr *DimExpr,
2051 SourceLocation RParenLoc) {
2052 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2053 }
2054
John Wiegley55262202011-04-25 06:54:41 +00002055 /// \brief Build a new expression trait expression.
2056 ///
2057 /// By default, performs semantic analysis to build the new expression.
2058 /// Subclasses may override this routine to provide different behavior.
2059 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2060 SourceLocation StartLoc,
2061 Expr *Queried,
2062 SourceLocation RParenLoc) {
2063 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2064 }
2065
Mike Stump1eb44332009-09-09 15:08:12 +00002066 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002067 /// expression.
2068 ///
2069 /// By default, performs semantic analysis to build the new expression.
2070 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002071 ExprResult RebuildDependentScopeDeclRefExpr(
2072 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002073 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002074 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002075 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002076 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002077 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002078
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002079 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002080 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002081 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002082
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002083 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002084 }
2085
2086 /// \brief Build a new template-id expression.
2087 ///
2088 /// By default, performs semantic analysis to build the new expression.
2089 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002090 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002091 SourceLocation TemplateKWLoc,
2092 LookupResult &R,
2093 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002094 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002095 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2096 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002097 }
2098
2099 /// \brief Build a new object-construction expression.
2100 ///
2101 /// By default, performs semantic analysis to build the new expression.
2102 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002103 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002104 SourceLocation Loc,
2105 CXXConstructorDecl *Constructor,
2106 bool IsElidable,
2107 MultiExprArg Args,
2108 bool HadMultipleCandidates,
2109 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002110 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002111 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002112 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002113 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002114 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002115 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002116
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002117 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002118 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002119 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002120 RequiresZeroInit, ConstructKind,
2121 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002122 }
2123
2124 /// \brief Build a new object-construction expression.
2125 ///
2126 /// By default, performs semantic analysis to build the new expression.
2127 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002128 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2129 SourceLocation LParenLoc,
2130 MultiExprArg Args,
2131 SourceLocation RParenLoc) {
2132 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002133 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002134 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002135 RParenLoc);
2136 }
2137
2138 /// \brief Build a new object-construction expression.
2139 ///
2140 /// By default, performs semantic analysis to build the new expression.
2141 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002142 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2143 SourceLocation LParenLoc,
2144 MultiExprArg Args,
2145 SourceLocation RParenLoc) {
2146 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002147 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002148 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002149 RParenLoc);
2150 }
Mike Stump1eb44332009-09-09 15:08:12 +00002151
Douglas Gregorb98b1992009-08-11 05:31:07 +00002152 /// \brief Build a new member reference expression.
2153 ///
2154 /// By default, performs semantic analysis to build the new expression.
2155 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002156 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002157 QualType BaseType,
2158 bool IsArrow,
2159 SourceLocation OperatorLoc,
2160 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002161 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002162 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002163 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002164 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002165 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002166 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002167
John McCall9ae2f072010-08-23 23:25:46 +00002168 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002169 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002170 SS, TemplateKWLoc,
2171 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002172 MemberNameInfo,
2173 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002174 }
2175
John McCall129e2df2009-11-30 22:42:35 +00002176 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002177 ///
2178 /// By default, performs semantic analysis to build the new expression.
2179 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002180 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2181 SourceLocation OperatorLoc,
2182 bool IsArrow,
2183 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002184 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002185 NamedDecl *FirstQualifierInScope,
2186 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002187 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002188 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002189 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002190
John McCall9ae2f072010-08-23 23:25:46 +00002191 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002192 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002193 SS, TemplateKWLoc,
2194 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002195 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002196 }
Mike Stump1eb44332009-09-09 15:08:12 +00002197
Sebastian Redl2e156222010-09-10 20:55:43 +00002198 /// \brief Build a new noexcept expression.
2199 ///
2200 /// By default, performs semantic analysis to build the new expression.
2201 /// Subclasses may override this routine to provide different behavior.
2202 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2203 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2204 }
2205
Douglas Gregoree8aff02011-01-04 17:33:58 +00002206 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002207 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2208 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002209 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002210 llvm::Optional<unsigned> Length) {
2211 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002212 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2213 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002214 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002215
2216 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2217 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002218 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002219 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002220
Patrick Beardeb382ec2012-04-19 00:25:12 +00002221 /// \brief Build a new Objective-C boxed expression.
2222 ///
2223 /// By default, performs semantic analysis to build the new expression.
2224 /// Subclasses may override this routine to provide different behavior.
2225 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2226 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2227 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002228
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002229 /// \brief Build a new Objective-C array literal.
2230 ///
2231 /// By default, performs semantic analysis to build the new expression.
2232 /// Subclasses may override this routine to provide different behavior.
2233 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2234 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002235 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002236 MultiExprArg(Elements, NumElements));
2237 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002238
2239 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002240 Expr *Base, Expr *Key,
2241 ObjCMethodDecl *getterMethod,
2242 ObjCMethodDecl *setterMethod) {
2243 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2244 getterMethod, setterMethod);
2245 }
2246
2247 /// \brief Build a new Objective-C dictionary literal.
2248 ///
2249 /// By default, performs semantic analysis to build the new expression.
2250 /// Subclasses may override this routine to provide different behavior.
2251 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2252 ObjCDictionaryElement *Elements,
2253 unsigned NumElements) {
2254 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2255 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002256
James Dennett699c9042012-06-15 07:13:21 +00002257 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002258 ///
2259 /// By default, performs semantic analysis to build the new expression.
2260 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002261 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002262 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002263 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002264 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002265 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002266 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002267
Douglas Gregor92e986e2010-04-22 16:44:27 +00002268 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002269 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002270 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002271 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002272 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002273 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002274 MultiExprArg Args,
2275 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002276 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2277 ReceiverTypeInfo->getType(),
2278 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002279 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002280 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002281 }
2282
2283 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002284 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002285 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002286 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002287 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002288 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002289 MultiExprArg Args,
2290 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002291 return SemaRef.BuildInstanceMessage(Receiver,
2292 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002293 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002294 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002295 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002296 }
2297
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002298 /// \brief Build a new Objective-C ivar reference expression.
2299 ///
2300 /// By default, performs semantic analysis to build the new expression.
2301 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002302 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002303 SourceLocation IvarLoc,
2304 bool IsArrow, bool IsFreeIvar) {
2305 // FIXME: We lose track of the IsFreeIvar bit.
2306 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002307 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002308 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2309 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002310 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002311 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002312 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002313 false);
John Wiegley429bb272011-04-08 18:41:53 +00002314 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002315 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002316
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002317 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002318 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002319
John Wiegley429bb272011-04-08 18:41:53 +00002320 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002321 /*FIXME:*/IvarLoc, IsArrow,
2322 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002323 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002324 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002325 /*TemplateArgs=*/0);
2326 }
Douglas Gregore3303542010-04-26 20:47:02 +00002327
2328 /// \brief Build a new Objective-C property reference expression.
2329 ///
2330 /// By default, performs semantic analysis to build the new expression.
2331 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002332 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002333 ObjCPropertyDecl *Property,
2334 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002335 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002336 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002337 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2338 Sema::LookupMemberName);
2339 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002340 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002341 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002342 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002343 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002344 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002345
Douglas Gregore3303542010-04-26 20:47:02 +00002346 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002347 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002348
John Wiegley429bb272011-04-08 18:41:53 +00002349 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002350 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002351 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002352 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002353 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002354 /*TemplateArgs=*/0);
2355 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002356
John McCall12f78a62010-12-02 01:19:52 +00002357 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002358 ///
2359 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002360 /// Subclasses may override this routine to provide different behavior.
2361 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2362 ObjCMethodDecl *Getter,
2363 ObjCMethodDecl *Setter,
2364 SourceLocation PropertyLoc) {
2365 // Since these expressions can only be value-dependent, we do not
2366 // need to perform semantic analysis again.
2367 return Owned(
2368 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2369 VK_LValue, OK_ObjCProperty,
2370 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002371 }
2372
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002373 /// \brief Build a new Objective-C "isa" expression.
2374 ///
2375 /// By default, performs semantic analysis to build the new expression.
2376 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002377 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002378 bool IsArrow) {
2379 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002380 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002381 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2382 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002383 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002384 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002385 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002386 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002387 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002388
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002389 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002390 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002391
John Wiegley429bb272011-04-08 18:41:53 +00002392 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002393 /*FIXME:*/IsaLoc, IsArrow,
2394 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002395 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002396 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002397 /*TemplateArgs=*/0);
2398 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002399
Douglas Gregorb98b1992009-08-11 05:31:07 +00002400 /// \brief Build a new shuffle vector expression.
2401 ///
2402 /// By default, performs semantic analysis to build the new expression.
2403 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002404 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002405 MultiExprArg SubExprs,
2406 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002407 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002408 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002409 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2410 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2411 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2412 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002413
Douglas Gregorb98b1992009-08-11 05:31:07 +00002414 // Build a reference to the __builtin_shufflevector builtin
2415 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002416 ExprResult Callee
John McCallf4b88a42012-03-10 09:33:50 +00002417 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false,
2418 Builtin->getType(),
John Wiegley429bb272011-04-08 18:41:53 +00002419 VK_LValue, BuiltinLoc));
2420 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2421 if (Callee.isInvalid())
2422 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002423
2424 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002425 ExprResult TheCall = SemaRef.Owned(
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002426 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(), SubExprs,
2427 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002428 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002429 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002430
Douglas Gregorb98b1992009-08-11 05:31:07 +00002431 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002432 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002433 }
John McCall43fed0d2010-11-12 08:19:04 +00002434
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002435 /// \brief Build a new template argument pack expansion.
2436 ///
2437 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002438 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002439 /// different behavior.
2440 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002441 SourceLocation EllipsisLoc,
2442 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002443 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002444 case TemplateArgument::Expression: {
2445 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002446 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2447 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002448 if (Result.isInvalid())
2449 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002450
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002451 return TemplateArgumentLoc(Result.get(), Result.get());
2452 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002453
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002454 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002455 return TemplateArgumentLoc(TemplateArgument(
2456 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002457 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002458 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002459 Pattern.getTemplateNameLoc(),
2460 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002461
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002462 case TemplateArgument::Null:
2463 case TemplateArgument::Integral:
2464 case TemplateArgument::Declaration:
2465 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002466 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002467 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002468
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002469 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002470 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002471 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002472 EllipsisLoc,
2473 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002474 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2475 Expansion);
2476 break;
2477 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002478
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002479 return TemplateArgumentLoc();
2480 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002481
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002482 /// \brief Build a new expression pack expansion.
2483 ///
2484 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002485 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002486 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002487 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2488 llvm::Optional<unsigned> NumExpansions) {
2489 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002490 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002491
2492 /// \brief Build a new atomic operation expression.
2493 ///
2494 /// By default, performs semantic analysis to build the new expression.
2495 /// Subclasses may override this routine to provide different behavior.
2496 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2497 MultiExprArg SubExprs,
2498 QualType RetTy,
2499 AtomicExpr::AtomicOp Op,
2500 SourceLocation RParenLoc) {
2501 // Just create the expression; there is not any interesting semantic
2502 // analysis here because we can't actually build an AtomicExpr until
2503 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002504 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002505 RParenLoc);
2506 }
2507
John McCall43fed0d2010-11-12 08:19:04 +00002508private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002509 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2510 QualType ObjectType,
2511 NamedDecl *FirstQualifierInScope,
2512 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002513
2514 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2515 QualType ObjectType,
2516 NamedDecl *FirstQualifierInScope,
2517 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002518};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002519
Douglas Gregor43959a92009-08-20 07:17:43 +00002520template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002521StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002522 if (!S)
2523 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002524
Douglas Gregor43959a92009-08-20 07:17:43 +00002525 switch (S->getStmtClass()) {
2526 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002527
Douglas Gregor43959a92009-08-20 07:17:43 +00002528 // Transform individual statement nodes
2529#define STMT(Node, Parent) \
2530 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002531#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002532#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002533#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002534
Douglas Gregor43959a92009-08-20 07:17:43 +00002535 // Transform expressions by calling TransformExpr.
2536#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002537#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002538#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002539#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002540 {
John McCall60d7b3a2010-08-24 06:29:42 +00002541 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002542 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002543 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002544
John McCall9ae2f072010-08-23 23:25:46 +00002545 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002546 }
Mike Stump1eb44332009-09-09 15:08:12 +00002547 }
2548
John McCall3fa5cae2010-10-26 07:05:15 +00002549 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002550}
Mike Stump1eb44332009-09-09 15:08:12 +00002551
2552
Douglas Gregor670444e2009-08-04 22:27:00 +00002553template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002554ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002555 if (!E)
2556 return SemaRef.Owned(E);
2557
2558 switch (E->getStmtClass()) {
2559 case Stmt::NoStmtClass: break;
2560#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002561#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002562#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002563 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002564#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002565 }
2566
John McCall3fa5cae2010-10-26 07:05:15 +00002567 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002568}
2569
2570template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002571bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2572 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002573 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002574 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002575 bool *ArgChanged) {
2576 for (unsigned I = 0; I != NumInputs; ++I) {
2577 // If requested, drop call arguments that need to be dropped.
2578 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2579 if (ArgChanged)
2580 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002581
Douglas Gregoraa165f82011-01-03 19:04:46 +00002582 break;
2583 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002584
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002585 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2586 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002587
Chris Lattner686775d2011-07-20 06:58:45 +00002588 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002589 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2590 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002591
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002592 // Determine whether the set of unexpanded parameter packs can and should
2593 // be expanded.
2594 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002595 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002596 llvm::Optional<unsigned> OrigNumExpansions
2597 = Expansion->getNumExpansions();
2598 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002599 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2600 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002601 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002602 Expand, RetainExpansion,
2603 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002604 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002605
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002606 if (!Expand) {
2607 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002608 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002609 // expansion.
2610 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2611 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2612 if (OutPattern.isInvalid())
2613 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002614
2615 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002616 Expansion->getEllipsisLoc(),
2617 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002618 if (Out.isInvalid())
2619 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002620
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002621 if (ArgChanged)
2622 *ArgChanged = true;
2623 Outputs.push_back(Out.get());
2624 continue;
2625 }
John McCallc8fc90a2011-07-06 07:30:07 +00002626
2627 // Record right away that the argument was changed. This needs
2628 // to happen even if the array expands to nothing.
2629 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002630
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002631 // The transform has determined that we should perform an elementwise
2632 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002633 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002634 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2635 ExprResult Out = getDerived().TransformExpr(Pattern);
2636 if (Out.isInvalid())
2637 return true;
2638
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002639 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002640 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2641 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002642 if (Out.isInvalid())
2643 return true;
2644 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002645
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002646 Outputs.push_back(Out.get());
2647 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002648
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002649 continue;
2650 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002651
Douglas Gregoraa165f82011-01-03 19:04:46 +00002652 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2653 if (Result.isInvalid())
2654 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002655
Douglas Gregoraa165f82011-01-03 19:04:46 +00002656 if (Result.get() != Inputs[I] && ArgChanged)
2657 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002658
2659 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002660 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002661
Douglas Gregoraa165f82011-01-03 19:04:46 +00002662 return false;
2663}
2664
2665template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002666NestedNameSpecifierLoc
2667TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2668 NestedNameSpecifierLoc NNS,
2669 QualType ObjectType,
2670 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002671 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002672 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002673 Qualifier = Qualifier.getPrefix())
2674 Qualifiers.push_back(Qualifier);
2675
2676 CXXScopeSpec SS;
2677 while (!Qualifiers.empty()) {
2678 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2679 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002680
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002681 switch (QNNS->getKind()) {
2682 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002683 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002684 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002685 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002686 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002687 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002688 FirstQualifierInScope, false))
2689 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002690
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002691 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002692
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002693 case NestedNameSpecifier::Namespace: {
2694 NamespaceDecl *NS
2695 = cast_or_null<NamespaceDecl>(
2696 getDerived().TransformDecl(
2697 Q.getLocalBeginLoc(),
2698 QNNS->getAsNamespace()));
2699 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2700 break;
2701 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002702
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002703 case NestedNameSpecifier::NamespaceAlias: {
2704 NamespaceAliasDecl *Alias
2705 = cast_or_null<NamespaceAliasDecl>(
2706 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2707 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002708 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002709 Q.getLocalEndLoc());
2710 break;
2711 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002712
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002713 case NestedNameSpecifier::Global:
2714 // There is no meaningful transformation that one could perform on the
2715 // global scope.
2716 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2717 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002718
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002719 case NestedNameSpecifier::TypeSpecWithTemplate:
2720 case NestedNameSpecifier::TypeSpec: {
2721 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2722 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002723
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002724 if (!TL)
2725 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002726
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002727 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00002728 (SemaRef.getLangOpts().CPlusPlus0x &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002729 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002730 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002731 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002732 if (TL.getType()->isEnumeralType())
2733 SemaRef.Diag(TL.getBeginLoc(),
2734 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002735 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2736 Q.getLocalEndLoc());
2737 break;
2738 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002739 // If the nested-name-specifier is an invalid type def, don't emit an
2740 // error because a previous error should have already been emitted.
2741 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2742 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002743 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002744 << TL.getType() << SS.getRange();
2745 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002746 return NestedNameSpecifierLoc();
2747 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002748 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002749
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002750 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002751 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002752 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002753 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002754
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002755 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002756 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002757 !getDerived().AlwaysRebuild())
2758 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002759
2760 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002761 // nested-name-specifier, do so.
2762 if (SS.location_size() == NNS.getDataLength() &&
2763 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2764 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2765
2766 // Allocate new nested-name-specifier location information.
2767 return SS.getWithLocInContext(SemaRef.Context);
2768}
2769
2770template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002771DeclarationNameInfo
2772TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002773::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002774 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002775 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002776 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002777
2778 switch (Name.getNameKind()) {
2779 case DeclarationName::Identifier:
2780 case DeclarationName::ObjCZeroArgSelector:
2781 case DeclarationName::ObjCOneArgSelector:
2782 case DeclarationName::ObjCMultiArgSelector:
2783 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002784 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002785 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002786 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002787
Douglas Gregor81499bb2009-09-03 22:13:48 +00002788 case DeclarationName::CXXConstructorName:
2789 case DeclarationName::CXXDestructorName:
2790 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002791 TypeSourceInfo *NewTInfo;
2792 CanQualType NewCanTy;
2793 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002794 NewTInfo = getDerived().TransformType(OldTInfo);
2795 if (!NewTInfo)
2796 return DeclarationNameInfo();
2797 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002798 }
2799 else {
2800 NewTInfo = 0;
2801 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002802 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002803 if (NewT.isNull())
2804 return DeclarationNameInfo();
2805 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2806 }
Mike Stump1eb44332009-09-09 15:08:12 +00002807
Abramo Bagnara25777432010-08-11 22:01:17 +00002808 DeclarationName NewName
2809 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2810 NewCanTy);
2811 DeclarationNameInfo NewNameInfo(NameInfo);
2812 NewNameInfo.setName(NewName);
2813 NewNameInfo.setNamedTypeInfo(NewTInfo);
2814 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002815 }
Mike Stump1eb44332009-09-09 15:08:12 +00002816 }
2817
David Blaikieb219cfc2011-09-23 05:06:16 +00002818 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002819}
2820
2821template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002822TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002823TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2824 TemplateName Name,
2825 SourceLocation NameLoc,
2826 QualType ObjectType,
2827 NamedDecl *FirstQualifierInScope) {
2828 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2829 TemplateDecl *Template = QTN->getTemplateDecl();
2830 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002831
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002832 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002833 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002834 Template));
2835 if (!TransTemplate)
2836 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002837
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002838 if (!getDerived().AlwaysRebuild() &&
2839 SS.getScopeRep() == QTN->getQualifier() &&
2840 TransTemplate == Template)
2841 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002842
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002843 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2844 TransTemplate);
2845 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002846
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002847 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2848 if (SS.getScopeRep()) {
2849 // These apply to the scope specifier, not the template.
2850 ObjectType = QualType();
2851 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002852 }
2853
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002854 if (!getDerived().AlwaysRebuild() &&
2855 SS.getScopeRep() == DTN->getQualifier() &&
2856 ObjectType.isNull())
2857 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002858
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002859 if (DTN->isIdentifier()) {
2860 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002861 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002862 NameLoc,
2863 ObjectType,
2864 FirstQualifierInScope);
2865 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002866
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002867 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2868 ObjectType);
2869 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002870
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002871 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2872 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002873 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002874 Template));
2875 if (!TransTemplate)
2876 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002877
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002878 if (!getDerived().AlwaysRebuild() &&
2879 TransTemplate == Template)
2880 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002881
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002882 return TemplateName(TransTemplate);
2883 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002884
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002885 if (SubstTemplateTemplateParmPackStorage *SubstPack
2886 = Name.getAsSubstTemplateTemplateParmPack()) {
2887 TemplateTemplateParmDecl *TransParam
2888 = cast_or_null<TemplateTemplateParmDecl>(
2889 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2890 if (!TransParam)
2891 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002892
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002893 if (!getDerived().AlwaysRebuild() &&
2894 TransParam == SubstPack->getParameterPack())
2895 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002896
2897 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002898 SubstPack->getArgumentPack());
2899 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002900
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002901 // These should be getting filtered out before they reach the AST.
2902 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002903}
2904
2905template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002906void TreeTransform<Derived>::InventTemplateArgumentLoc(
2907 const TemplateArgument &Arg,
2908 TemplateArgumentLoc &Output) {
2909 SourceLocation Loc = getDerived().getBaseLocation();
2910 switch (Arg.getKind()) {
2911 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002912 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002913 break;
2914
2915 case TemplateArgument::Type:
2916 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002917 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002918
John McCall833ca992009-10-29 08:12:44 +00002919 break;
2920
Douglas Gregor788cd062009-11-11 01:00:40 +00002921 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002922 case TemplateArgument::TemplateExpansion: {
2923 NestedNameSpecifierLocBuilder Builder;
2924 TemplateName Template = Arg.getAsTemplate();
2925 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2926 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2927 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2928 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002929
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002930 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002931 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002932 Builder.getWithLocInContext(SemaRef.Context),
2933 Loc);
2934 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00002935 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002936 Builder.getWithLocInContext(SemaRef.Context),
2937 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002938
Douglas Gregor788cd062009-11-11 01:00:40 +00002939 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002940 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002941
John McCall833ca992009-10-29 08:12:44 +00002942 case TemplateArgument::Expression:
2943 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2944 break;
2945
2946 case TemplateArgument::Declaration:
2947 case TemplateArgument::Integral:
2948 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002949 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002950 break;
2951 }
2952}
2953
2954template<typename Derived>
2955bool TreeTransform<Derived>::TransformTemplateArgument(
2956 const TemplateArgumentLoc &Input,
2957 TemplateArgumentLoc &Output) {
2958 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002959 switch (Arg.getKind()) {
2960 case TemplateArgument::Null:
2961 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002962 Output = Input;
2963 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002964
Douglas Gregor670444e2009-08-04 22:27:00 +00002965 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002966 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002967 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002968 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002969
2970 DI = getDerived().TransformType(DI);
2971 if (!DI) return true;
2972
2973 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2974 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002975 }
Mike Stump1eb44332009-09-09 15:08:12 +00002976
Douglas Gregor670444e2009-08-04 22:27:00 +00002977 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002978 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002979 DeclarationName Name;
2980 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2981 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002982 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002983 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002984 if (!D) return true;
2985
John McCall828bff22009-10-29 18:45:58 +00002986 Expr *SourceExpr = Input.getSourceDeclExpression();
2987 if (SourceExpr) {
2988 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002989 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002990 ExprResult E = getDerived().TransformExpr(SourceExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00002991 E = SemaRef.ActOnConstantExpression(E);
John McCall9ae2f072010-08-23 23:25:46 +00002992 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002993 }
2994
2995 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002996 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002997 }
Mike Stump1eb44332009-09-09 15:08:12 +00002998
Douglas Gregor788cd062009-11-11 01:00:40 +00002999 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003000 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3001 if (QualifierLoc) {
3002 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3003 if (!QualifierLoc)
3004 return true;
3005 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003006
Douglas Gregor1d752d72011-03-02 18:46:51 +00003007 CXXScopeSpec SS;
3008 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003009 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003010 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3011 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003012 if (Template.isNull())
3013 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003014
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003015 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003016 Input.getTemplateNameLoc());
3017 return false;
3018 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003019
3020 case TemplateArgument::TemplateExpansion:
3021 llvm_unreachable("Caller should expand pack expansions");
3022
Douglas Gregor670444e2009-08-04 22:27:00 +00003023 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003024 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003025 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003026 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003027
John McCall833ca992009-10-29 08:12:44 +00003028 Expr *InputExpr = Input.getSourceExpression();
3029 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3030
Chris Lattner223de242011-04-25 20:37:58 +00003031 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003032 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003033 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003034 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003035 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003036 }
Mike Stump1eb44332009-09-09 15:08:12 +00003037
Douglas Gregor670444e2009-08-04 22:27:00 +00003038 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00003039 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00003040 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00003041 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00003042 AEnd = Arg.pack_end();
3043 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00003044
John McCall833ca992009-10-29 08:12:44 +00003045 // FIXME: preserve source information here when we start
3046 // caring about parameter packs.
3047
John McCall828bff22009-10-29 18:45:58 +00003048 TemplateArgumentLoc InputArg;
3049 TemplateArgumentLoc OutputArg;
3050 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3051 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00003052 return true;
3053
John McCall828bff22009-10-29 18:45:58 +00003054 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00003055 }
Douglas Gregor910f8002010-11-07 23:05:16 +00003056
3057 TemplateArgument *TransformedArgsPtr
3058 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3059 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3060 TransformedArgsPtr);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003061 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3062 TransformedArgs.size()),
Douglas Gregor910f8002010-11-07 23:05:16 +00003063 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003064 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003065 }
3066 }
Mike Stump1eb44332009-09-09 15:08:12 +00003067
Douglas Gregor670444e2009-08-04 22:27:00 +00003068 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003069 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003070}
3071
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003072/// \brief Iterator adaptor that invents template argument location information
3073/// for each of the template arguments in its underlying iterator.
3074template<typename Derived, typename InputIterator>
3075class TemplateArgumentLocInventIterator {
3076 TreeTransform<Derived> &Self;
3077 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003078
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003079public:
3080 typedef TemplateArgumentLoc value_type;
3081 typedef TemplateArgumentLoc reference;
3082 typedef typename std::iterator_traits<InputIterator>::difference_type
3083 difference_type;
3084 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003085
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003086 class pointer {
3087 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003088
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003089 public:
3090 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003091
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003092 const TemplateArgumentLoc *operator->() const { return &Arg; }
3093 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003094
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003095 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003096
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003097 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3098 InputIterator Iter)
3099 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003100
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003101 TemplateArgumentLocInventIterator &operator++() {
3102 ++Iter;
3103 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003104 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003105
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003106 TemplateArgumentLocInventIterator operator++(int) {
3107 TemplateArgumentLocInventIterator Old(*this);
3108 ++(*this);
3109 return Old;
3110 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003111
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003112 reference operator*() const {
3113 TemplateArgumentLoc Result;
3114 Self.InventTemplateArgumentLoc(*Iter, Result);
3115 return Result;
3116 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003117
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003118 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003119
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003120 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3121 const TemplateArgumentLocInventIterator &Y) {
3122 return X.Iter == Y.Iter;
3123 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003124
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003125 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3126 const TemplateArgumentLocInventIterator &Y) {
3127 return X.Iter != Y.Iter;
3128 }
3129};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003130
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003131template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003132template<typename InputIterator>
3133bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3134 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003135 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003136 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003137 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003138 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003139
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003140 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3141 // Unpack argument packs, which we translate them into separate
3142 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003143 // FIXME: We could do much better if we could guarantee that the
3144 // TemplateArgumentLocInfo for the pack expansion would be usable for
3145 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003146 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003147 TemplateArgument::pack_iterator>
3148 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003149 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003150 In.getArgument().pack_begin()),
3151 PackLocIterator(*this,
3152 In.getArgument().pack_end()),
3153 Outputs))
3154 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003155
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003156 continue;
3157 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003158
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003159 if (In.getArgument().isPackExpansion()) {
3160 // We have a pack expansion, for which we will be substituting into
3161 // the pattern.
3162 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003163 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003164 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003165 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003166 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003167
Chris Lattner686775d2011-07-20 06:58:45 +00003168 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003169 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3170 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003171
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003172 // Determine whether the set of unexpanded parameter packs can and should
3173 // be expanded.
3174 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003175 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003176 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003177 if (getDerived().TryExpandParameterPacks(Ellipsis,
3178 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003179 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003180 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003181 RetainExpansion,
3182 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003183 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003184
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003185 if (!Expand) {
3186 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003187 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003188 // expansion.
3189 TemplateArgumentLoc OutPattern;
3190 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3191 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3192 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003193
Douglas Gregorcded4f62011-01-14 17:04:44 +00003194 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3195 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003196 if (Out.getArgument().isNull())
3197 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003198
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003199 Outputs.addArgument(Out);
3200 continue;
3201 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003202
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003203 // The transform has determined that we should perform an elementwise
3204 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003205 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003206 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3207
3208 if (getDerived().TransformTemplateArgument(Pattern, Out))
3209 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003210
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003211 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003212 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3213 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003214 if (Out.getArgument().isNull())
3215 return true;
3216 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003217
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003218 Outputs.addArgument(Out);
3219 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003220
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003221 // If we're supposed to retain a pack expansion, do so by temporarily
3222 // forgetting the partially-substituted parameter pack.
3223 if (RetainExpansion) {
3224 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003225
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003226 if (getDerived().TransformTemplateArgument(Pattern, Out))
3227 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003228
Douglas Gregorcded4f62011-01-14 17:04:44 +00003229 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3230 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003231 if (Out.getArgument().isNull())
3232 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003233
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003234 Outputs.addArgument(Out);
3235 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003236
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003237 continue;
3238 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003239
3240 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003241 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003242 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003243
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003244 Outputs.addArgument(Out);
3245 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003246
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003247 return false;
3248
3249}
3250
Douglas Gregor577f75a2009-08-04 16:50:30 +00003251//===----------------------------------------------------------------------===//
3252// Type transformation
3253//===----------------------------------------------------------------------===//
3254
3255template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003256QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003257 if (getDerived().AlreadyTransformed(T))
3258 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003259
John McCalla2becad2009-10-21 00:40:46 +00003260 // Temporary workaround. All of these transformations should
3261 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003262 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3263 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003264
John McCall43fed0d2010-11-12 08:19:04 +00003265 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003266
John McCalla2becad2009-10-21 00:40:46 +00003267 if (!NewDI)
3268 return QualType();
3269
3270 return NewDI->getType();
3271}
3272
3273template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003274TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003275 // Refine the base location to the type's location.
3276 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3277 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003278 if (getDerived().AlreadyTransformed(DI->getType()))
3279 return DI;
3280
3281 TypeLocBuilder TLB;
3282
3283 TypeLoc TL = DI->getTypeLoc();
3284 TLB.reserve(TL.getFullDataSize());
3285
John McCall43fed0d2010-11-12 08:19:04 +00003286 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003287 if (Result.isNull())
3288 return 0;
3289
John McCalla93c9342009-12-07 02:54:59 +00003290 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003291}
3292
3293template<typename Derived>
3294QualType
John McCall43fed0d2010-11-12 08:19:04 +00003295TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003296 switch (T.getTypeLocClass()) {
3297#define ABSTRACT_TYPELOC(CLASS, PARENT)
3298#define TYPELOC(CLASS, PARENT) \
3299 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003300 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003301#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003302 }
Mike Stump1eb44332009-09-09 15:08:12 +00003303
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003304 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003305}
3306
3307/// FIXME: By default, this routine adds type qualifiers only to types
3308/// that can have qualifiers, and silently suppresses those qualifiers
3309/// that are not permitted (e.g., qualifiers on reference or function
3310/// types). This is the right thing for template instantiation, but
3311/// probably not for other clients.
3312template<typename Derived>
3313QualType
3314TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003315 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003316 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003317
John McCall43fed0d2010-11-12 08:19:04 +00003318 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003319 if (Result.isNull())
3320 return QualType();
3321
3322 // Silently suppress qualifiers if the result type can't be qualified.
3323 // FIXME: this is the right thing for template instantiation, but
3324 // probably not for other clients.
3325 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003326 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003327
John McCallf85e1932011-06-15 23:02:42 +00003328 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003329 // resulting type.
3330 if (Quals.hasObjCLifetime()) {
3331 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3332 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003333 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003334 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003335 // A lifetime qualifier applied to a substituted template parameter
3336 // overrides the lifetime qualifier from the template argument.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003337 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003338 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3339 QualType Replacement = SubstTypeParam->getReplacementType();
3340 Qualifiers Qs = Replacement.getQualifiers();
3341 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003342 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003343 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3344 Qs);
3345 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003346 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003347 Replacement);
3348 TLB.TypeWasModifiedSafely(Result);
3349 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003350 // Otherwise, complain about the addition of a qualifier to an
3351 // already-qualified type.
3352 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003353 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003354 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003355
Douglas Gregore559ca12011-06-17 22:11:49 +00003356 Quals.removeObjCLifetime();
3357 }
3358 }
3359 }
John McCall28654742010-06-05 06:41:15 +00003360 if (!Quals.empty()) {
3361 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3362 TLB.push<QualifiedTypeLoc>(Result);
3363 // No location information to preserve.
3364 }
John McCalla2becad2009-10-21 00:40:46 +00003365
3366 return Result;
3367}
3368
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003369template<typename Derived>
3370TypeLoc
3371TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3372 QualType ObjectType,
3373 NamedDecl *UnqualLookup,
3374 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003375 QualType T = TL.getType();
3376 if (getDerived().AlreadyTransformed(T))
3377 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003378
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003379 TypeLocBuilder TLB;
3380 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003381
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003382 if (isa<TemplateSpecializationType>(T)) {
3383 TemplateSpecializationTypeLoc SpecTL
3384 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003385
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003386 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003387 getDerived().TransformTemplateName(SS,
3388 SpecTL.getTypePtr()->getTemplateName(),
3389 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003390 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003391 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003392 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003393
3394 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003395 Template);
3396 } else if (isa<DependentTemplateSpecializationType>(T)) {
3397 DependentTemplateSpecializationTypeLoc SpecTL
3398 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003399
Douglas Gregora88f09f2011-02-28 17:23:35 +00003400 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003401 = getDerived().RebuildTemplateName(SS,
3402 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003403 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003404 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003405 if (Template.isNull())
3406 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003407
3408 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003409 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003410 Template,
3411 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003412 } else {
3413 // Nothing special needs to be done for these.
3414 Result = getDerived().TransformType(TLB, TL);
3415 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003416
3417 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003418 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003419
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003420 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3421}
3422
Douglas Gregorb71d8212011-03-02 18:32:08 +00003423template<typename Derived>
3424TypeSourceInfo *
3425TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3426 QualType ObjectType,
3427 NamedDecl *UnqualLookup,
3428 CXXScopeSpec &SS) {
3429 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003430
Douglas Gregorb71d8212011-03-02 18:32:08 +00003431 QualType T = TSInfo->getType();
3432 if (getDerived().AlreadyTransformed(T))
3433 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003434
Douglas Gregorb71d8212011-03-02 18:32:08 +00003435 TypeLocBuilder TLB;
3436 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003437
Douglas Gregorb71d8212011-03-02 18:32:08 +00003438 TypeLoc TL = TSInfo->getTypeLoc();
3439 if (isa<TemplateSpecializationType>(T)) {
3440 TemplateSpecializationTypeLoc SpecTL
3441 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003442
Douglas Gregorb71d8212011-03-02 18:32:08 +00003443 TemplateName Template
3444 = getDerived().TransformTemplateName(SS,
3445 SpecTL.getTypePtr()->getTemplateName(),
3446 SpecTL.getTemplateNameLoc(),
3447 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003448 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003449 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003450
3451 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003452 Template);
3453 } else if (isa<DependentTemplateSpecializationType>(T)) {
3454 DependentTemplateSpecializationTypeLoc SpecTL
3455 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003456
Douglas Gregorb71d8212011-03-02 18:32:08 +00003457 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003458 = getDerived().RebuildTemplateName(SS,
3459 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003460 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003461 ObjectType, UnqualLookup);
3462 if (Template.isNull())
3463 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003464
3465 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003466 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003467 Template,
3468 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003469 } else {
3470 // Nothing special needs to be done for these.
3471 Result = getDerived().TransformType(TLB, TL);
3472 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003473
3474 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003475 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003476
Douglas Gregorb71d8212011-03-02 18:32:08 +00003477 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3478}
3479
John McCalla2becad2009-10-21 00:40:46 +00003480template <class TyLoc> static inline
3481QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3482 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3483 NewT.setNameLoc(T.getNameLoc());
3484 return T.getType();
3485}
3486
John McCalla2becad2009-10-21 00:40:46 +00003487template<typename Derived>
3488QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003489 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003490 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3491 NewT.setBuiltinLoc(T.getBuiltinLoc());
3492 if (T.needsExtraLocalData())
3493 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3494 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003495}
Mike Stump1eb44332009-09-09 15:08:12 +00003496
Douglas Gregor577f75a2009-08-04 16:50:30 +00003497template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003498QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003499 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003500 // FIXME: recurse?
3501 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003502}
Mike Stump1eb44332009-09-09 15:08:12 +00003503
Douglas Gregor577f75a2009-08-04 16:50:30 +00003504template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003505QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003506 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003507 QualType PointeeType
3508 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003509 if (PointeeType.isNull())
3510 return QualType();
3511
3512 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003513 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003514 // A dependent pointer type 'T *' has is being transformed such
3515 // that an Objective-C class type is being replaced for 'T'. The
3516 // resulting pointer type is an ObjCObjectPointerType, not a
3517 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003518 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003519
John McCallc12c5bb2010-05-15 11:32:37 +00003520 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3521 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003522 return Result;
3523 }
John McCall43fed0d2010-11-12 08:19:04 +00003524
Douglas Gregor92e986e2010-04-22 16:44:27 +00003525 if (getDerived().AlwaysRebuild() ||
3526 PointeeType != TL.getPointeeLoc().getType()) {
3527 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3528 if (Result.isNull())
3529 return QualType();
3530 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003531
John McCallf85e1932011-06-15 23:02:42 +00003532 // Objective-C ARC can add lifetime qualifiers to the type that we're
3533 // pointing to.
3534 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003535
Douglas Gregor92e986e2010-04-22 16:44:27 +00003536 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3537 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003538 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003539}
Mike Stump1eb44332009-09-09 15:08:12 +00003540
3541template<typename Derived>
3542QualType
John McCalla2becad2009-10-21 00:40:46 +00003543TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003544 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003545 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003546 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3547 if (PointeeType.isNull())
3548 return QualType();
3549
3550 QualType Result = TL.getType();
3551 if (getDerived().AlwaysRebuild() ||
3552 PointeeType != TL.getPointeeLoc().getType()) {
3553 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003554 TL.getSigilLoc());
3555 if (Result.isNull())
3556 return QualType();
3557 }
3558
Douglas Gregor39968ad2010-04-22 16:50:51 +00003559 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003560 NewT.setSigilLoc(TL.getSigilLoc());
3561 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003562}
3563
John McCall85737a72009-10-30 00:06:24 +00003564/// Transforms a reference type. Note that somewhat paradoxically we
3565/// don't care whether the type itself is an l-value type or an r-value
3566/// type; we only care if the type was *written* as an l-value type
3567/// or an r-value type.
3568template<typename Derived>
3569QualType
3570TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003571 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003572 const ReferenceType *T = TL.getTypePtr();
3573
3574 // Note that this works with the pointee-as-written.
3575 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3576 if (PointeeType.isNull())
3577 return QualType();
3578
3579 QualType Result = TL.getType();
3580 if (getDerived().AlwaysRebuild() ||
3581 PointeeType != T->getPointeeTypeAsWritten()) {
3582 Result = getDerived().RebuildReferenceType(PointeeType,
3583 T->isSpelledAsLValue(),
3584 TL.getSigilLoc());
3585 if (Result.isNull())
3586 return QualType();
3587 }
3588
John McCallf85e1932011-06-15 23:02:42 +00003589 // Objective-C ARC can add lifetime qualifiers to the type that we're
3590 // referring to.
3591 TLB.TypeWasModifiedSafely(
3592 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3593
John McCall85737a72009-10-30 00:06:24 +00003594 // r-value references can be rebuilt as l-value references.
3595 ReferenceTypeLoc NewTL;
3596 if (isa<LValueReferenceType>(Result))
3597 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3598 else
3599 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3600 NewTL.setSigilLoc(TL.getSigilLoc());
3601
3602 return Result;
3603}
3604
Mike Stump1eb44332009-09-09 15:08:12 +00003605template<typename Derived>
3606QualType
John McCalla2becad2009-10-21 00:40:46 +00003607TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003608 LValueReferenceTypeLoc TL) {
3609 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003610}
3611
Mike Stump1eb44332009-09-09 15:08:12 +00003612template<typename Derived>
3613QualType
John McCalla2becad2009-10-21 00:40:46 +00003614TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003615 RValueReferenceTypeLoc TL) {
3616 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003617}
Mike Stump1eb44332009-09-09 15:08:12 +00003618
Douglas Gregor577f75a2009-08-04 16:50:30 +00003619template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003620QualType
John McCalla2becad2009-10-21 00:40:46 +00003621TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003622 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003623 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003624 if (PointeeType.isNull())
3625 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003626
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003627 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3628 TypeSourceInfo* NewClsTInfo = 0;
3629 if (OldClsTInfo) {
3630 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3631 if (!NewClsTInfo)
3632 return QualType();
3633 }
3634
3635 const MemberPointerType *T = TL.getTypePtr();
3636 QualType OldClsType = QualType(T->getClass(), 0);
3637 QualType NewClsType;
3638 if (NewClsTInfo)
3639 NewClsType = NewClsTInfo->getType();
3640 else {
3641 NewClsType = getDerived().TransformType(OldClsType);
3642 if (NewClsType.isNull())
3643 return QualType();
3644 }
Mike Stump1eb44332009-09-09 15:08:12 +00003645
John McCalla2becad2009-10-21 00:40:46 +00003646 QualType Result = TL.getType();
3647 if (getDerived().AlwaysRebuild() ||
3648 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003649 NewClsType != OldClsType) {
3650 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003651 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003652 if (Result.isNull())
3653 return QualType();
3654 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003655
John McCalla2becad2009-10-21 00:40:46 +00003656 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3657 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003658 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003659
3660 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003661}
3662
Mike Stump1eb44332009-09-09 15:08:12 +00003663template<typename Derived>
3664QualType
John McCalla2becad2009-10-21 00:40:46 +00003665TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003666 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003667 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003668 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003669 if (ElementType.isNull())
3670 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003671
John McCalla2becad2009-10-21 00:40:46 +00003672 QualType Result = TL.getType();
3673 if (getDerived().AlwaysRebuild() ||
3674 ElementType != T->getElementType()) {
3675 Result = getDerived().RebuildConstantArrayType(ElementType,
3676 T->getSizeModifier(),
3677 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003678 T->getIndexTypeCVRQualifiers(),
3679 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003680 if (Result.isNull())
3681 return QualType();
3682 }
Eli Friedman457a3772012-01-25 22:19:07 +00003683
3684 // We might have either a ConstantArrayType or a VariableArrayType now:
3685 // a ConstantArrayType is allowed to have an element type which is a
3686 // VariableArrayType if the type is dependent. Fortunately, all array
3687 // types have the same location layout.
3688 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003689 NewTL.setLBracketLoc(TL.getLBracketLoc());
3690 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003691
John McCalla2becad2009-10-21 00:40:46 +00003692 Expr *Size = TL.getSizeExpr();
3693 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003694 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3695 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003696 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003697 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003698 }
3699 NewTL.setSizeExpr(Size);
3700
3701 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003702}
Mike Stump1eb44332009-09-09 15:08:12 +00003703
Douglas Gregor577f75a2009-08-04 16:50:30 +00003704template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003705QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003706 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003707 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003708 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003709 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003710 if (ElementType.isNull())
3711 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003712
John McCalla2becad2009-10-21 00:40:46 +00003713 QualType Result = TL.getType();
3714 if (getDerived().AlwaysRebuild() ||
3715 ElementType != T->getElementType()) {
3716 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003717 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003718 T->getIndexTypeCVRQualifiers(),
3719 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003720 if (Result.isNull())
3721 return QualType();
3722 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003723
John McCalla2becad2009-10-21 00:40:46 +00003724 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3725 NewTL.setLBracketLoc(TL.getLBracketLoc());
3726 NewTL.setRBracketLoc(TL.getRBracketLoc());
3727 NewTL.setSizeExpr(0);
3728
3729 return Result;
3730}
3731
3732template<typename Derived>
3733QualType
3734TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003735 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003736 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003737 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3738 if (ElementType.isNull())
3739 return QualType();
3740
John McCall60d7b3a2010-08-24 06:29:42 +00003741 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003742 = getDerived().TransformExpr(T->getSizeExpr());
3743 if (SizeResult.isInvalid())
3744 return QualType();
3745
John McCall9ae2f072010-08-23 23:25:46 +00003746 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003747
3748 QualType Result = TL.getType();
3749 if (getDerived().AlwaysRebuild() ||
3750 ElementType != T->getElementType() ||
3751 Size != T->getSizeExpr()) {
3752 Result = getDerived().RebuildVariableArrayType(ElementType,
3753 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003754 Size,
John McCalla2becad2009-10-21 00:40:46 +00003755 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003756 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003757 if (Result.isNull())
3758 return QualType();
3759 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003760
John McCalla2becad2009-10-21 00:40:46 +00003761 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3762 NewTL.setLBracketLoc(TL.getLBracketLoc());
3763 NewTL.setRBracketLoc(TL.getRBracketLoc());
3764 NewTL.setSizeExpr(Size);
3765
3766 return Result;
3767}
3768
3769template<typename Derived>
3770QualType
3771TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003772 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003773 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003774 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3775 if (ElementType.isNull())
3776 return QualType();
3777
Richard Smithf6702a32011-12-20 02:08:33 +00003778 // Array bounds are constant expressions.
3779 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3780 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003781
John McCall3b657512011-01-19 10:06:00 +00003782 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3783 Expr *origSize = TL.getSizeExpr();
3784 if (!origSize) origSize = T->getSizeExpr();
3785
3786 ExprResult sizeResult
3787 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003788 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003789 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003790 return QualType();
3791
John McCall3b657512011-01-19 10:06:00 +00003792 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003793
3794 QualType Result = TL.getType();
3795 if (getDerived().AlwaysRebuild() ||
3796 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003797 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003798 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3799 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003800 size,
John McCalla2becad2009-10-21 00:40:46 +00003801 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003802 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003803 if (Result.isNull())
3804 return QualType();
3805 }
John McCalla2becad2009-10-21 00:40:46 +00003806
3807 // We might have any sort of array type now, but fortunately they
3808 // all have the same location layout.
3809 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3810 NewTL.setLBracketLoc(TL.getLBracketLoc());
3811 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003812 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003813
3814 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003815}
Mike Stump1eb44332009-09-09 15:08:12 +00003816
3817template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003818QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003819 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003820 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003821 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003822
3823 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003824 QualType ElementType = getDerived().TransformType(T->getElementType());
3825 if (ElementType.isNull())
3826 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003827
Richard Smithf6702a32011-12-20 02:08:33 +00003828 // Vector sizes are constant expressions.
3829 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3830 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003831
John McCall60d7b3a2010-08-24 06:29:42 +00003832 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003833 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003834 if (Size.isInvalid())
3835 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003836
John McCalla2becad2009-10-21 00:40:46 +00003837 QualType Result = TL.getType();
3838 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003839 ElementType != T->getElementType() ||
3840 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003841 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003842 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003843 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003844 if (Result.isNull())
3845 return QualType();
3846 }
John McCalla2becad2009-10-21 00:40:46 +00003847
3848 // Result might be dependent or not.
3849 if (isa<DependentSizedExtVectorType>(Result)) {
3850 DependentSizedExtVectorTypeLoc NewTL
3851 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3852 NewTL.setNameLoc(TL.getNameLoc());
3853 } else {
3854 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3855 NewTL.setNameLoc(TL.getNameLoc());
3856 }
3857
3858 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003859}
Mike Stump1eb44332009-09-09 15:08:12 +00003860
3861template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003862QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003863 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003864 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003865 QualType ElementType = getDerived().TransformType(T->getElementType());
3866 if (ElementType.isNull())
3867 return QualType();
3868
John McCalla2becad2009-10-21 00:40:46 +00003869 QualType Result = TL.getType();
3870 if (getDerived().AlwaysRebuild() ||
3871 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003872 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003873 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003874 if (Result.isNull())
3875 return QualType();
3876 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003877
John McCalla2becad2009-10-21 00:40:46 +00003878 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3879 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003880
John McCalla2becad2009-10-21 00:40:46 +00003881 return Result;
3882}
3883
3884template<typename Derived>
3885QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003886 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003887 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003888 QualType ElementType = getDerived().TransformType(T->getElementType());
3889 if (ElementType.isNull())
3890 return QualType();
3891
3892 QualType Result = TL.getType();
3893 if (getDerived().AlwaysRebuild() ||
3894 ElementType != T->getElementType()) {
3895 Result = getDerived().RebuildExtVectorType(ElementType,
3896 T->getNumElements(),
3897 /*FIXME*/ SourceLocation());
3898 if (Result.isNull())
3899 return QualType();
3900 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003901
John McCalla2becad2009-10-21 00:40:46 +00003902 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3903 NewTL.setNameLoc(TL.getNameLoc());
3904
3905 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003906}
Mike Stump1eb44332009-09-09 15:08:12 +00003907
3908template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003909ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003910TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003911 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003912 llvm::Optional<unsigned> NumExpansions,
3913 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003914 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003915 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003916
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003917 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003918 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003919 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003920 TypeLoc OldTL = OldDI->getTypeLoc();
3921 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003922
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003923 TypeLocBuilder TLB;
3924 TypeLoc NewTL = OldDI->getTypeLoc();
3925 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003926
3927 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003928 OldExpansionTL.getPatternLoc());
3929 if (Result.isNull())
3930 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003931
3932 Result = RebuildPackExpansionType(Result,
3933 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003934 OldExpansionTL.getEllipsisLoc(),
3935 NumExpansions);
3936 if (Result.isNull())
3937 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003938
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003939 PackExpansionTypeLoc NewExpansionTL
3940 = TLB.push<PackExpansionTypeLoc>(Result);
3941 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3942 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3943 } else
3944 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003945 if (!NewDI)
3946 return 0;
3947
John McCallfb44de92011-05-01 22:35:37 +00003948 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003949 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003950
3951 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3952 OldParm->getDeclContext(),
3953 OldParm->getInnerLocStart(),
3954 OldParm->getLocation(),
3955 OldParm->getIdentifier(),
3956 NewDI->getType(),
3957 NewDI,
3958 OldParm->getStorageClass(),
3959 OldParm->getStorageClassAsWritten(),
3960 /* DefArg */ NULL);
3961 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3962 OldParm->getFunctionScopeIndex() + indexAdjustment);
3963 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003964}
3965
3966template<typename Derived>
3967bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003968 TransformFunctionTypeParams(SourceLocation Loc,
3969 ParmVarDecl **Params, unsigned NumParams,
3970 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003971 SmallVectorImpl<QualType> &OutParamTypes,
3972 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003973 int indexAdjustment = 0;
3974
Douglas Gregora009b592011-01-07 00:20:55 +00003975 for (unsigned i = 0; i != NumParams; ++i) {
3976 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003977 assert(OldParm->getFunctionScopeIndex() == i);
3978
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003979 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003980 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003981 if (OldParm->isParameterPack()) {
3982 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003983 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003984
Douglas Gregor603cfb42011-01-05 23:12:31 +00003985 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003986 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3987 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3988 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3989 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003990 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3991
Douglas Gregor603cfb42011-01-05 23:12:31 +00003992 // Determine whether we should expand the parameter packs.
3993 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003994 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003995 llvm::Optional<unsigned> OrigNumExpansions
3996 = ExpansionTL.getTypePtr()->getNumExpansions();
3997 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003998 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3999 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004000 Unexpanded,
4001 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004002 RetainExpansion,
4003 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004004 return true;
4005 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004006
Douglas Gregor603cfb42011-01-05 23:12:31 +00004007 if (ShouldExpand) {
4008 // Expand the function parameter pack into multiple, separate
4009 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004010 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004011 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004012 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004013 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004014 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004015 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004016 OrigNumExpansions,
4017 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004018 if (!NewParm)
4019 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004020
Douglas Gregora009b592011-01-07 00:20:55 +00004021 OutParamTypes.push_back(NewParm->getType());
4022 if (PVars)
4023 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004024 }
Douglas Gregord3731192011-01-10 07:32:04 +00004025
4026 // If we're supposed to retain a pack expansion, do so by temporarily
4027 // forgetting the partially-substituted parameter pack.
4028 if (RetainExpansion) {
4029 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004030 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004031 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004032 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004033 OrigNumExpansions,
4034 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004035 if (!NewParm)
4036 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004037
Douglas Gregord3731192011-01-10 07:32:04 +00004038 OutParamTypes.push_back(NewParm->getType());
4039 if (PVars)
4040 PVars->push_back(NewParm);
4041 }
4042
John McCallfb44de92011-05-01 22:35:37 +00004043 // The next parameter should have the same adjustment as the
4044 // last thing we pushed, but we post-incremented indexAdjustment
4045 // on every push. Also, if we push nothing, the adjustment should
4046 // go down by one.
4047 indexAdjustment--;
4048
Douglas Gregor603cfb42011-01-05 23:12:31 +00004049 // We're done with the pack expansion.
4050 continue;
4051 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004052
4053 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004054 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004055 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4056 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004057 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004058 NumExpansions,
4059 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004060 } else {
4061 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004062 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004063 llvm::Optional<unsigned>(),
4064 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004065 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004066
John McCall21ef0fa2010-03-11 09:03:00 +00004067 if (!NewParm)
4068 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004069
Douglas Gregora009b592011-01-07 00:20:55 +00004070 OutParamTypes.push_back(NewParm->getType());
4071 if (PVars)
4072 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004073 continue;
4074 }
John McCall21ef0fa2010-03-11 09:03:00 +00004075
4076 // Deal with the possibility that we don't have a parameter
4077 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004078 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004079 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004080 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004081 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004082 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004083 = dyn_cast<PackExpansionType>(OldType)) {
4084 // We have a function parameter pack that may need to be expanded.
4085 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004086 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004087 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004088
Douglas Gregor603cfb42011-01-05 23:12:31 +00004089 // Determine whether we should expand the parameter packs.
4090 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004091 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004092 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004093 Unexpanded,
4094 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004095 RetainExpansion,
4096 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004097 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004098 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004099
Douglas Gregor603cfb42011-01-05 23:12:31 +00004100 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004101 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004102 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004103 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004104 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4105 QualType NewType = getDerived().TransformType(Pattern);
4106 if (NewType.isNull())
4107 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004108
Douglas Gregora009b592011-01-07 00:20:55 +00004109 OutParamTypes.push_back(NewType);
4110 if (PVars)
4111 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004112 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004113
Douglas Gregor603cfb42011-01-05 23:12:31 +00004114 // We're done with the pack expansion.
4115 continue;
4116 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004117
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004118 // If we're supposed to retain a pack expansion, do so by temporarily
4119 // forgetting the partially-substituted parameter pack.
4120 if (RetainExpansion) {
4121 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4122 QualType NewType = getDerived().TransformType(Pattern);
4123 if (NewType.isNull())
4124 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004125
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004126 OutParamTypes.push_back(NewType);
4127 if (PVars)
4128 PVars->push_back(0);
4129 }
Douglas Gregord3731192011-01-10 07:32:04 +00004130
Chad Rosier4a9d7952012-08-08 18:46:20 +00004131 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004132 // expansion.
4133 OldType = Expansion->getPattern();
4134 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004135 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4136 NewType = getDerived().TransformType(OldType);
4137 } else {
4138 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004139 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004140
Douglas Gregor603cfb42011-01-05 23:12:31 +00004141 if (NewType.isNull())
4142 return true;
4143
4144 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004145 NewType = getSema().Context.getPackExpansionType(NewType,
4146 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004147
Douglas Gregora009b592011-01-07 00:20:55 +00004148 OutParamTypes.push_back(NewType);
4149 if (PVars)
4150 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004151 }
4152
John McCallfb44de92011-05-01 22:35:37 +00004153#ifndef NDEBUG
4154 if (PVars) {
4155 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4156 if (ParmVarDecl *parm = (*PVars)[i])
4157 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004158 }
John McCallfb44de92011-05-01 22:35:37 +00004159#endif
4160
4161 return false;
4162}
John McCall21ef0fa2010-03-11 09:03:00 +00004163
4164template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004165QualType
John McCalla2becad2009-10-21 00:40:46 +00004166TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004167 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004168 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4169}
4170
4171template<typename Derived>
4172QualType
4173TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4174 FunctionProtoTypeLoc TL,
4175 CXXRecordDecl *ThisContext,
4176 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004177 // Transform the parameters and return type.
4178 //
Richard Smithe6975e92012-04-17 00:58:00 +00004179 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004180 // When the function has a trailing return type, we instantiate the
4181 // parameters before the return type, since the return type can then refer
4182 // to the parameters themselves (via decltype, sizeof, etc.).
4183 //
Chris Lattner686775d2011-07-20 06:58:45 +00004184 SmallVector<QualType, 4> ParamTypes;
4185 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004186 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004187
Douglas Gregordab60ad2010-10-01 18:44:50 +00004188 QualType ResultType;
4189
Richard Smith9fbf3272012-08-14 22:51:13 +00004190 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004191 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004192 TL.getParmArray(),
4193 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004194 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004195 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004196 return QualType();
4197
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004198 {
4199 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004200 // If a declaration declares a member function or member function
4201 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004202 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004203 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004204 // declarator.
4205 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004206
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004207 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4208 if (ResultType.isNull())
4209 return QualType();
4210 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004211 }
4212 else {
4213 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4214 if (ResultType.isNull())
4215 return QualType();
4216
Chad Rosier4a9d7952012-08-08 18:46:20 +00004217 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004218 TL.getParmArray(),
4219 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004220 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004221 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004222 return QualType();
4223 }
4224
Richard Smithe6975e92012-04-17 00:58:00 +00004225 // FIXME: Need to transform the exception-specification too.
4226
John McCalla2becad2009-10-21 00:40:46 +00004227 QualType Result = TL.getType();
4228 if (getDerived().AlwaysRebuild() ||
4229 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004230 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004231 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4232 Result = getDerived().RebuildFunctionProtoType(ResultType,
4233 ParamTypes.data(),
4234 ParamTypes.size(),
4235 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004236 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004237 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004238 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004239 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004240 if (Result.isNull())
4241 return QualType();
4242 }
Mike Stump1eb44332009-09-09 15:08:12 +00004243
John McCalla2becad2009-10-21 00:40:46 +00004244 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004245 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4246 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004247 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4248 NewTL.setArg(i, ParamDecls[i]);
4249
4250 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004251}
Mike Stump1eb44332009-09-09 15:08:12 +00004252
Douglas Gregor577f75a2009-08-04 16:50:30 +00004253template<typename Derived>
4254QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004255 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004256 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004257 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004258 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4259 if (ResultType.isNull())
4260 return QualType();
4261
4262 QualType Result = TL.getType();
4263 if (getDerived().AlwaysRebuild() ||
4264 ResultType != T->getResultType())
4265 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4266
4267 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004268 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4269 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004270
4271 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004272}
Mike Stump1eb44332009-09-09 15:08:12 +00004273
John McCalled976492009-12-04 22:46:56 +00004274template<typename Derived> QualType
4275TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004276 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004277 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004278 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004279 if (!D)
4280 return QualType();
4281
4282 QualType Result = TL.getType();
4283 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4284 Result = getDerived().RebuildUnresolvedUsingType(D);
4285 if (Result.isNull())
4286 return QualType();
4287 }
4288
4289 // We might get an arbitrary type spec type back. We should at
4290 // least always get a type spec type, though.
4291 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4292 NewTL.setNameLoc(TL.getNameLoc());
4293
4294 return Result;
4295}
4296
Douglas Gregor577f75a2009-08-04 16:50:30 +00004297template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004298QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004299 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004300 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004301 TypedefNameDecl *Typedef
4302 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4303 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004304 if (!Typedef)
4305 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004306
John McCalla2becad2009-10-21 00:40:46 +00004307 QualType Result = TL.getType();
4308 if (getDerived().AlwaysRebuild() ||
4309 Typedef != T->getDecl()) {
4310 Result = getDerived().RebuildTypedefType(Typedef);
4311 if (Result.isNull())
4312 return QualType();
4313 }
Mike Stump1eb44332009-09-09 15:08:12 +00004314
John McCalla2becad2009-10-21 00:40:46 +00004315 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4316 NewTL.setNameLoc(TL.getNameLoc());
4317
4318 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004319}
Mike Stump1eb44332009-09-09 15:08:12 +00004320
Douglas Gregor577f75a2009-08-04 16:50:30 +00004321template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004322QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004323 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004324 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004325 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004326
John McCall60d7b3a2010-08-24 06:29:42 +00004327 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004328 if (E.isInvalid())
4329 return QualType();
4330
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004331 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4332 if (E.isInvalid())
4333 return QualType();
4334
John McCalla2becad2009-10-21 00:40:46 +00004335 QualType Result = TL.getType();
4336 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004337 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004338 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004339 if (Result.isNull())
4340 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004341 }
John McCalla2becad2009-10-21 00:40:46 +00004342 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004343
John McCalla2becad2009-10-21 00:40:46 +00004344 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004345 NewTL.setTypeofLoc(TL.getTypeofLoc());
4346 NewTL.setLParenLoc(TL.getLParenLoc());
4347 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004348
4349 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004350}
Mike Stump1eb44332009-09-09 15:08:12 +00004351
4352template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004353QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004354 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004355 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4356 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4357 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004358 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004359
John McCalla2becad2009-10-21 00:40:46 +00004360 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004361 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4362 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004363 if (Result.isNull())
4364 return QualType();
4365 }
Mike Stump1eb44332009-09-09 15:08:12 +00004366
John McCalla2becad2009-10-21 00:40:46 +00004367 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004368 NewTL.setTypeofLoc(TL.getTypeofLoc());
4369 NewTL.setLParenLoc(TL.getLParenLoc());
4370 NewTL.setRParenLoc(TL.getRParenLoc());
4371 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004372
4373 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004374}
Mike Stump1eb44332009-09-09 15:08:12 +00004375
4376template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004377QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004378 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004379 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004380
Douglas Gregor670444e2009-08-04 22:27:00 +00004381 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004382 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4383 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004384
John McCall60d7b3a2010-08-24 06:29:42 +00004385 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004386 if (E.isInvalid())
4387 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004388
Richard Smith76f3f692012-02-22 02:04:18 +00004389 E = getSema().ActOnDecltypeExpression(E.take());
4390 if (E.isInvalid())
4391 return QualType();
4392
John McCalla2becad2009-10-21 00:40:46 +00004393 QualType Result = TL.getType();
4394 if (getDerived().AlwaysRebuild() ||
4395 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004396 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004397 if (Result.isNull())
4398 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004399 }
John McCalla2becad2009-10-21 00:40:46 +00004400 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004401
John McCalla2becad2009-10-21 00:40:46 +00004402 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4403 NewTL.setNameLoc(TL.getNameLoc());
4404
4405 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004406}
4407
4408template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004409QualType TreeTransform<Derived>::TransformUnaryTransformType(
4410 TypeLocBuilder &TLB,
4411 UnaryTransformTypeLoc TL) {
4412 QualType Result = TL.getType();
4413 if (Result->isDependentType()) {
4414 const UnaryTransformType *T = TL.getTypePtr();
4415 QualType NewBase =
4416 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4417 Result = getDerived().RebuildUnaryTransformType(NewBase,
4418 T->getUTTKind(),
4419 TL.getKWLoc());
4420 if (Result.isNull())
4421 return QualType();
4422 }
4423
4424 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4425 NewTL.setKWLoc(TL.getKWLoc());
4426 NewTL.setParensRange(TL.getParensRange());
4427 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4428 return Result;
4429}
4430
4431template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004432QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4433 AutoTypeLoc TL) {
4434 const AutoType *T = TL.getTypePtr();
4435 QualType OldDeduced = T->getDeducedType();
4436 QualType NewDeduced;
4437 if (!OldDeduced.isNull()) {
4438 NewDeduced = getDerived().TransformType(OldDeduced);
4439 if (NewDeduced.isNull())
4440 return QualType();
4441 }
4442
4443 QualType Result = TL.getType();
4444 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4445 Result = getDerived().RebuildAutoType(NewDeduced);
4446 if (Result.isNull())
4447 return QualType();
4448 }
4449
4450 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4451 NewTL.setNameLoc(TL.getNameLoc());
4452
4453 return Result;
4454}
4455
4456template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004457QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004458 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004459 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004460 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004461 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4462 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004463 if (!Record)
4464 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004465
John McCalla2becad2009-10-21 00:40:46 +00004466 QualType Result = TL.getType();
4467 if (getDerived().AlwaysRebuild() ||
4468 Record != T->getDecl()) {
4469 Result = getDerived().RebuildRecordType(Record);
4470 if (Result.isNull())
4471 return QualType();
4472 }
Mike Stump1eb44332009-09-09 15:08:12 +00004473
John McCalla2becad2009-10-21 00:40:46 +00004474 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4475 NewTL.setNameLoc(TL.getNameLoc());
4476
4477 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004478}
Mike Stump1eb44332009-09-09 15:08:12 +00004479
4480template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004481QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004482 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004483 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004484 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004485 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4486 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004487 if (!Enum)
4488 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004489
John McCalla2becad2009-10-21 00:40:46 +00004490 QualType Result = TL.getType();
4491 if (getDerived().AlwaysRebuild() ||
4492 Enum != T->getDecl()) {
4493 Result = getDerived().RebuildEnumType(Enum);
4494 if (Result.isNull())
4495 return QualType();
4496 }
Mike Stump1eb44332009-09-09 15:08:12 +00004497
John McCalla2becad2009-10-21 00:40:46 +00004498 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4499 NewTL.setNameLoc(TL.getNameLoc());
4500
4501 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004502}
John McCall7da24312009-09-05 00:15:47 +00004503
John McCall3cb0ebd2010-03-10 03:28:59 +00004504template<typename Derived>
4505QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4506 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004507 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004508 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4509 TL.getTypePtr()->getDecl());
4510 if (!D) return QualType();
4511
4512 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4513 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4514 return T;
4515}
4516
Douglas Gregor577f75a2009-08-04 16:50:30 +00004517template<typename Derived>
4518QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004519 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004520 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004521 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004522}
4523
Mike Stump1eb44332009-09-09 15:08:12 +00004524template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004525QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004526 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004527 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004528 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004529
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004530 // Substitute into the replacement type, which itself might involve something
4531 // that needs to be transformed. This only tends to occur with default
4532 // template arguments of template template parameters.
4533 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4534 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4535 if (Replacement.isNull())
4536 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004537
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004538 // Always canonicalize the replacement type.
4539 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4540 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004541 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004542 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004543
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004544 // Propagate type-source information.
4545 SubstTemplateTypeParmTypeLoc NewTL
4546 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4547 NewTL.setNameLoc(TL.getNameLoc());
4548 return Result;
4549
John McCall49a832b2009-10-18 09:09:24 +00004550}
4551
4552template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004553QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4554 TypeLocBuilder &TLB,
4555 SubstTemplateTypeParmPackTypeLoc TL) {
4556 return TransformTypeSpecType(TLB, TL);
4557}
4558
4559template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004560QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004561 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004562 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004563 const TemplateSpecializationType *T = TL.getTypePtr();
4564
Douglas Gregor1d752d72011-03-02 18:46:51 +00004565 // The nested-name-specifier never matters in a TemplateSpecializationType,
4566 // because we can't have a dependent nested-name-specifier anyway.
4567 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004568 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004569 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4570 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004571 if (Template.isNull())
4572 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004573
John McCall43fed0d2010-11-12 08:19:04 +00004574 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4575}
4576
Eli Friedmanb001de72011-10-06 23:00:33 +00004577template<typename Derived>
4578QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4579 AtomicTypeLoc TL) {
4580 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4581 if (ValueType.isNull())
4582 return QualType();
4583
4584 QualType Result = TL.getType();
4585 if (getDerived().AlwaysRebuild() ||
4586 ValueType != TL.getValueLoc().getType()) {
4587 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4588 if (Result.isNull())
4589 return QualType();
4590 }
4591
4592 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4593 NewTL.setKWLoc(TL.getKWLoc());
4594 NewTL.setLParenLoc(TL.getLParenLoc());
4595 NewTL.setRParenLoc(TL.getRParenLoc());
4596
4597 return Result;
4598}
4599
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004600namespace {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004601 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004602 /// container that provides a \c getArgLoc() member function.
4603 ///
4604 /// This iterator is intended to be used with the iterator form of
4605 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4606 template<typename ArgLocContainer>
4607 class TemplateArgumentLocContainerIterator {
4608 ArgLocContainer *Container;
4609 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004610
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004611 public:
4612 typedef TemplateArgumentLoc value_type;
4613 typedef TemplateArgumentLoc reference;
4614 typedef int difference_type;
4615 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004616
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004617 class pointer {
4618 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004619
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004620 public:
4621 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004622
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004623 const TemplateArgumentLoc *operator->() const {
4624 return &Arg;
4625 }
4626 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004627
4628
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004629 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004630
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004631 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4632 unsigned Index)
4633 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004634
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004635 TemplateArgumentLocContainerIterator &operator++() {
4636 ++Index;
4637 return *this;
4638 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004639
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004640 TemplateArgumentLocContainerIterator operator++(int) {
4641 TemplateArgumentLocContainerIterator Old(*this);
4642 ++(*this);
4643 return Old;
4644 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004645
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004646 TemplateArgumentLoc operator*() const {
4647 return Container->getArgLoc(Index);
4648 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004649
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004650 pointer operator->() const {
4651 return pointer(Container->getArgLoc(Index));
4652 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004653
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004654 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004655 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004656 return X.Container == Y.Container && X.Index == Y.Index;
4657 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004658
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004659 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004660 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004661 return !(X == Y);
4662 }
4663 };
4664}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004665
4666
John McCall43fed0d2010-11-12 08:19:04 +00004667template <typename Derived>
4668QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4669 TypeLocBuilder &TLB,
4670 TemplateSpecializationTypeLoc TL,
4671 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004672 TemplateArgumentListInfo NewTemplateArgs;
4673 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4674 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004675 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4676 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004677 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004678 ArgIterator(TL, TL.getNumArgs()),
4679 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004680 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004681
John McCall833ca992009-10-29 08:12:44 +00004682 // FIXME: maybe don't rebuild if all the template arguments are the same.
4683
4684 QualType Result =
4685 getDerived().RebuildTemplateSpecializationType(Template,
4686 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004687 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004688
4689 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004690 // Specializations of template template parameters are represented as
4691 // TemplateSpecializationTypes, and substitution of type alias templates
4692 // within a dependent context can transform them into
4693 // DependentTemplateSpecializationTypes.
4694 if (isa<DependentTemplateSpecializationType>(Result)) {
4695 DependentTemplateSpecializationTypeLoc NewTL
4696 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004697 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004698 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004699 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004700 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004701 NewTL.setLAngleLoc(TL.getLAngleLoc());
4702 NewTL.setRAngleLoc(TL.getRAngleLoc());
4703 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4704 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4705 return Result;
4706 }
4707
John McCall833ca992009-10-29 08:12:44 +00004708 TemplateSpecializationTypeLoc NewTL
4709 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004710 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004711 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4712 NewTL.setLAngleLoc(TL.getLAngleLoc());
4713 NewTL.setRAngleLoc(TL.getRAngleLoc());
4714 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4715 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004716 }
Mike Stump1eb44332009-09-09 15:08:12 +00004717
John McCall833ca992009-10-29 08:12:44 +00004718 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004719}
Mike Stump1eb44332009-09-09 15:08:12 +00004720
Douglas Gregora88f09f2011-02-28 17:23:35 +00004721template <typename Derived>
4722QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4723 TypeLocBuilder &TLB,
4724 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004725 TemplateName Template,
4726 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004727 TemplateArgumentListInfo NewTemplateArgs;
4728 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4729 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4730 typedef TemplateArgumentLocContainerIterator<
4731 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004732 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004733 ArgIterator(TL, TL.getNumArgs()),
4734 NewTemplateArgs))
4735 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004736
Douglas Gregora88f09f2011-02-28 17:23:35 +00004737 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004738
Douglas Gregora88f09f2011-02-28 17:23:35 +00004739 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4740 QualType Result
4741 = getSema().Context.getDependentTemplateSpecializationType(
4742 TL.getTypePtr()->getKeyword(),
4743 DTN->getQualifier(),
4744 DTN->getIdentifier(),
4745 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004746
Douglas Gregora88f09f2011-02-28 17:23:35 +00004747 DependentTemplateSpecializationTypeLoc NewTL
4748 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004749 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004750 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004751 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004752 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004753 NewTL.setLAngleLoc(TL.getLAngleLoc());
4754 NewTL.setRAngleLoc(TL.getRAngleLoc());
4755 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4756 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4757 return Result;
4758 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004759
4760 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004761 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004762 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004763 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004764
Douglas Gregora88f09f2011-02-28 17:23:35 +00004765 if (!Result.isNull()) {
4766 /// FIXME: Wrap this in an elaborated-type-specifier?
4767 TemplateSpecializationTypeLoc NewTL
4768 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004769 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004770 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004771 NewTL.setLAngleLoc(TL.getLAngleLoc());
4772 NewTL.setRAngleLoc(TL.getRAngleLoc());
4773 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4774 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4775 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004776
Douglas Gregora88f09f2011-02-28 17:23:35 +00004777 return Result;
4778}
4779
Mike Stump1eb44332009-09-09 15:08:12 +00004780template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004781QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004782TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004783 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004784 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004785
Douglas Gregor9e876872011-03-01 18:12:44 +00004786 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004787 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004788 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004789 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004790 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4791 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004792 return QualType();
4793 }
Mike Stump1eb44332009-09-09 15:08:12 +00004794
John McCall43fed0d2010-11-12 08:19:04 +00004795 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4796 if (NamedT.isNull())
4797 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004798
Richard Smith3e4c6c42011-05-05 21:57:07 +00004799 // C++0x [dcl.type.elab]p2:
4800 // If the identifier resolves to a typedef-name or the simple-template-id
4801 // resolves to an alias template specialization, the
4802 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004803 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4804 if (const TemplateSpecializationType *TST =
4805 NamedT->getAs<TemplateSpecializationType>()) {
4806 TemplateName Template = TST->getTemplateName();
4807 if (TypeAliasTemplateDecl *TAT =
4808 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4809 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4810 diag::err_tag_reference_non_tag) << 4;
4811 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4812 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004813 }
4814 }
4815
John McCalla2becad2009-10-21 00:40:46 +00004816 QualType Result = TL.getType();
4817 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004818 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004819 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004820 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004821 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004822 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004823 if (Result.isNull())
4824 return QualType();
4825 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004826
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004827 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004828 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004829 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004830 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004831}
Mike Stump1eb44332009-09-09 15:08:12 +00004832
4833template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004834QualType TreeTransform<Derived>::TransformAttributedType(
4835 TypeLocBuilder &TLB,
4836 AttributedTypeLoc TL) {
4837 const AttributedType *oldType = TL.getTypePtr();
4838 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4839 if (modifiedType.isNull())
4840 return QualType();
4841
4842 QualType result = TL.getType();
4843
4844 // FIXME: dependent operand expressions?
4845 if (getDerived().AlwaysRebuild() ||
4846 modifiedType != oldType->getModifiedType()) {
4847 // TODO: this is really lame; we should really be rebuilding the
4848 // equivalent type from first principles.
4849 QualType equivalentType
4850 = getDerived().TransformType(oldType->getEquivalentType());
4851 if (equivalentType.isNull())
4852 return QualType();
4853 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4854 modifiedType,
4855 equivalentType);
4856 }
4857
4858 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4859 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4860 if (TL.hasAttrOperand())
4861 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4862 if (TL.hasAttrExprOperand())
4863 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4864 else if (TL.hasAttrEnumOperand())
4865 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4866
4867 return result;
4868}
4869
4870template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004871QualType
4872TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4873 ParenTypeLoc TL) {
4874 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4875 if (Inner.isNull())
4876 return QualType();
4877
4878 QualType Result = TL.getType();
4879 if (getDerived().AlwaysRebuild() ||
4880 Inner != TL.getInnerLoc().getType()) {
4881 Result = getDerived().RebuildParenType(Inner);
4882 if (Result.isNull())
4883 return QualType();
4884 }
4885
4886 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4887 NewTL.setLParenLoc(TL.getLParenLoc());
4888 NewTL.setRParenLoc(TL.getRParenLoc());
4889 return Result;
4890}
4891
4892template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004893QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004894 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004895 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004896
Douglas Gregor2494dd02011-03-01 01:34:45 +00004897 NestedNameSpecifierLoc QualifierLoc
4898 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4899 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004900 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004901
John McCall33500952010-06-11 00:33:02 +00004902 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004903 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004904 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004905 QualifierLoc,
4906 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004907 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004908 if (Result.isNull())
4909 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004910
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004911 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4912 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004913 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4914
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004915 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004916 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004917 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004918 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004919 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004920 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004921 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004922 NewTL.setNameLoc(TL.getNameLoc());
4923 }
John McCalla2becad2009-10-21 00:40:46 +00004924 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004925}
Mike Stump1eb44332009-09-09 15:08:12 +00004926
Douglas Gregor577f75a2009-08-04 16:50:30 +00004927template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004928QualType TreeTransform<Derived>::
4929 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004930 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004931 NestedNameSpecifierLoc QualifierLoc;
4932 if (TL.getQualifierLoc()) {
4933 QualifierLoc
4934 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4935 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004936 return QualType();
4937 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004938
John McCall43fed0d2010-11-12 08:19:04 +00004939 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004940 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004941}
4942
4943template<typename Derived>
4944QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004945TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4946 DependentTemplateSpecializationTypeLoc TL,
4947 NestedNameSpecifierLoc QualifierLoc) {
4948 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004949
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004950 TemplateArgumentListInfo NewTemplateArgs;
4951 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4952 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004953
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004954 typedef TemplateArgumentLocContainerIterator<
4955 DependentTemplateSpecializationTypeLoc> ArgIterator;
4956 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4957 ArgIterator(TL, TL.getNumArgs()),
4958 NewTemplateArgs))
4959 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004960
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004961 QualType Result
4962 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4963 QualifierLoc,
4964 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004965 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004966 NewTemplateArgs);
4967 if (Result.isNull())
4968 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004969
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004970 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4971 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004972
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004973 // Copy information relevant to the template specialization.
4974 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004975 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004976 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004977 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004978 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4979 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004980 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004981 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004982
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004983 // Copy information relevant to the elaborated type.
4984 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004985 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004986 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004987 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4988 DependentTemplateSpecializationTypeLoc SpecTL
4989 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004990 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004991 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004992 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004993 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004994 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4995 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004996 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004997 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004998 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004999 TemplateSpecializationTypeLoc SpecTL
5000 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005001 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005002 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005003 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5004 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005005 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005006 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005007 }
5008 return Result;
5009}
5010
5011template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005012QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5013 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005014 QualType Pattern
5015 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005016 if (Pattern.isNull())
5017 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005018
5019 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005020 if (getDerived().AlwaysRebuild() ||
5021 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005022 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005023 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005024 TL.getEllipsisLoc(),
5025 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005026 if (Result.isNull())
5027 return QualType();
5028 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005029
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005030 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5031 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5032 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005033}
5034
5035template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005036QualType
5037TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005038 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005039 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005040 TLB.pushFullCopy(TL);
5041 return TL.getType();
5042}
5043
5044template<typename Derived>
5045QualType
5046TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005047 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005048 // ObjCObjectType is never dependent.
5049 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005050 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005051}
Mike Stump1eb44332009-09-09 15:08:12 +00005052
5053template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005054QualType
5055TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005056 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005057 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005058 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005059 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005060}
5061
Douglas Gregor577f75a2009-08-04 16:50:30 +00005062//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005063// Statement transformation
5064//===----------------------------------------------------------------------===//
5065template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005066StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005067TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005068 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005069}
5070
5071template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005072StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005073TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5074 return getDerived().TransformCompoundStmt(S, false);
5075}
5076
5077template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005078StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005079TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005080 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005081 Sema::CompoundScopeRAII CompoundScope(getSema());
5082
John McCall7114cba2010-08-27 19:56:05 +00005083 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005084 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005085 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005086 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5087 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005088 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005089 if (Result.isInvalid()) {
5090 // Immediately fail if this was a DeclStmt, since it's very
5091 // likely that this will cause problems for future statements.
5092 if (isa<DeclStmt>(*B))
5093 return StmtError();
5094
5095 // Otherwise, just keep processing substatements and fail later.
5096 SubStmtInvalid = true;
5097 continue;
5098 }
Mike Stump1eb44332009-09-09 15:08:12 +00005099
Douglas Gregor43959a92009-08-20 07:17:43 +00005100 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5101 Statements.push_back(Result.takeAs<Stmt>());
5102 }
Mike Stump1eb44332009-09-09 15:08:12 +00005103
John McCall7114cba2010-08-27 19:56:05 +00005104 if (SubStmtInvalid)
5105 return StmtError();
5106
Douglas Gregor43959a92009-08-20 07:17:43 +00005107 if (!getDerived().AlwaysRebuild() &&
5108 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005109 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005110
5111 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005112 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005113 S->getRBracLoc(),
5114 IsStmtExpr);
5115}
Mike Stump1eb44332009-09-09 15:08:12 +00005116
Douglas Gregor43959a92009-08-20 07:17:43 +00005117template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005118StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005119TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005120 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005121 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005122 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5123 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005124
Eli Friedman264c1f82009-11-19 03:14:00 +00005125 // Transform the left-hand case value.
5126 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005127 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005128 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005129 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005130
Eli Friedman264c1f82009-11-19 03:14:00 +00005131 // Transform the right-hand case value (for the GNU case-range extension).
5132 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005133 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005134 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005135 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005136 }
Mike Stump1eb44332009-09-09 15:08:12 +00005137
Douglas Gregor43959a92009-08-20 07:17:43 +00005138 // Build the case statement.
5139 // Case statements are always rebuilt so that they will attached to their
5140 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005141 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005142 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005143 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005144 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005145 S->getColonLoc());
5146 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005147 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005148
Douglas Gregor43959a92009-08-20 07:17:43 +00005149 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005150 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005151 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005152 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005153
Douglas Gregor43959a92009-08-20 07:17:43 +00005154 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005155 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005156}
5157
5158template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005159StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005160TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005161 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005162 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005163 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005164 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005165
Douglas Gregor43959a92009-08-20 07:17:43 +00005166 // Default statements are always rebuilt
5167 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005168 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005169}
Mike Stump1eb44332009-09-09 15:08:12 +00005170
Douglas Gregor43959a92009-08-20 07:17:43 +00005171template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005172StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005173TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005174 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005175 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005176 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005177
Chris Lattner57ad3782011-02-17 20:34:02 +00005178 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5179 S->getDecl());
5180 if (!LD)
5181 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005182
5183
Douglas Gregor43959a92009-08-20 07:17:43 +00005184 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005185 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005186 cast<LabelDecl>(LD), SourceLocation(),
5187 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005188}
Mike Stump1eb44332009-09-09 15:08:12 +00005189
Douglas Gregor43959a92009-08-20 07:17:43 +00005190template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005191StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005192TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5193 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5194 if (SubStmt.isInvalid())
5195 return StmtError();
5196
5197 // TODO: transform attributes
5198 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5199 return S;
5200
5201 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5202 S->getAttrs(),
5203 SubStmt.get());
5204}
5205
5206template<typename Derived>
5207StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005208TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005209 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005210 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005211 VarDecl *ConditionVar = 0;
5212 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005213 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005214 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005215 getDerived().TransformDefinition(
5216 S->getConditionVariable()->getLocation(),
5217 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005218 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005219 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005220 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005221 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005222
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005223 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005224 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005225
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005226 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005227 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005228 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005229 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005230 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005231 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005232
John McCall9ae2f072010-08-23 23:25:46 +00005233 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005234 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005235 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005236
John McCall9ae2f072010-08-23 23:25:46 +00005237 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5238 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005239 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005240
Douglas Gregor43959a92009-08-20 07:17:43 +00005241 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005242 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005243 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005244 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005245
Douglas Gregor43959a92009-08-20 07:17:43 +00005246 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005247 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005248 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005249 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005250
Douglas Gregor43959a92009-08-20 07:17:43 +00005251 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005252 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005253 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005254 Then.get() == S->getThen() &&
5255 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005256 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005257
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005258 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005259 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005260 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005261}
5262
5263template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005264StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005265TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005266 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005267 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005268 VarDecl *ConditionVar = 0;
5269 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005270 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005271 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005272 getDerived().TransformDefinition(
5273 S->getConditionVariable()->getLocation(),
5274 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005275 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005276 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005277 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005278 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005279
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005280 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005281 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005282 }
Mike Stump1eb44332009-09-09 15:08:12 +00005283
Douglas Gregor43959a92009-08-20 07:17:43 +00005284 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005285 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005286 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005287 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005288 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005289 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005290
Douglas Gregor43959a92009-08-20 07:17:43 +00005291 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005292 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005293 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005294 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005295
Douglas Gregor43959a92009-08-20 07:17:43 +00005296 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005297 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5298 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005299}
Mike Stump1eb44332009-09-09 15:08:12 +00005300
Douglas Gregor43959a92009-08-20 07:17:43 +00005301template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005302StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005303TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005304 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005305 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005306 VarDecl *ConditionVar = 0;
5307 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005308 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005309 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005310 getDerived().TransformDefinition(
5311 S->getConditionVariable()->getLocation(),
5312 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005313 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005314 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005315 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005316 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005317
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005318 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005319 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005320
5321 if (S->getCond()) {
5322 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005323 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005324 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005325 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005326 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005327 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005328 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005329 }
Mike Stump1eb44332009-09-09 15:08:12 +00005330
John McCall9ae2f072010-08-23 23:25:46 +00005331 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5332 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005333 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005334
Douglas Gregor43959a92009-08-20 07:17:43 +00005335 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005336 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005337 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005338 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005339
Douglas Gregor43959a92009-08-20 07:17:43 +00005340 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005341 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005342 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005343 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005344 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005345
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005346 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005347 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005348}
Mike Stump1eb44332009-09-09 15:08:12 +00005349
Douglas Gregor43959a92009-08-20 07:17:43 +00005350template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005351StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005352TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005353 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005354 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005355 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005356 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005357
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005358 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005359 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005360 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005361 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005362
Douglas Gregor43959a92009-08-20 07:17:43 +00005363 if (!getDerived().AlwaysRebuild() &&
5364 Cond.get() == S->getCond() &&
5365 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005366 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005367
John McCall9ae2f072010-08-23 23:25:46 +00005368 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5369 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005370 S->getRParenLoc());
5371}
Mike Stump1eb44332009-09-09 15:08:12 +00005372
Douglas Gregor43959a92009-08-20 07:17:43 +00005373template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005374StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005375TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005376 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005377 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005378 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005379 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005380
Douglas Gregor43959a92009-08-20 07:17:43 +00005381 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005382 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005383 VarDecl *ConditionVar = 0;
5384 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005385 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005386 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005387 getDerived().TransformDefinition(
5388 S->getConditionVariable()->getLocation(),
5389 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005390 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005391 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005392 } else {
5393 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005394
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005395 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005396 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005397
5398 if (S->getCond()) {
5399 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005400 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005401 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005402 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005403 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005404
John McCall9ae2f072010-08-23 23:25:46 +00005405 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005406 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005407 }
Mike Stump1eb44332009-09-09 15:08:12 +00005408
Chad Rosier4a9d7952012-08-08 18:46:20 +00005409 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005410 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005411 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005412
Douglas Gregor43959a92009-08-20 07:17:43 +00005413 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005414 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005415 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005416 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005417
John McCall9ae2f072010-08-23 23:25:46 +00005418 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5419 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005420 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005421
Douglas Gregor43959a92009-08-20 07:17:43 +00005422 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005423 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005424 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005425 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005426
Douglas Gregor43959a92009-08-20 07:17:43 +00005427 if (!getDerived().AlwaysRebuild() &&
5428 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005429 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005430 Inc.get() == S->getInc() &&
5431 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005432 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005433
Douglas Gregor43959a92009-08-20 07:17:43 +00005434 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005435 Init.get(), FullCond, ConditionVar,
5436 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005437}
5438
5439template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005440StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005441TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005442 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5443 S->getLabel());
5444 if (!LD)
5445 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005446
Douglas Gregor43959a92009-08-20 07:17:43 +00005447 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005448 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005449 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005450}
5451
5452template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005453StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005454TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005455 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005456 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005457 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005458 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005459
Douglas Gregor43959a92009-08-20 07:17:43 +00005460 if (!getDerived().AlwaysRebuild() &&
5461 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005462 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005463
5464 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005465 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005466}
5467
5468template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005469StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005470TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005471 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005472}
Mike Stump1eb44332009-09-09 15:08:12 +00005473
Douglas Gregor43959a92009-08-20 07:17:43 +00005474template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005475StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005476TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005477 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005478}
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
Mike Stump1eb44332009-09-09 15:08:12 +00005482TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005483 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005484 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005485 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005486
Mike Stump1eb44332009-09-09 15:08:12 +00005487 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005488 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005489 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005490}
Mike Stump1eb44332009-09-09 15:08:12 +00005491
Douglas Gregor43959a92009-08-20 07:17:43 +00005492template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005493StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005494TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005495 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005496 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005497 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5498 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005499 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5500 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005501 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005502 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005503
Douglas Gregor43959a92009-08-20 07:17:43 +00005504 if (Transformed != *D)
5505 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005506
Douglas Gregor43959a92009-08-20 07:17:43 +00005507 Decls.push_back(Transformed);
5508 }
Mike Stump1eb44332009-09-09 15:08:12 +00005509
Douglas Gregor43959a92009-08-20 07:17:43 +00005510 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005511 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005512
5513 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005514 S->getStartLoc(), S->getEndLoc());
5515}
Mike Stump1eb44332009-09-09 15:08:12 +00005516
Douglas Gregor43959a92009-08-20 07:17:43 +00005517template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005518StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005519TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005520
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005521 SmallVector<Expr*, 8> Constraints;
5522 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005523 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005524
John McCall60d7b3a2010-08-24 06:29:42 +00005525 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005526 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005527
5528 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005529
Anders Carlsson703e3942010-01-24 05:50:09 +00005530 // Go through the outputs.
5531 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005532 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005533
Anders Carlsson703e3942010-01-24 05:50:09 +00005534 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005535 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005536
Anders Carlsson703e3942010-01-24 05:50:09 +00005537 // Transform the output expr.
5538 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005539 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005540 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005541 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005542
Anders Carlsson703e3942010-01-24 05:50:09 +00005543 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005544
John McCall9ae2f072010-08-23 23:25:46 +00005545 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005546 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005547
Anders Carlsson703e3942010-01-24 05:50:09 +00005548 // Go through the inputs.
5549 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005550 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005551
Anders Carlsson703e3942010-01-24 05:50:09 +00005552 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005553 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005554
Anders Carlsson703e3942010-01-24 05:50:09 +00005555 // Transform the input expr.
5556 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005557 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005558 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005559 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005560
Anders Carlsson703e3942010-01-24 05:50:09 +00005561 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005562
John McCall9ae2f072010-08-23 23:25:46 +00005563 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005564 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005565
Anders Carlsson703e3942010-01-24 05:50:09 +00005566 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005567 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005568
5569 // Go through the clobbers.
5570 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005571 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005572
5573 // No need to transform the asm string literal.
5574 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005575 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5576 S->isVolatile(), S->getNumOutputs(),
5577 S->getNumInputs(), Names.data(),
5578 Constraints, Exprs, AsmString.get(),
5579 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005580}
5581
Chad Rosier8cd64b42012-06-11 20:47:18 +00005582template<typename Derived>
5583StmtResult
5584TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005585 ArrayRef<Token> AsmToks =
5586 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005587
Chad Rosier7bd092b2012-08-15 16:53:30 +00005588 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5589 AsmToks, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005590}
Douglas Gregor43959a92009-08-20 07:17:43 +00005591
5592template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005593StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005594TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005595 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005596 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005597 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005598 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005599
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005600 // Transform the @catch statements (if present).
5601 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005602 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005603 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005604 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005605 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005606 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005607 if (Catch.get() != S->getCatchStmt(I))
5608 AnyCatchChanged = true;
5609 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005610 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005611
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005612 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005613 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005614 if (S->getFinallyStmt()) {
5615 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5616 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005617 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005618 }
5619
5620 // If nothing changed, just retain this statement.
5621 if (!getDerived().AlwaysRebuild() &&
5622 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005623 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005624 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005625 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005626
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005627 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005628 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005629 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005630}
Mike Stump1eb44332009-09-09 15:08:12 +00005631
Douglas Gregor43959a92009-08-20 07:17:43 +00005632template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005633StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005634TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005635 // Transform the @catch parameter, if there is one.
5636 VarDecl *Var = 0;
5637 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5638 TypeSourceInfo *TSInfo = 0;
5639 if (FromVar->getTypeSourceInfo()) {
5640 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5641 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005642 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005643 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005644
Douglas Gregorbe270a02010-04-26 17:57:08 +00005645 QualType T;
5646 if (TSInfo)
5647 T = TSInfo->getType();
5648 else {
5649 T = getDerived().TransformType(FromVar->getType());
5650 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005651 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005652 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005653
Douglas Gregorbe270a02010-04-26 17:57:08 +00005654 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5655 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005656 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005657 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005658
John McCall60d7b3a2010-08-24 06:29:42 +00005659 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005660 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005661 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005662
5663 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005664 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005665 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005666}
Mike Stump1eb44332009-09-09 15:08:12 +00005667
Douglas Gregor43959a92009-08-20 07:17:43 +00005668template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005669StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005670TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005671 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005672 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005673 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005674 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005675
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005676 // If nothing changed, just retain this statement.
5677 if (!getDerived().AlwaysRebuild() &&
5678 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005679 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005680
5681 // Build a new statement.
5682 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005683 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005684}
Mike Stump1eb44332009-09-09 15:08:12 +00005685
Douglas Gregor43959a92009-08-20 07:17:43 +00005686template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005687StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005688TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005689 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005690 if (S->getThrowExpr()) {
5691 Operand = getDerived().TransformExpr(S->getThrowExpr());
5692 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005693 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005694 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005695
Douglas Gregord1377b22010-04-22 21:44:01 +00005696 if (!getDerived().AlwaysRebuild() &&
5697 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005698 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005699
John McCall9ae2f072010-08-23 23:25:46 +00005700 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005701}
Mike Stump1eb44332009-09-09 15:08:12 +00005702
Douglas Gregor43959a92009-08-20 07:17:43 +00005703template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005704StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005705TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005706 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005707 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005708 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005709 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005710 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005711 Object =
5712 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5713 Object.get());
5714 if (Object.isInvalid())
5715 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005716
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005717 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005718 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005719 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005720 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005721
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005722 // If nothing change, just retain the current statement.
5723 if (!getDerived().AlwaysRebuild() &&
5724 Object.get() == S->getSynchExpr() &&
5725 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005726 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005727
5728 // Build a new statement.
5729 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005730 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005731}
5732
5733template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005734StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005735TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5736 ObjCAutoreleasePoolStmt *S) {
5737 // Transform the body.
5738 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5739 if (Body.isInvalid())
5740 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005741
John McCallf85e1932011-06-15 23:02:42 +00005742 // If nothing changed, just retain this statement.
5743 if (!getDerived().AlwaysRebuild() &&
5744 Body.get() == S->getSubStmt())
5745 return SemaRef.Owned(S);
5746
5747 // Build a new statement.
5748 return getDerived().RebuildObjCAutoreleasePoolStmt(
5749 S->getAtLoc(), Body.get());
5750}
5751
5752template<typename Derived>
5753StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005754TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005755 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005756 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005757 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005758 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005759 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005760
Douglas Gregorc3203e72010-04-22 23:10:45 +00005761 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005762 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005763 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005764 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005765
Douglas Gregorc3203e72010-04-22 23:10:45 +00005766 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005767 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005768 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005769 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005770
Douglas Gregorc3203e72010-04-22 23:10:45 +00005771 // If nothing changed, just retain this statement.
5772 if (!getDerived().AlwaysRebuild() &&
5773 Element.get() == S->getElement() &&
5774 Collection.get() == S->getCollection() &&
5775 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005776 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005777
Douglas Gregorc3203e72010-04-22 23:10:45 +00005778 // Build a new statement.
5779 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005780 Element.get(),
5781 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005782 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005783 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005784}
5785
5786
5787template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005788StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005789TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5790 // Transform the exception declaration, if any.
5791 VarDecl *Var = 0;
5792 if (S->getExceptionDecl()) {
5793 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005794 TypeSourceInfo *T = getDerived().TransformType(
5795 ExceptionDecl->getTypeSourceInfo());
5796 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005797 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005798
Douglas Gregor83cb9422010-09-09 17:09:21 +00005799 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005800 ExceptionDecl->getInnerLocStart(),
5801 ExceptionDecl->getLocation(),
5802 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005803 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005804 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005805 }
Mike Stump1eb44332009-09-09 15:08:12 +00005806
Douglas Gregor43959a92009-08-20 07:17:43 +00005807 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005808 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005809 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005810 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005811
Douglas Gregor43959a92009-08-20 07:17:43 +00005812 if (!getDerived().AlwaysRebuild() &&
5813 !Var &&
5814 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005815 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005816
5817 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5818 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005819 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005820}
Mike Stump1eb44332009-09-09 15:08:12 +00005821
Douglas Gregor43959a92009-08-20 07:17:43 +00005822template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005823StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005824TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5825 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005826 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005827 = getDerived().TransformCompoundStmt(S->getTryBlock());
5828 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005829 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005830
Douglas Gregor43959a92009-08-20 07:17:43 +00005831 // Transform the handlers.
5832 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005833 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005834 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005835 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005836 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5837 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005838 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005839
Douglas Gregor43959a92009-08-20 07:17:43 +00005840 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5841 Handlers.push_back(Handler.takeAs<Stmt>());
5842 }
Mike Stump1eb44332009-09-09 15:08:12 +00005843
Douglas Gregor43959a92009-08-20 07:17:43 +00005844 if (!getDerived().AlwaysRebuild() &&
5845 TryBlock.get() == S->getTryBlock() &&
5846 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005847 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005848
John McCall9ae2f072010-08-23 23:25:46 +00005849 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005850 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005851}
Mike Stump1eb44332009-09-09 15:08:12 +00005852
Richard Smithad762fc2011-04-14 22:09:26 +00005853template<typename Derived>
5854StmtResult
5855TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5856 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5857 if (Range.isInvalid())
5858 return StmtError();
5859
5860 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5861 if (BeginEnd.isInvalid())
5862 return StmtError();
5863
5864 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5865 if (Cond.isInvalid())
5866 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005867 if (Cond.get())
5868 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5869 if (Cond.isInvalid())
5870 return StmtError();
5871 if (Cond.get())
5872 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005873
5874 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5875 if (Inc.isInvalid())
5876 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005877 if (Inc.get())
5878 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005879
5880 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5881 if (LoopVar.isInvalid())
5882 return StmtError();
5883
5884 StmtResult NewStmt = S;
5885 if (getDerived().AlwaysRebuild() ||
5886 Range.get() != S->getRangeStmt() ||
5887 BeginEnd.get() != S->getBeginEndStmt() ||
5888 Cond.get() != S->getCond() ||
5889 Inc.get() != S->getInc() ||
5890 LoopVar.get() != S->getLoopVarStmt())
5891 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5892 S->getColonLoc(), Range.get(),
5893 BeginEnd.get(), Cond.get(),
5894 Inc.get(), LoopVar.get(),
5895 S->getRParenLoc());
5896
5897 StmtResult Body = getDerived().TransformStmt(S->getBody());
5898 if (Body.isInvalid())
5899 return StmtError();
5900
5901 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5902 // it now so we have a new statement to attach the body to.
5903 if (Body.get() != S->getBody() && NewStmt.get() == S)
5904 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5905 S->getColonLoc(), Range.get(),
5906 BeginEnd.get(), Cond.get(),
5907 Inc.get(), LoopVar.get(),
5908 S->getRParenLoc());
5909
5910 if (NewStmt.get() == S)
5911 return SemaRef.Owned(S);
5912
5913 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5914}
5915
John Wiegley28bbe4b2011-04-28 01:08:34 +00005916template<typename Derived>
5917StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005918TreeTransform<Derived>::TransformMSDependentExistsStmt(
5919 MSDependentExistsStmt *S) {
5920 // Transform the nested-name-specifier, if any.
5921 NestedNameSpecifierLoc QualifierLoc;
5922 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005923 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005924 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5925 if (!QualifierLoc)
5926 return StmtError();
5927 }
5928
5929 // Transform the declaration name.
5930 DeclarationNameInfo NameInfo = S->getNameInfo();
5931 if (NameInfo.getName()) {
5932 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5933 if (!NameInfo.getName())
5934 return StmtError();
5935 }
5936
5937 // Check whether anything changed.
5938 if (!getDerived().AlwaysRebuild() &&
5939 QualifierLoc == S->getQualifierLoc() &&
5940 NameInfo.getName() == S->getNameInfo().getName())
5941 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005942
Douglas Gregorba0513d2011-10-25 01:33:02 +00005943 // Determine whether this name exists, if we can.
5944 CXXScopeSpec SS;
5945 SS.Adopt(QualifierLoc);
5946 bool Dependent = false;
5947 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5948 case Sema::IER_Exists:
5949 if (S->isIfExists())
5950 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005951
Douglas Gregorba0513d2011-10-25 01:33:02 +00005952 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5953
5954 case Sema::IER_DoesNotExist:
5955 if (S->isIfNotExists())
5956 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005957
Douglas Gregorba0513d2011-10-25 01:33:02 +00005958 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005959
Douglas Gregorba0513d2011-10-25 01:33:02 +00005960 case Sema::IER_Dependent:
5961 Dependent = true;
5962 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005963
Douglas Gregor65019ac2011-10-25 03:44:56 +00005964 case Sema::IER_Error:
5965 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005966 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005967
Douglas Gregorba0513d2011-10-25 01:33:02 +00005968 // We need to continue with the instantiation, so do so now.
5969 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5970 if (SubStmt.isInvalid())
5971 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005972
Douglas Gregorba0513d2011-10-25 01:33:02 +00005973 // If we have resolved the name, just transform to the substatement.
5974 if (!Dependent)
5975 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005976
Douglas Gregorba0513d2011-10-25 01:33:02 +00005977 // The name is still dependent, so build a dependent expression again.
5978 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5979 S->isIfExists(),
5980 QualifierLoc,
5981 NameInfo,
5982 SubStmt.get());
5983}
5984
5985template<typename Derived>
5986StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00005987TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5988 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5989 if(TryBlock.isInvalid()) return StmtError();
5990
5991 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5992 if(!getDerived().AlwaysRebuild() &&
5993 TryBlock.get() == S->getTryBlock() &&
5994 Handler.get() == S->getHandler())
5995 return SemaRef.Owned(S);
5996
5997 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5998 S->getTryLoc(),
5999 TryBlock.take(),
6000 Handler.take());
6001}
6002
6003template<typename Derived>
6004StmtResult
6005TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6006 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6007 if(Block.isInvalid()) return StmtError();
6008
6009 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6010 Block.take());
6011}
6012
6013template<typename Derived>
6014StmtResult
6015TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6016 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6017 if(FilterExpr.isInvalid()) return StmtError();
6018
6019 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6020 if(Block.isInvalid()) return StmtError();
6021
6022 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6023 FilterExpr.take(),
6024 Block.take());
6025}
6026
6027template<typename Derived>
6028StmtResult
6029TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6030 if(isa<SEHFinallyStmt>(Handler))
6031 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6032 else
6033 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6034}
6035
Douglas Gregor43959a92009-08-20 07:17:43 +00006036//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006037// Expression transformation
6038//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006039template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006040ExprResult
John McCall454feb92009-12-08 09:21:05 +00006041TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006042 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006043}
Mike Stump1eb44332009-09-09 15:08:12 +00006044
6045template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006046ExprResult
John McCall454feb92009-12-08 09:21:05 +00006047TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006048 NestedNameSpecifierLoc QualifierLoc;
6049 if (E->getQualifierLoc()) {
6050 QualifierLoc
6051 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6052 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006053 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006054 }
John McCalldbd872f2009-12-08 09:08:17 +00006055
6056 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006057 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6058 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006059 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006060 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006061
John McCallec8045d2010-08-17 21:27:17 +00006062 DeclarationNameInfo NameInfo = E->getNameInfo();
6063 if (NameInfo.getName()) {
6064 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6065 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006066 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006067 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006068
6069 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006070 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006071 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006072 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006073 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006074
6075 // Mark it referenced in the new context regardless.
6076 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006077 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006078
John McCall3fa5cae2010-10-26 07:05:15 +00006079 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006080 }
John McCalldbd872f2009-12-08 09:08:17 +00006081
6082 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006083 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006084 TemplateArgs = &TransArgs;
6085 TransArgs.setLAngleLoc(E->getLAngleLoc());
6086 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006087 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6088 E->getNumTemplateArgs(),
6089 TransArgs))
6090 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006091 }
6092
Chad Rosier4a9d7952012-08-08 18:46:20 +00006093 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006094 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006095}
Mike Stump1eb44332009-09-09 15:08:12 +00006096
Douglas Gregorb98b1992009-08-11 05:31:07 +00006097template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006098ExprResult
John McCall454feb92009-12-08 09:21:05 +00006099TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006100 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006101}
Mike Stump1eb44332009-09-09 15:08:12 +00006102
Douglas Gregorb98b1992009-08-11 05:31:07 +00006103template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006104ExprResult
John McCall454feb92009-12-08 09:21:05 +00006105TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006106 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006107}
Mike Stump1eb44332009-09-09 15:08:12 +00006108
Douglas Gregorb98b1992009-08-11 05:31:07 +00006109template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006110ExprResult
John McCall454feb92009-12-08 09:21:05 +00006111TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006112 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006113}
Mike Stump1eb44332009-09-09 15:08:12 +00006114
Douglas Gregorb98b1992009-08-11 05:31:07 +00006115template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006116ExprResult
John McCall454feb92009-12-08 09:21:05 +00006117TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006118 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006119}
Mike Stump1eb44332009-09-09 15:08:12 +00006120
Douglas Gregorb98b1992009-08-11 05:31:07 +00006121template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006122ExprResult
John McCall454feb92009-12-08 09:21:05 +00006123TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006124 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006125}
6126
6127template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006128ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006129TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6130 return SemaRef.MaybeBindToTemporary(E);
6131}
6132
6133template<typename Derived>
6134ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006135TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6136 ExprResult ControllingExpr =
6137 getDerived().TransformExpr(E->getControllingExpr());
6138 if (ControllingExpr.isInvalid())
6139 return ExprError();
6140
Chris Lattner686775d2011-07-20 06:58:45 +00006141 SmallVector<Expr *, 4> AssocExprs;
6142 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006143 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6144 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6145 if (TS) {
6146 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6147 if (!AssocType)
6148 return ExprError();
6149 AssocTypes.push_back(AssocType);
6150 } else {
6151 AssocTypes.push_back(0);
6152 }
6153
6154 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6155 if (AssocExpr.isInvalid())
6156 return ExprError();
6157 AssocExprs.push_back(AssocExpr.release());
6158 }
6159
6160 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6161 E->getDefaultLoc(),
6162 E->getRParenLoc(),
6163 ControllingExpr.release(),
6164 AssocTypes.data(),
6165 AssocExprs.data(),
6166 E->getNumAssocs());
6167}
6168
6169template<typename Derived>
6170ExprResult
John McCall454feb92009-12-08 09:21:05 +00006171TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006172 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006173 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006174 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006175
Douglas Gregorb98b1992009-08-11 05:31:07 +00006176 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006177 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006178
John McCall9ae2f072010-08-23 23:25:46 +00006179 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006180 E->getRParen());
6181}
6182
Mike Stump1eb44332009-09-09 15:08:12 +00006183template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006184ExprResult
John McCall454feb92009-12-08 09:21:05 +00006185TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006186 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006187 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006188 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006189
Douglas Gregorb98b1992009-08-11 05:31:07 +00006190 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006191 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006192
Douglas Gregorb98b1992009-08-11 05:31:07 +00006193 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6194 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006195 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006196}
Mike Stump1eb44332009-09-09 15:08:12 +00006197
Douglas Gregorb98b1992009-08-11 05:31:07 +00006198template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006199ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006200TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6201 // Transform the type.
6202 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6203 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006204 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006205
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006206 // Transform all of the components into components similar to what the
6207 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006208 // FIXME: It would be slightly more efficient in the non-dependent case to
6209 // just map FieldDecls, rather than requiring the rebuilder to look for
6210 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006211 // template code that we don't care.
6212 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006213 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006214 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006215 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006216 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6217 const Node &ON = E->getComponent(I);
6218 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006219 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006220 Comp.LocStart = ON.getSourceRange().getBegin();
6221 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006222 switch (ON.getKind()) {
6223 case Node::Array: {
6224 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006225 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006226 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006227 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006228
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006229 ExprChanged = ExprChanged || Index.get() != FromIndex;
6230 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006231 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006232 break;
6233 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006234
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006235 case Node::Field:
6236 case Node::Identifier:
6237 Comp.isBrackets = false;
6238 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006239 if (!Comp.U.IdentInfo)
6240 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006241
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006242 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006243
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006244 case Node::Base:
6245 // Will be recomputed during the rebuild.
6246 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006247 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006248
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006249 Components.push_back(Comp);
6250 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006251
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006252 // If nothing changed, retain the existing expression.
6253 if (!getDerived().AlwaysRebuild() &&
6254 Type == E->getTypeSourceInfo() &&
6255 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006256 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006257
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006258 // Build a new offsetof expression.
6259 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6260 Components.data(), Components.size(),
6261 E->getRParenLoc());
6262}
6263
6264template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006265ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006266TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6267 assert(getDerived().AlreadyTransformed(E->getType()) &&
6268 "opaque value expression requires transformation");
6269 return SemaRef.Owned(E);
6270}
6271
6272template<typename Derived>
6273ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006274TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006275 // Rebuild the syntactic form. The original syntactic form has
6276 // opaque-value expressions in it, so strip those away and rebuild
6277 // the result. This is a really awful way of doing this, but the
6278 // better solution (rebuilding the semantic expressions and
6279 // rebinding OVEs as necessary) doesn't work; we'd need
6280 // TreeTransform to not strip away implicit conversions.
6281 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6282 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006283 if (result.isInvalid()) return ExprError();
6284
6285 // If that gives us a pseudo-object result back, the pseudo-object
6286 // expression must have been an lvalue-to-rvalue conversion which we
6287 // should reapply.
6288 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6289 result = SemaRef.checkPseudoObjectRValue(result.take());
6290
6291 return result;
6292}
6293
6294template<typename Derived>
6295ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006296TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6297 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006298 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006299 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006300
John McCalla93c9342009-12-07 02:54:59 +00006301 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006302 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006303 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006304
John McCall5ab75172009-11-04 07:28:41 +00006305 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006306 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006307
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006308 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6309 E->getKind(),
6310 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006311 }
Mike Stump1eb44332009-09-09 15:08:12 +00006312
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006313 // C++0x [expr.sizeof]p1:
6314 // The operand is either an expression, which is an unevaluated operand
6315 // [...]
6316 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006317
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006318 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6319 if (SubExpr.isInvalid())
6320 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006321
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006322 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6323 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006324
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006325 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6326 E->getOperatorLoc(),
6327 E->getKind(),
6328 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006329}
Mike Stump1eb44332009-09-09 15:08:12 +00006330
Douglas Gregorb98b1992009-08-11 05:31:07 +00006331template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006332ExprResult
John McCall454feb92009-12-08 09:21:05 +00006333TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006334 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006335 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006336 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006337
John McCall60d7b3a2010-08-24 06:29:42 +00006338 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006339 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006340 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006341
6342
Douglas Gregorb98b1992009-08-11 05:31:07 +00006343 if (!getDerived().AlwaysRebuild() &&
6344 LHS.get() == E->getLHS() &&
6345 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006346 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006347
John McCall9ae2f072010-08-23 23:25:46 +00006348 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006349 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006350 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006351 E->getRBracketLoc());
6352}
Mike Stump1eb44332009-09-09 15:08:12 +00006353
6354template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006355ExprResult
John McCall454feb92009-12-08 09:21:05 +00006356TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006357 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006358 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006359 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006360 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006361
6362 // Transform arguments.
6363 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006364 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006365 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006366 &ArgChanged))
6367 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006368
Douglas Gregorb98b1992009-08-11 05:31:07 +00006369 if (!getDerived().AlwaysRebuild() &&
6370 Callee.get() == E->getCallee() &&
6371 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006372 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006373
Douglas Gregorb98b1992009-08-11 05:31:07 +00006374 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006375 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006376 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006377 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006378 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006379 E->getRParenLoc());
6380}
Mike Stump1eb44332009-09-09 15:08:12 +00006381
6382template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006383ExprResult
John McCall454feb92009-12-08 09:21:05 +00006384TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006385 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006386 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006387 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006388
Douglas Gregor40d96a62011-02-28 21:54:11 +00006389 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006390 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006391 QualifierLoc
6392 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006393
Douglas Gregor40d96a62011-02-28 21:54:11 +00006394 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006395 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006396 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006397 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006398
Eli Friedmanf595cc42009-12-04 06:40:45 +00006399 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006400 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6401 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006402 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006403 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006404
John McCall6bb80172010-03-30 21:47:33 +00006405 NamedDecl *FoundDecl = E->getFoundDecl();
6406 if (FoundDecl == E->getMemberDecl()) {
6407 FoundDecl = Member;
6408 } else {
6409 FoundDecl = cast_or_null<NamedDecl>(
6410 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6411 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006412 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006413 }
6414
Douglas Gregorb98b1992009-08-11 05:31:07 +00006415 if (!getDerived().AlwaysRebuild() &&
6416 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006417 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006418 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006419 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006420 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006421
Anders Carlsson1f240322009-12-22 05:24:09 +00006422 // Mark it referenced in the new context regardless.
6423 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006424 SemaRef.MarkMemberReferenced(E);
6425
John McCall3fa5cae2010-10-26 07:05:15 +00006426 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006427 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006428
John McCalld5532b62009-11-23 01:53:49 +00006429 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006430 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006431 TransArgs.setLAngleLoc(E->getLAngleLoc());
6432 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006433 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6434 E->getNumTemplateArgs(),
6435 TransArgs))
6436 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006437 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006438
Douglas Gregorb98b1992009-08-11 05:31:07 +00006439 // FIXME: Bogus source location for the operator
6440 SourceLocation FakeOperatorLoc
6441 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6442
John McCallc2233c52010-01-15 08:34:02 +00006443 // FIXME: to do this check properly, we will need to preserve the
6444 // first-qualifier-in-scope here, just in case we had a dependent
6445 // base (and therefore couldn't do the check) and a
6446 // nested-name-qualifier (and therefore could do the lookup).
6447 NamedDecl *FirstQualifierInScope = 0;
6448
John McCall9ae2f072010-08-23 23:25:46 +00006449 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006450 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006451 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006452 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006453 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006454 Member,
John McCall6bb80172010-03-30 21:47:33 +00006455 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006456 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006457 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006458 FirstQualifierInScope);
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 McCall60d7b3a2010-08-24 06:29:42 +00006462ExprResult
John McCall454feb92009-12-08 09:21:05 +00006463TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006464 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006465 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006466 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006467
John McCall60d7b3a2010-08-24 06:29:42 +00006468 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006469 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006470 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006471
Douglas Gregorb98b1992009-08-11 05:31:07 +00006472 if (!getDerived().AlwaysRebuild() &&
6473 LHS.get() == E->getLHS() &&
6474 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006475 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006476
Douglas Gregorb98b1992009-08-11 05:31:07 +00006477 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006478 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006479}
6480
Mike Stump1eb44332009-09-09 15:08:12 +00006481template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006482ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006483TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006484 CompoundAssignOperator *E) {
6485 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006486}
Mike Stump1eb44332009-09-09 15:08:12 +00006487
Douglas Gregorb98b1992009-08-11 05:31:07 +00006488template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006489ExprResult TreeTransform<Derived>::
6490TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6491 // Just rebuild the common and RHS expressions and see whether we
6492 // get any changes.
6493
6494 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6495 if (commonExpr.isInvalid())
6496 return ExprError();
6497
6498 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6499 if (rhs.isInvalid())
6500 return ExprError();
6501
6502 if (!getDerived().AlwaysRebuild() &&
6503 commonExpr.get() == e->getCommon() &&
6504 rhs.get() == e->getFalseExpr())
6505 return SemaRef.Owned(e);
6506
6507 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6508 e->getQuestionLoc(),
6509 0,
6510 e->getColonLoc(),
6511 rhs.get());
6512}
6513
6514template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006515ExprResult
John McCall454feb92009-12-08 09:21:05 +00006516TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006517 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006518 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006519 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006520
John McCall60d7b3a2010-08-24 06:29:42 +00006521 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006522 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006523 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006524
John McCall60d7b3a2010-08-24 06:29:42 +00006525 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006526 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006527 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006528
Douglas Gregorb98b1992009-08-11 05:31:07 +00006529 if (!getDerived().AlwaysRebuild() &&
6530 Cond.get() == E->getCond() &&
6531 LHS.get() == E->getLHS() &&
6532 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006533 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006534
John McCall9ae2f072010-08-23 23:25:46 +00006535 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006536 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006537 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006538 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006539 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006540}
Mike Stump1eb44332009-09-09 15:08:12 +00006541
6542template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006543ExprResult
John McCall454feb92009-12-08 09:21:05 +00006544TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006545 // Implicit casts are eliminated during transformation, since they
6546 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006547 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006548}
Mike Stump1eb44332009-09-09 15:08:12 +00006549
Douglas Gregorb98b1992009-08-11 05:31:07 +00006550template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006551ExprResult
John McCall454feb92009-12-08 09:21:05 +00006552TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006553 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6554 if (!Type)
6555 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006556
John McCall60d7b3a2010-08-24 06:29:42 +00006557 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006558 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006559 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006560 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006561
Douglas Gregorb98b1992009-08-11 05:31:07 +00006562 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006563 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006564 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006565 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006566
John McCall9d125032010-01-15 18:39:57 +00006567 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006568 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006569 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006570 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006571}
Mike Stump1eb44332009-09-09 15:08:12 +00006572
Douglas Gregorb98b1992009-08-11 05:31:07 +00006573template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006574ExprResult
John McCall454feb92009-12-08 09:21:05 +00006575TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006576 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6577 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6578 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006579 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006580
John McCall60d7b3a2010-08-24 06:29:42 +00006581 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006582 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006583 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006584
Douglas Gregorb98b1992009-08-11 05:31:07 +00006585 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006586 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006587 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006588 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006589
John McCall1d7d8d62010-01-19 22:33:45 +00006590 // Note: the expression type doesn't necessarily match the
6591 // type-as-written, but that's okay, because it should always be
6592 // derivable from the initializer.
6593
John McCall42f56b52010-01-18 19:35:47 +00006594 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006595 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006596 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006597}
Mike Stump1eb44332009-09-09 15:08:12 +00006598
Douglas Gregorb98b1992009-08-11 05:31:07 +00006599template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006600ExprResult
John McCall454feb92009-12-08 09:21:05 +00006601TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006602 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006603 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006604 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006605
Douglas Gregorb98b1992009-08-11 05:31:07 +00006606 if (!getDerived().AlwaysRebuild() &&
6607 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006608 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006609
Douglas Gregorb98b1992009-08-11 05:31:07 +00006610 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006611 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006612 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006613 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006614 E->getAccessorLoc(),
6615 E->getAccessor());
6616}
Mike Stump1eb44332009-09-09 15:08:12 +00006617
Douglas Gregorb98b1992009-08-11 05:31:07 +00006618template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006619ExprResult
John McCall454feb92009-12-08 09:21:05 +00006620TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006622
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006623 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006624 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006625 Inits, &InitChanged))
6626 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006627
Douglas Gregorb98b1992009-08-11 05:31:07 +00006628 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006629 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006630
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006631 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006632 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633}
Mike Stump1eb44332009-09-09 15:08:12 +00006634
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006636ExprResult
John McCall454feb92009-12-08 09:21:05 +00006637TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006638 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006639
Douglas Gregor43959a92009-08-20 07:17:43 +00006640 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006641 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006642 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006643 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006644
Douglas Gregor43959a92009-08-20 07:17:43 +00006645 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006646 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006647 bool ExprChanged = false;
6648 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6649 DEnd = E->designators_end();
6650 D != DEnd; ++D) {
6651 if (D->isFieldDesignator()) {
6652 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6653 D->getDotLoc(),
6654 D->getFieldLoc()));
6655 continue;
6656 }
Mike Stump1eb44332009-09-09 15:08:12 +00006657
Douglas Gregorb98b1992009-08-11 05:31:07 +00006658 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006659 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006660 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006661 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006662
6663 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006664 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006665
Douglas Gregorb98b1992009-08-11 05:31:07 +00006666 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6667 ArrayExprs.push_back(Index.release());
6668 continue;
6669 }
Mike Stump1eb44332009-09-09 15:08:12 +00006670
Douglas Gregorb98b1992009-08-11 05:31:07 +00006671 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006672 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006673 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6674 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006675 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006676
John McCall60d7b3a2010-08-24 06:29:42 +00006677 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006679 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006680
6681 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006682 End.get(),
6683 D->getLBracketLoc(),
6684 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006685
Douglas Gregorb98b1992009-08-11 05:31:07 +00006686 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6687 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006688
Douglas Gregorb98b1992009-08-11 05:31:07 +00006689 ArrayExprs.push_back(Start.release());
6690 ArrayExprs.push_back(End.release());
6691 }
Mike Stump1eb44332009-09-09 15:08:12 +00006692
Douglas Gregorb98b1992009-08-11 05:31:07 +00006693 if (!getDerived().AlwaysRebuild() &&
6694 Init.get() == E->getInit() &&
6695 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006696 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006697
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006698 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006699 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006700 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006701}
Mike Stump1eb44332009-09-09 15:08:12 +00006702
Douglas Gregorb98b1992009-08-11 05:31:07 +00006703template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006704ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006705TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006706 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006707 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006708
Douglas Gregor5557b252009-10-28 00:29:27 +00006709 // FIXME: Will we ever have proper type location here? Will we actually
6710 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006711 QualType T = getDerived().TransformType(E->getType());
6712 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006713 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006714
Douglas Gregorb98b1992009-08-11 05:31:07 +00006715 if (!getDerived().AlwaysRebuild() &&
6716 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006717 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006718
Douglas Gregorb98b1992009-08-11 05:31:07 +00006719 return getDerived().RebuildImplicitValueInitExpr(T);
6720}
Mike Stump1eb44332009-09-09 15:08:12 +00006721
Douglas Gregorb98b1992009-08-11 05:31:07 +00006722template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006723ExprResult
John McCall454feb92009-12-08 09:21:05 +00006724TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006725 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6726 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006727 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006728
John McCall60d7b3a2010-08-24 06:29:42 +00006729 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006730 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006731 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006732
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006734 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006735 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006736 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006737
John McCall9ae2f072010-08-23 23:25:46 +00006738 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006739 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006740}
6741
6742template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006743ExprResult
John McCall454feb92009-12-08 09:21:05 +00006744TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006745 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006746 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006747 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6748 &ArgumentChanged))
6749 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006750
Douglas Gregorb98b1992009-08-11 05:31:07 +00006751 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006752 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006753 E->getRParenLoc());
6754}
Mike Stump1eb44332009-09-09 15:08:12 +00006755
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756/// \brief Transform an address-of-label expression.
6757///
6758/// By default, the transformation of an address-of-label expression always
6759/// rebuilds the expression, so that the label identifier can be resolved to
6760/// the corresponding label statement by semantic analysis.
6761template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006762ExprResult
John McCall454feb92009-12-08 09:21:05 +00006763TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006764 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6765 E->getLabel());
6766 if (!LD)
6767 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006768
Douglas Gregorb98b1992009-08-11 05:31:07 +00006769 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006770 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006771}
Mike Stump1eb44332009-09-09 15:08:12 +00006772
6773template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006774ExprResult
John McCall454feb92009-12-08 09:21:05 +00006775TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006776 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006777 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006778 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006779 if (SubStmt.isInvalid()) {
6780 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006781 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006782 }
Mike Stump1eb44332009-09-09 15:08:12 +00006783
Douglas Gregorb98b1992009-08-11 05:31:07 +00006784 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006785 SubStmt.get() == E->getSubStmt()) {
6786 // Calling this an 'error' is unintuitive, but it does the right thing.
6787 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006788 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006789 }
Mike Stump1eb44332009-09-09 15:08:12 +00006790
6791 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006792 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006793 E->getRParenLoc());
6794}
Mike Stump1eb44332009-09-09 15:08:12 +00006795
Douglas Gregorb98b1992009-08-11 05:31:07 +00006796template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006797ExprResult
John McCall454feb92009-12-08 09:21:05 +00006798TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006799 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006800 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006801 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006802
John McCall60d7b3a2010-08-24 06:29:42 +00006803 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006804 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006805 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006806
John McCall60d7b3a2010-08-24 06:29:42 +00006807 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006808 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006809 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006810
Douglas Gregorb98b1992009-08-11 05:31:07 +00006811 if (!getDerived().AlwaysRebuild() &&
6812 Cond.get() == E->getCond() &&
6813 LHS.get() == E->getLHS() &&
6814 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006815 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006816
Douglas Gregorb98b1992009-08-11 05:31:07 +00006817 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006818 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006819 E->getRParenLoc());
6820}
Mike Stump1eb44332009-09-09 15:08:12 +00006821
Douglas Gregorb98b1992009-08-11 05:31:07 +00006822template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006823ExprResult
John McCall454feb92009-12-08 09:21:05 +00006824TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006825 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006826}
6827
6828template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006829ExprResult
John McCall454feb92009-12-08 09:21:05 +00006830TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006831 switch (E->getOperator()) {
6832 case OO_New:
6833 case OO_Delete:
6834 case OO_Array_New:
6835 case OO_Array_Delete:
6836 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006837
Douglas Gregor668d6d92009-12-13 20:44:55 +00006838 case OO_Call: {
6839 // This is a call to an object's operator().
6840 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6841
6842 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006843 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006844 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006845 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006846
6847 // FIXME: Poor location information
6848 SourceLocation FakeLParenLoc
6849 = SemaRef.PP.getLocForEndOfToken(
6850 static_cast<Expr *>(Object.get())->getLocEnd());
6851
6852 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006853 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006854 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006855 Args))
6856 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006857
John McCall9ae2f072010-08-23 23:25:46 +00006858 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006859 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006860 E->getLocEnd());
6861 }
6862
6863#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6864 case OO_##Name:
6865#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6866#include "clang/Basic/OperatorKinds.def"
6867 case OO_Subscript:
6868 // Handled below.
6869 break;
6870
6871 case OO_Conditional:
6872 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006873
6874 case OO_None:
6875 case NUM_OVERLOADED_OPERATORS:
6876 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006877 }
6878
John McCall60d7b3a2010-08-24 06:29:42 +00006879 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006880 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006881 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006882
John McCall60d7b3a2010-08-24 06:29:42 +00006883 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006884 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006885 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006886
John McCall60d7b3a2010-08-24 06:29:42 +00006887 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006888 if (E->getNumArgs() == 2) {
6889 Second = getDerived().TransformExpr(E->getArg(1));
6890 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006891 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006892 }
Mike Stump1eb44332009-09-09 15:08:12 +00006893
Douglas Gregorb98b1992009-08-11 05:31:07 +00006894 if (!getDerived().AlwaysRebuild() &&
6895 Callee.get() == E->getCallee() &&
6896 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006897 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006898 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006899
Douglas Gregorb98b1992009-08-11 05:31:07 +00006900 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6901 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006902 Callee.get(),
6903 First.get(),
6904 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006905}
Mike Stump1eb44332009-09-09 15:08:12 +00006906
Douglas Gregorb98b1992009-08-11 05:31:07 +00006907template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006908ExprResult
John McCall454feb92009-12-08 09:21:05 +00006909TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6910 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006911}
Mike Stump1eb44332009-09-09 15:08:12 +00006912
Douglas Gregorb98b1992009-08-11 05:31:07 +00006913template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006914ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006915TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6916 // Transform the callee.
6917 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6918 if (Callee.isInvalid())
6919 return ExprError();
6920
6921 // Transform exec config.
6922 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6923 if (EC.isInvalid())
6924 return ExprError();
6925
6926 // Transform arguments.
6927 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006928 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006929 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006930 &ArgChanged))
6931 return ExprError();
6932
6933 if (!getDerived().AlwaysRebuild() &&
6934 Callee.get() == E->getCallee() &&
6935 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006936 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006937
6938 // FIXME: Wrong source location information for the '('.
6939 SourceLocation FakeLParenLoc
6940 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6941 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006942 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006943 E->getRParenLoc(), EC.get());
6944}
6945
6946template<typename Derived>
6947ExprResult
John McCall454feb92009-12-08 09:21:05 +00006948TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006949 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6950 if (!Type)
6951 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006952
John McCall60d7b3a2010-08-24 06:29:42 +00006953 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006954 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006955 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006956 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006957
Douglas Gregorb98b1992009-08-11 05:31:07 +00006958 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006959 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006960 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006961 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006962
Douglas Gregorb98b1992009-08-11 05:31:07 +00006963 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006964 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006965 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6966 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6967 SourceLocation FakeRParenLoc
6968 = SemaRef.PP.getLocForEndOfToken(
6969 E->getSubExpr()->getSourceRange().getEnd());
6970 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006971 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006972 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006973 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006974 FakeRAngleLoc,
6975 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006976 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006977 FakeRParenLoc);
6978}
Mike Stump1eb44332009-09-09 15:08:12 +00006979
Douglas Gregorb98b1992009-08-11 05:31:07 +00006980template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006981ExprResult
John McCall454feb92009-12-08 09:21:05 +00006982TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6983 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006984}
Mike Stump1eb44332009-09-09 15:08:12 +00006985
6986template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006987ExprResult
John McCall454feb92009-12-08 09:21:05 +00006988TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6989 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006990}
6991
Douglas Gregorb98b1992009-08-11 05:31:07 +00006992template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006993ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006994TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006995 CXXReinterpretCastExpr *E) {
6996 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006997}
Mike Stump1eb44332009-09-09 15:08:12 +00006998
Douglas Gregorb98b1992009-08-11 05:31:07 +00006999template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007000ExprResult
John McCall454feb92009-12-08 09:21:05 +00007001TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7002 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007003}
Mike Stump1eb44332009-09-09 15:08:12 +00007004
Douglas Gregorb98b1992009-08-11 05:31:07 +00007005template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007006ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007007TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007008 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007009 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7010 if (!Type)
7011 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007012
John McCall60d7b3a2010-08-24 06:29:42 +00007013 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007014 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007015 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007016 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007017
Douglas Gregorb98b1992009-08-11 05:31:07 +00007018 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007019 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007020 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007021 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007022
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007023 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007024 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007025 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007026 E->getRParenLoc());
7027}
Mike Stump1eb44332009-09-09 15:08:12 +00007028
Douglas Gregorb98b1992009-08-11 05:31:07 +00007029template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007030ExprResult
John McCall454feb92009-12-08 09:21:05 +00007031TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007032 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007033 TypeSourceInfo *TInfo
7034 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7035 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007036 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007037
Douglas Gregorb98b1992009-08-11 05:31:07 +00007038 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007039 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007040 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007041
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007042 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7043 E->getLocStart(),
7044 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007045 E->getLocEnd());
7046 }
Mike Stump1eb44332009-09-09 15:08:12 +00007047
Eli Friedmanef331b72012-01-20 01:26:23 +00007048 // We don't know whether the subexpression is potentially evaluated until
7049 // after we perform semantic analysis. We speculatively assume it is
7050 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007051 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00007052 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00007053
John McCall60d7b3a2010-08-24 06:29:42 +00007054 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007055 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007056 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007057
Douglas Gregorb98b1992009-08-11 05:31:07 +00007058 if (!getDerived().AlwaysRebuild() &&
7059 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007060 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007061
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007062 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7063 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007064 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007065 E->getLocEnd());
7066}
7067
7068template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007069ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007070TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7071 if (E->isTypeOperand()) {
7072 TypeSourceInfo *TInfo
7073 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7074 if (!TInfo)
7075 return ExprError();
7076
7077 if (!getDerived().AlwaysRebuild() &&
7078 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007079 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007080
Douglas Gregor3c52a212011-03-06 17:40:41 +00007081 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007082 E->getLocStart(),
7083 TInfo,
7084 E->getLocEnd());
7085 }
7086
Francois Pichet01b7c302010-09-08 12:20:18 +00007087 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7088
7089 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7090 if (SubExpr.isInvalid())
7091 return ExprError();
7092
7093 if (!getDerived().AlwaysRebuild() &&
7094 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007095 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007096
7097 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7098 E->getLocStart(),
7099 SubExpr.get(),
7100 E->getLocEnd());
7101}
7102
7103template<typename Derived>
7104ExprResult
John McCall454feb92009-12-08 09:21:05 +00007105TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007106 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007107}
Mike Stump1eb44332009-09-09 15:08:12 +00007108
Douglas Gregorb98b1992009-08-11 05:31:07 +00007109template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007110ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007111TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007112 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007113 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007114}
Mike Stump1eb44332009-09-09 15:08:12 +00007115
Douglas Gregorb98b1992009-08-11 05:31:07 +00007116template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007117ExprResult
John McCall454feb92009-12-08 09:21:05 +00007118TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007119 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007120 QualType T;
7121 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7122 T = MD->getThisType(getSema().Context);
7123 else
7124 T = getSema().Context.getPointerType(
7125 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007126
Douglas Gregorec79d872012-02-24 17:41:38 +00007127 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7128 // Make sure that we capture 'this'.
7129 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007130 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007131 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007132
Douglas Gregor828a1972010-01-07 23:12:05 +00007133 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007134}
Mike Stump1eb44332009-09-09 15:08:12 +00007135
Douglas Gregorb98b1992009-08-11 05:31:07 +00007136template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007137ExprResult
John McCall454feb92009-12-08 09:21:05 +00007138TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007139 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007140 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007141 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007142
Douglas Gregorb98b1992009-08-11 05:31:07 +00007143 if (!getDerived().AlwaysRebuild() &&
7144 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007145 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007146
Douglas Gregorbca01b42011-07-06 22:04:06 +00007147 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7148 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007149}
Mike Stump1eb44332009-09-09 15:08:12 +00007150
Douglas Gregorb98b1992009-08-11 05:31:07 +00007151template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007152ExprResult
John McCall454feb92009-12-08 09:21:05 +00007153TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007154 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007155 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7156 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007157 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007158 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007159
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007160 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007161 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007162 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007163
Douglas Gregor036aed12009-12-23 23:03:06 +00007164 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007165}
Mike Stump1eb44332009-09-09 15:08:12 +00007166
Douglas Gregorb98b1992009-08-11 05:31:07 +00007167template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007168ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007169TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7170 CXXScalarValueInitExpr *E) {
7171 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7172 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007173 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007174
Douglas Gregorb98b1992009-08-11 05:31:07 +00007175 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007176 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007177 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007178
Chad Rosier4a9d7952012-08-08 18:46:20 +00007179 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007180 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007181 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007182}
Mike Stump1eb44332009-09-09 15:08:12 +00007183
Douglas Gregorb98b1992009-08-11 05:31:07 +00007184template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007185ExprResult
John McCall454feb92009-12-08 09:21:05 +00007186TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007187 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007188 TypeSourceInfo *AllocTypeInfo
7189 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7190 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007191 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007192
Douglas Gregorb98b1992009-08-11 05:31:07 +00007193 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007194 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007195 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007196 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007197
Douglas Gregorb98b1992009-08-11 05:31:07 +00007198 // Transform the placement arguments (if any).
7199 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007200 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007201 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007202 E->getNumPlacementArgs(), true,
7203 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007204 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007205
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007206 // Transform the initializer (if any).
7207 Expr *OldInit = E->getInitializer();
7208 ExprResult NewInit;
7209 if (OldInit)
7210 NewInit = getDerived().TransformExpr(OldInit);
7211 if (NewInit.isInvalid())
7212 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007213
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007214 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007215 FunctionDecl *OperatorNew = 0;
7216 if (E->getOperatorNew()) {
7217 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007218 getDerived().TransformDecl(E->getLocStart(),
7219 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007220 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007221 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007222 }
7223
7224 FunctionDecl *OperatorDelete = 0;
7225 if (E->getOperatorDelete()) {
7226 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007227 getDerived().TransformDecl(E->getLocStart(),
7228 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007229 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007230 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007231 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007232
Douglas Gregorb98b1992009-08-11 05:31:07 +00007233 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007234 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007235 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007236 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007237 OperatorNew == E->getOperatorNew() &&
7238 OperatorDelete == E->getOperatorDelete() &&
7239 !ArgumentChanged) {
7240 // Mark any declarations we need as referenced.
7241 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007242 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007243 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007244 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007245 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007246
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007247 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007248 QualType ElementType
7249 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7250 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7251 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7252 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007253 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007254 }
7255 }
7256 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007257
John McCall3fa5cae2010-10-26 07:05:15 +00007258 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007259 }
Mike Stump1eb44332009-09-09 15:08:12 +00007260
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007261 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007262 if (!ArraySize.get()) {
7263 // If no array size was specified, but the new expression was
7264 // instantiated with an array type (e.g., "new T" where T is
7265 // instantiated with "int[4]"), extract the outer bound from the
7266 // array type as our array size. We do this with constant and
7267 // dependently-sized array types.
7268 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7269 if (!ArrayT) {
7270 // Do nothing
7271 } else if (const ConstantArrayType *ConsArrayT
7272 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007273 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007274 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007275 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007276 SemaRef.Context.getSizeType(),
7277 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007278 AllocType = ConsArrayT->getElementType();
7279 } else if (const DependentSizedArrayType *DepArrayT
7280 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7281 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007282 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007283 AllocType = DepArrayT->getElementType();
7284 }
7285 }
7286 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007287
Douglas Gregorb98b1992009-08-11 05:31:07 +00007288 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7289 E->isGlobalNew(),
7290 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007291 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007292 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007293 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007294 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007295 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007296 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007297 E->getDirectInitRange(),
7298 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007299}
Mike Stump1eb44332009-09-09 15:08:12 +00007300
Douglas Gregorb98b1992009-08-11 05:31:07 +00007301template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007302ExprResult
John McCall454feb92009-12-08 09:21:05 +00007303TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007304 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007305 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007306 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007307
Douglas Gregor1af74512010-02-26 00:38:10 +00007308 // Transform the delete operator, if known.
7309 FunctionDecl *OperatorDelete = 0;
7310 if (E->getOperatorDelete()) {
7311 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007312 getDerived().TransformDecl(E->getLocStart(),
7313 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007314 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007315 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007316 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007317
Douglas Gregorb98b1992009-08-11 05:31:07 +00007318 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007319 Operand.get() == E->getArgument() &&
7320 OperatorDelete == E->getOperatorDelete()) {
7321 // Mark any declarations we need as referenced.
7322 // FIXME: instantiation-specific.
7323 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007324 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007325
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007326 if (!E->getArgument()->isTypeDependent()) {
7327 QualType Destroyed = SemaRef.Context.getBaseElementType(
7328 E->getDestroyedType());
7329 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7330 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007331 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007332 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007333 }
7334 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007335
John McCall3fa5cae2010-10-26 07:05:15 +00007336 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007337 }
Mike Stump1eb44332009-09-09 15:08:12 +00007338
Douglas Gregorb98b1992009-08-11 05:31:07 +00007339 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7340 E->isGlobalDelete(),
7341 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007342 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007343}
Mike Stump1eb44332009-09-09 15:08:12 +00007344
Douglas Gregorb98b1992009-08-11 05:31:07 +00007345template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007346ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007347TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007348 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007349 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007350 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007351 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007352
John McCallb3d87482010-08-24 05:47:05 +00007353 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007354 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007355 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007356 E->getOperatorLoc(),
7357 E->isArrow()? tok::arrow : tok::period,
7358 ObjectTypePtr,
7359 MayBePseudoDestructor);
7360 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007361 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007362
John McCallb3d87482010-08-24 05:47:05 +00007363 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007364 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7365 if (QualifierLoc) {
7366 QualifierLoc
7367 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7368 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007369 return ExprError();
7370 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007371 CXXScopeSpec SS;
7372 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007373
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007374 PseudoDestructorTypeStorage Destroyed;
7375 if (E->getDestroyedTypeInfo()) {
7376 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007377 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007378 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007379 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007380 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007381 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007382 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007383 // We aren't likely to be able to resolve the identifier down to a type
7384 // now anyway, so just retain the identifier.
7385 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7386 E->getDestroyedTypeLoc());
7387 } else {
7388 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007389 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007390 *E->getDestroyedTypeIdentifier(),
7391 E->getDestroyedTypeLoc(),
7392 /*Scope=*/0,
7393 SS, ObjectTypePtr,
7394 false);
7395 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007396 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007397
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007398 Destroyed
7399 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7400 E->getDestroyedTypeLoc());
7401 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007402
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007403 TypeSourceInfo *ScopeTypeInfo = 0;
7404 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007405 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007406 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007407 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007408 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007409
John McCall9ae2f072010-08-23 23:25:46 +00007410 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007411 E->getOperatorLoc(),
7412 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007413 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007414 ScopeTypeInfo,
7415 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007416 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007417 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007418}
Mike Stump1eb44332009-09-09 15:08:12 +00007419
Douglas Gregora71d8192009-09-04 17:36:40 +00007420template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007421ExprResult
John McCallba135432009-11-21 08:51:07 +00007422TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007423 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007424 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7425 Sema::LookupOrdinaryName);
7426
7427 // Transform all the decls.
7428 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7429 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007430 NamedDecl *InstD = static_cast<NamedDecl*>(
7431 getDerived().TransformDecl(Old->getNameLoc(),
7432 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007433 if (!InstD) {
7434 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7435 // This can happen because of dependent hiding.
7436 if (isa<UsingShadowDecl>(*I))
7437 continue;
7438 else
John McCallf312b1e2010-08-26 23:41:50 +00007439 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007440 }
John McCallf7a1a742009-11-24 19:00:30 +00007441
7442 // Expand using declarations.
7443 if (isa<UsingDecl>(InstD)) {
7444 UsingDecl *UD = cast<UsingDecl>(InstD);
7445 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7446 E = UD->shadow_end(); I != E; ++I)
7447 R.addDecl(*I);
7448 continue;
7449 }
7450
7451 R.addDecl(InstD);
7452 }
7453
7454 // Resolve a kind, but don't do any further analysis. If it's
7455 // ambiguous, the callee needs to deal with it.
7456 R.resolveKind();
7457
7458 // Rebuild the nested-name qualifier, if present.
7459 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007460 if (Old->getQualifierLoc()) {
7461 NestedNameSpecifierLoc QualifierLoc
7462 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7463 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007464 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007465
Douglas Gregor4c9be892011-02-28 20:01:57 +00007466 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007467 }
7468
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007469 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007470 CXXRecordDecl *NamingClass
7471 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7472 Old->getNameLoc(),
7473 Old->getNamingClass()));
7474 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007475 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007476
Douglas Gregor66c45152010-04-27 16:10:10 +00007477 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007478 }
7479
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007480 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7481
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007482 // If we have neither explicit template arguments, nor the template keyword,
7483 // it's a normal declaration name.
7484 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007485 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7486
7487 // If we have template arguments, rebuild them, then rebuild the
7488 // templateid expression.
7489 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007490 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7491 Old->getNumTemplateArgs(),
7492 TransArgs))
7493 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007494
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007495 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007496 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007497}
Mike Stump1eb44332009-09-09 15:08:12 +00007498
Douglas Gregorb98b1992009-08-11 05:31:07 +00007499template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007500ExprResult
John McCall454feb92009-12-08 09:21:05 +00007501TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007502 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7503 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007504 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007505
Douglas Gregorb98b1992009-08-11 05:31:07 +00007506 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007507 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007508 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007509
Mike Stump1eb44332009-09-09 15:08:12 +00007510 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007511 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007512 T,
7513 E->getLocEnd());
7514}
Mike Stump1eb44332009-09-09 15:08:12 +00007515
Douglas Gregorb98b1992009-08-11 05:31:07 +00007516template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007517ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007518TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7519 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7520 if (!LhsT)
7521 return ExprError();
7522
7523 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7524 if (!RhsT)
7525 return ExprError();
7526
7527 if (!getDerived().AlwaysRebuild() &&
7528 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7529 return SemaRef.Owned(E);
7530
7531 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7532 E->getLocStart(),
7533 LhsT, RhsT,
7534 E->getLocEnd());
7535}
7536
7537template<typename Derived>
7538ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007539TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7540 bool ArgChanged = false;
7541 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7542 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7543 TypeSourceInfo *From = E->getArg(I);
7544 TypeLoc FromTL = From->getTypeLoc();
7545 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7546 TypeLocBuilder TLB;
7547 TLB.reserve(FromTL.getFullDataSize());
7548 QualType To = getDerived().TransformType(TLB, FromTL);
7549 if (To.isNull())
7550 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007551
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007552 if (To == From->getType())
7553 Args.push_back(From);
7554 else {
7555 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7556 ArgChanged = true;
7557 }
7558 continue;
7559 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007560
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007561 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007562
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007563 // We have a pack expansion. Instantiate it.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007564 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007565 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7566 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7567 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007568
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007569 // Determine whether the set of unexpanded parameter packs can and should
7570 // be expanded.
7571 bool Expand = true;
7572 bool RetainExpansion = false;
7573 llvm::Optional<unsigned> OrigNumExpansions
7574 = ExpansionTL.getTypePtr()->getNumExpansions();
7575 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7576 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7577 PatternTL.getSourceRange(),
7578 Unexpanded,
7579 Expand, RetainExpansion,
7580 NumExpansions))
7581 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007582
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007583 if (!Expand) {
7584 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007585 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007586 // expansion.
7587 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007588
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007589 TypeLocBuilder TLB;
7590 TLB.reserve(From->getTypeLoc().getFullDataSize());
7591
7592 QualType To = getDerived().TransformType(TLB, PatternTL);
7593 if (To.isNull())
7594 return ExprError();
7595
Chad Rosier4a9d7952012-08-08 18:46:20 +00007596 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007597 PatternTL.getSourceRange(),
7598 ExpansionTL.getEllipsisLoc(),
7599 NumExpansions);
7600 if (To.isNull())
7601 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007602
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007603 PackExpansionTypeLoc ToExpansionTL
7604 = TLB.push<PackExpansionTypeLoc>(To);
7605 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7606 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7607 continue;
7608 }
7609
7610 // Expand the pack expansion by substituting for each argument in the
7611 // pack(s).
7612 for (unsigned I = 0; I != *NumExpansions; ++I) {
7613 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7614 TypeLocBuilder TLB;
7615 TLB.reserve(PatternTL.getFullDataSize());
7616 QualType To = getDerived().TransformType(TLB, PatternTL);
7617 if (To.isNull())
7618 return ExprError();
7619
7620 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7621 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007622
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007623 if (!RetainExpansion)
7624 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007625
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007626 // If we're supposed to retain a pack expansion, do so by temporarily
7627 // forgetting the partially-substituted parameter pack.
7628 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7629
7630 TypeLocBuilder TLB;
7631 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007632
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007633 QualType To = getDerived().TransformType(TLB, PatternTL);
7634 if (To.isNull())
7635 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007636
7637 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007638 PatternTL.getSourceRange(),
7639 ExpansionTL.getEllipsisLoc(),
7640 NumExpansions);
7641 if (To.isNull())
7642 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007643
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007644 PackExpansionTypeLoc ToExpansionTL
7645 = TLB.push<PackExpansionTypeLoc>(To);
7646 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7647 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7648 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007649
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007650 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7651 return SemaRef.Owned(E);
7652
7653 return getDerived().RebuildTypeTrait(E->getTrait(),
7654 E->getLocStart(),
7655 Args,
7656 E->getLocEnd());
7657}
7658
7659template<typename Derived>
7660ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007661TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7662 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7663 if (!T)
7664 return ExprError();
7665
7666 if (!getDerived().AlwaysRebuild() &&
7667 T == E->getQueriedTypeSourceInfo())
7668 return SemaRef.Owned(E);
7669
7670 ExprResult SubExpr;
7671 {
7672 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7673 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7674 if (SubExpr.isInvalid())
7675 return ExprError();
7676
7677 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7678 return SemaRef.Owned(E);
7679 }
7680
7681 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7682 E->getLocStart(),
7683 T,
7684 SubExpr.get(),
7685 E->getLocEnd());
7686}
7687
7688template<typename Derived>
7689ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007690TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7691 ExprResult SubExpr;
7692 {
7693 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7694 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7695 if (SubExpr.isInvalid())
7696 return ExprError();
7697
7698 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7699 return SemaRef.Owned(E);
7700 }
7701
7702 return getDerived().RebuildExpressionTrait(
7703 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7704}
7705
7706template<typename Derived>
7707ExprResult
John McCall865d4472009-11-19 22:55:06 +00007708TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007709 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007710 NestedNameSpecifierLoc QualifierLoc
7711 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7712 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007713 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007714 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007715
John McCall43fed0d2010-11-12 08:19:04 +00007716 // TODO: If this is a conversion-function-id, verify that the
7717 // destination type name (if present) resolves the same way after
7718 // instantiation as it did in the local scope.
7719
Abramo Bagnara25777432010-08-11 22:01:17 +00007720 DeclarationNameInfo NameInfo
7721 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7722 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007723 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007724
John McCallf7a1a742009-11-24 19:00:30 +00007725 if (!E->hasExplicitTemplateArgs()) {
7726 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007727 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007728 // Note: it is sufficient to compare the Name component of NameInfo:
7729 // if name has not changed, DNLoc has not changed either.
7730 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007731 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007732
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007733 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007734 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007735 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007736 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007737 }
John McCalld5532b62009-11-23 01:53:49 +00007738
7739 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007740 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7741 E->getNumTemplateArgs(),
7742 TransArgs))
7743 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007744
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007745 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007746 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007747 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007748 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007749}
7750
7751template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007752ExprResult
John McCall454feb92009-12-08 09:21:05 +00007753TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007754 // CXXConstructExprs are always implicit, so when we have a
7755 // 1-argument construction we just transform that argument.
7756 if (E->getNumArgs() == 1 ||
7757 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7758 return getDerived().TransformExpr(E->getArg(0));
7759
Douglas Gregorb98b1992009-08-11 05:31:07 +00007760 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7761
7762 QualType T = getDerived().TransformType(E->getType());
7763 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007764 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007765
7766 CXXConstructorDecl *Constructor
7767 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007768 getDerived().TransformDecl(E->getLocStart(),
7769 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007770 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007771 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007772
Douglas Gregorb98b1992009-08-11 05:31:07 +00007773 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007774 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007775 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007776 &ArgumentChanged))
7777 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007778
Douglas Gregorb98b1992009-08-11 05:31:07 +00007779 if (!getDerived().AlwaysRebuild() &&
7780 T == E->getType() &&
7781 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007782 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007783 // Mark the constructor as referenced.
7784 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007785 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007786 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007787 }
Mike Stump1eb44332009-09-09 15:08:12 +00007788
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007789 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7790 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007791 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007792 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007793 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007794 E->getConstructionKind(),
7795 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007796}
Mike Stump1eb44332009-09-09 15:08:12 +00007797
Douglas Gregorb98b1992009-08-11 05:31:07 +00007798/// \brief Transform a C++ temporary-binding expression.
7799///
Douglas Gregor51326552009-12-24 18:51:59 +00007800/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7801/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007802template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007803ExprResult
John McCall454feb92009-12-08 09:21:05 +00007804TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007805 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007806}
Mike Stump1eb44332009-09-09 15:08:12 +00007807
John McCall4765fa02010-12-06 08:20:24 +00007808/// \brief Transform a C++ expression that contains cleanups that should
7809/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007810///
John McCall4765fa02010-12-06 08:20:24 +00007811/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007812/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007813template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007814ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007815TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007816 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007817}
Mike Stump1eb44332009-09-09 15:08:12 +00007818
Douglas Gregorb98b1992009-08-11 05:31:07 +00007819template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007820ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007821TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007822 CXXTemporaryObjectExpr *E) {
7823 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7824 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007825 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007826
Douglas Gregorb98b1992009-08-11 05:31:07 +00007827 CXXConstructorDecl *Constructor
7828 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007829 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007830 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007831 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007832 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007833
Douglas Gregorb98b1992009-08-11 05:31:07 +00007834 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007835 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007836 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007837 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007838 &ArgumentChanged))
7839 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007840
Douglas Gregorb98b1992009-08-11 05:31:07 +00007841 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007842 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007843 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007844 !ArgumentChanged) {
7845 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007846 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007847 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007848 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007849
Douglas Gregorab6677e2010-09-08 00:15:04 +00007850 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7851 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007852 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007853 E->getLocEnd());
7854}
Mike Stump1eb44332009-09-09 15:08:12 +00007855
Douglas Gregorb98b1992009-08-11 05:31:07 +00007856template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007857ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007858TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007859 // Create the local class that will describe the lambda.
7860 CXXRecordDecl *Class
Douglas Gregorf54486a2012-04-04 17:40:10 +00007861 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7862 /*KnownDependent=*/false);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007863 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007864
Douglas Gregordfca6f52012-02-13 22:00:16 +00007865 // Transform the type of the lambda parameters and start the definition of
7866 // the lambda itself.
7867 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00007868 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00007869 if (!MethodTy)
7870 return ExprError();
7871
Douglas Gregorc6889e72012-02-14 22:28:59 +00007872 // Transform lambda parameters.
Douglas Gregorc6889e72012-02-14 22:28:59 +00007873 llvm::SmallVector<QualType, 4> ParamTypes;
7874 llvm::SmallVector<ParmVarDecl *, 4> Params;
7875 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7876 E->getCallOperator()->param_begin(),
7877 E->getCallOperator()->param_size(),
7878 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00007879 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00007880
Douglas Gregordfca6f52012-02-13 22:00:16 +00007881 // Build the call operator.
7882 CXXMethodDecl *CallOperator
7883 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007884 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007885 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007886 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007887 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00007888
Richard Smith612409e2012-07-25 03:56:55 +00007889 return getDerived().TransformLambdaScope(E, CallOperator);
7890}
7891
7892template<typename Derived>
7893ExprResult
7894TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
7895 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00007896 // Introduce the context of the call operator.
7897 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7898
Douglas Gregordfca6f52012-02-13 22:00:16 +00007899 // Enter the scope of the lambda.
7900 sema::LambdaScopeInfo *LSI
7901 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7902 E->getCaptureDefault(),
7903 E->hasExplicitParameters(),
7904 E->hasExplicitResultType(),
7905 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007906
Douglas Gregordfca6f52012-02-13 22:00:16 +00007907 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00007908 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00007909 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007910 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007911 CEnd = E->capture_end();
7912 C != CEnd; ++C) {
7913 // When we hit the first implicit capture, tell Sema that we've finished
7914 // the list of explicit captures.
7915 if (!FinishedExplicitCaptures && C->isImplicit()) {
7916 getSema().finishLambdaExplicitCaptures(LSI);
7917 FinishedExplicitCaptures = true;
7918 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007919
Douglas Gregordfca6f52012-02-13 22:00:16 +00007920 // Capturing 'this' is trivial.
7921 if (C->capturesThis()) {
7922 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7923 continue;
7924 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007925
Douglas Gregora7365242012-02-14 19:27:52 +00007926 // Determine the capture kind for Sema.
7927 Sema::TryCaptureKind Kind
7928 = C->isImplicit()? Sema::TryCapture_Implicit
7929 : C->getCaptureKind() == LCK_ByCopy
7930 ? Sema::TryCapture_ExplicitByVal
7931 : Sema::TryCapture_ExplicitByRef;
7932 SourceLocation EllipsisLoc;
7933 if (C->isPackExpansion()) {
7934 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7935 bool ShouldExpand = false;
7936 bool RetainExpansion = false;
7937 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007938 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7939 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00007940 Unexpanded,
7941 ShouldExpand, RetainExpansion,
7942 NumExpansions))
7943 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007944
Douglas Gregora7365242012-02-14 19:27:52 +00007945 if (ShouldExpand) {
7946 // The transform has determined that we should perform an expansion;
7947 // transform and capture each of the arguments.
7948 // expansion of the pattern. Do so.
7949 VarDecl *Pack = C->getCapturedVar();
7950 for (unsigned I = 0; I != *NumExpansions; ++I) {
7951 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7952 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00007953 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00007954 Pack));
7955 if (!CapturedVar) {
7956 Invalid = true;
7957 continue;
7958 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007959
Douglas Gregora7365242012-02-14 19:27:52 +00007960 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007961 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
7962 }
Douglas Gregora7365242012-02-14 19:27:52 +00007963 continue;
7964 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007965
Douglas Gregora7365242012-02-14 19:27:52 +00007966 EllipsisLoc = C->getEllipsisLoc();
7967 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007968
Douglas Gregordfca6f52012-02-13 22:00:16 +00007969 // Transform the captured variable.
7970 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00007971 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007972 C->getCapturedVar()));
7973 if (!CapturedVar) {
7974 Invalid = true;
7975 continue;
7976 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007977
Douglas Gregordfca6f52012-02-13 22:00:16 +00007978 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007979 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007980 }
7981 if (!FinishedExplicitCaptures)
7982 getSema().finishLambdaExplicitCaptures(LSI);
7983
Douglas Gregordfca6f52012-02-13 22:00:16 +00007984
7985 // Enter a new evaluation context to insulate the lambda from any
7986 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007987 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007988
7989 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007990 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00007991 /*IsInstantiation=*/true);
7992 return ExprError();
7993 }
7994
7995 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00007996 StmtResult Body = getDerived().TransformStmt(E->getBody());
7997 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007998 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00007999 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008000 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008001 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008002
Chad Rosier4a9d7952012-08-08 18:46:20 +00008003 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008004 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008005}
8006
8007template<typename Derived>
8008ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008009TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008010 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008011 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8012 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008013 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008014
Douglas Gregorb98b1992009-08-11 05:31:07 +00008015 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008016 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008017 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008018 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008019 &ArgumentChanged))
8020 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008021
Douglas Gregorb98b1992009-08-11 05:31:07 +00008022 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008023 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008024 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008025 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008026
Douglas Gregorb98b1992009-08-11 05:31:07 +00008027 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008028 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008029 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008030 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008031 E->getRParenLoc());
8032}
Mike Stump1eb44332009-09-09 15:08:12 +00008033
Douglas Gregorb98b1992009-08-11 05:31:07 +00008034template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008035ExprResult
John McCall865d4472009-11-19 22:55:06 +00008036TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008037 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008038 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008039 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008040 Expr *OldBase;
8041 QualType BaseType;
8042 QualType ObjectType;
8043 if (!E->isImplicitAccess()) {
8044 OldBase = E->getBase();
8045 Base = getDerived().TransformExpr(OldBase);
8046 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008047 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008048
John McCallaa81e162009-12-01 22:10:20 +00008049 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008050 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008051 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008052 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008053 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008054 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008055 ObjectTy,
8056 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008057 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008058 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008059
John McCallb3d87482010-08-24 05:47:05 +00008060 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008061 BaseType = ((Expr*) Base.get())->getType();
8062 } else {
8063 OldBase = 0;
8064 BaseType = getDerived().TransformType(E->getBaseType());
8065 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8066 }
Mike Stump1eb44332009-09-09 15:08:12 +00008067
Douglas Gregor6cd21982009-10-20 05:58:46 +00008068 // Transform the first part of the nested-name-specifier that qualifies
8069 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008070 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008071 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008072 E->getFirstQualifierFoundInScope(),
8073 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008074
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008075 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008076 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008077 QualifierLoc
8078 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8079 ObjectType,
8080 FirstQualifierInScope);
8081 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008082 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008083 }
Mike Stump1eb44332009-09-09 15:08:12 +00008084
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008085 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8086
John McCall43fed0d2010-11-12 08:19:04 +00008087 // TODO: If this is a conversion-function-id, verify that the
8088 // destination type name (if present) resolves the same way after
8089 // instantiation as it did in the local scope.
8090
Abramo Bagnara25777432010-08-11 22:01:17 +00008091 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008092 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008093 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008094 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008095
John McCallaa81e162009-12-01 22:10:20 +00008096 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008097 // This is a reference to a member without an explicitly-specified
8098 // template argument list. Optimize for this common case.
8099 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008100 Base.get() == OldBase &&
8101 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008102 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008103 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008104 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008105 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008106
John McCall9ae2f072010-08-23 23:25:46 +00008107 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008108 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008109 E->isArrow(),
8110 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008111 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008112 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008113 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008114 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008115 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008116 }
8117
John McCalld5532b62009-11-23 01:53:49 +00008118 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008119 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8120 E->getNumTemplateArgs(),
8121 TransArgs))
8122 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008123
John McCall9ae2f072010-08-23 23:25:46 +00008124 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008125 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008126 E->isArrow(),
8127 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008128 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008129 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008130 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008131 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008132 &TransArgs);
8133}
8134
8135template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008136ExprResult
John McCall454feb92009-12-08 09:21:05 +00008137TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008138 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008139 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008140 QualType BaseType;
8141 if (!Old->isImplicitAccess()) {
8142 Base = getDerived().TransformExpr(Old->getBase());
8143 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008144 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008145 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8146 Old->isArrow());
8147 if (Base.isInvalid())
8148 return ExprError();
8149 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008150 } else {
8151 BaseType = getDerived().TransformType(Old->getBaseType());
8152 }
John McCall129e2df2009-11-30 22:42:35 +00008153
Douglas Gregor4c9be892011-02-28 20:01:57 +00008154 NestedNameSpecifierLoc QualifierLoc;
8155 if (Old->getQualifierLoc()) {
8156 QualifierLoc
8157 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8158 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008159 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008160 }
8161
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008162 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8163
Abramo Bagnara25777432010-08-11 22:01:17 +00008164 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008165 Sema::LookupOrdinaryName);
8166
8167 // Transform all the decls.
8168 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8169 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008170 NamedDecl *InstD = static_cast<NamedDecl*>(
8171 getDerived().TransformDecl(Old->getMemberLoc(),
8172 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008173 if (!InstD) {
8174 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8175 // This can happen because of dependent hiding.
8176 if (isa<UsingShadowDecl>(*I))
8177 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008178 else {
8179 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008180 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008181 }
John McCall9f54ad42009-12-10 09:41:52 +00008182 }
John McCall129e2df2009-11-30 22:42:35 +00008183
8184 // Expand using declarations.
8185 if (isa<UsingDecl>(InstD)) {
8186 UsingDecl *UD = cast<UsingDecl>(InstD);
8187 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8188 E = UD->shadow_end(); I != E; ++I)
8189 R.addDecl(*I);
8190 continue;
8191 }
8192
8193 R.addDecl(InstD);
8194 }
8195
8196 R.resolveKind();
8197
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008198 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008199 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008200 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008201 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008202 Old->getMemberLoc(),
8203 Old->getNamingClass()));
8204 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008205 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008206
Douglas Gregor66c45152010-04-27 16:10:10 +00008207 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008208 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008209
John McCall129e2df2009-11-30 22:42:35 +00008210 TemplateArgumentListInfo TransArgs;
8211 if (Old->hasExplicitTemplateArgs()) {
8212 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8213 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008214 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8215 Old->getNumTemplateArgs(),
8216 TransArgs))
8217 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008218 }
John McCallc2233c52010-01-15 08:34:02 +00008219
8220 // FIXME: to do this check properly, we will need to preserve the
8221 // first-qualifier-in-scope here, just in case we had a dependent
8222 // base (and therefore couldn't do the check) and a
8223 // nested-name-qualifier (and therefore could do the lookup).
8224 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008225
John McCall9ae2f072010-08-23 23:25:46 +00008226 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008227 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008228 Old->getOperatorLoc(),
8229 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008230 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008231 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008232 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008233 R,
8234 (Old->hasExplicitTemplateArgs()
8235 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008236}
8237
8238template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008239ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008240TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008241 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008242 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8243 if (SubExpr.isInvalid())
8244 return ExprError();
8245
8246 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008247 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008248
8249 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8250}
8251
8252template<typename Derived>
8253ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008254TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008255 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8256 if (Pattern.isInvalid())
8257 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008258
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008259 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8260 return SemaRef.Owned(E);
8261
Douglas Gregor67fd1252011-01-14 21:20:45 +00008262 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8263 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008264}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008265
8266template<typename Derived>
8267ExprResult
8268TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8269 // If E is not value-dependent, then nothing will change when we transform it.
8270 // Note: This is an instantiation-centric view.
8271 if (!E->isValueDependent())
8272 return SemaRef.Owned(E);
8273
8274 // Note: None of the implementations of TryExpandParameterPacks can ever
8275 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008276 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008277 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8278 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008279 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008280 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008281 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008282 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008283 ShouldExpand, RetainExpansion,
8284 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008285 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008286
Douglas Gregor089e8932011-10-10 18:59:29 +00008287 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008288 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008289
Douglas Gregor089e8932011-10-10 18:59:29 +00008290 NamedDecl *Pack = E->getPack();
8291 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008292 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008293 Pack));
8294 if (!Pack)
8295 return ExprError();
8296 }
8297
Chad Rosier4a9d7952012-08-08 18:46:20 +00008298
Douglas Gregoree8aff02011-01-04 17:33:58 +00008299 // We now know the length of the parameter pack, so build a new expression
8300 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008301 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8302 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008303 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008304}
8305
Douglas Gregorbe230c32011-01-03 17:17:50 +00008306template<typename Derived>
8307ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008308TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8309 SubstNonTypeTemplateParmPackExpr *E) {
8310 // Default behavior is to do nothing with this transformation.
8311 return SemaRef.Owned(E);
8312}
8313
8314template<typename Derived>
8315ExprResult
John McCall91a57552011-07-15 05:09:51 +00008316TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8317 SubstNonTypeTemplateParmExpr *E) {
8318 // Default behavior is to do nothing with this transformation.
8319 return SemaRef.Owned(E);
8320}
8321
8322template<typename Derived>
8323ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008324TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8325 MaterializeTemporaryExpr *E) {
8326 return getDerived().TransformExpr(E->GetTemporaryExpr());
8327}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008328
Douglas Gregor03e80032011-06-21 17:03:29 +00008329template<typename Derived>
8330ExprResult
John McCall454feb92009-12-08 09:21:05 +00008331TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008332 return SemaRef.MaybeBindToTemporary(E);
8333}
8334
8335template<typename Derived>
8336ExprResult
8337TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008338 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008339}
8340
8341template<typename Derived>
8342ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008343TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8344 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8345 if (SubExpr.isInvalid())
8346 return ExprError();
8347
8348 if (!getDerived().AlwaysRebuild() &&
8349 SubExpr.get() == E->getSubExpr())
8350 return SemaRef.Owned(E);
8351
8352 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008353}
8354
8355template<typename Derived>
8356ExprResult
8357TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8358 // Transform each of the elements.
8359 llvm::SmallVector<Expr *, 8> Elements;
8360 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008361 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008362 /*IsCall=*/false, Elements, &ArgChanged))
8363 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008364
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008365 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8366 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008367
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008368 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8369 Elements.data(),
8370 Elements.size());
8371}
8372
8373template<typename Derived>
8374ExprResult
8375TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008376 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008377 // Transform each of the elements.
8378 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8379 bool ArgChanged = false;
8380 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8381 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008382
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008383 if (OrigElement.isPackExpansion()) {
8384 // This key/value element is a pack expansion.
8385 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8386 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8387 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8388 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8389
8390 // Determine whether the set of unexpanded parameter packs can
8391 // and should be expanded.
8392 bool Expand = true;
8393 bool RetainExpansion = false;
8394 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8395 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8396 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8397 OrigElement.Value->getLocEnd());
8398 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8399 PatternRange,
8400 Unexpanded,
8401 Expand, RetainExpansion,
8402 NumExpansions))
8403 return ExprError();
8404
8405 if (!Expand) {
8406 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008407 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008408 // expansion.
8409 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8410 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8411 if (Key.isInvalid())
8412 return ExprError();
8413
8414 if (Key.get() != OrigElement.Key)
8415 ArgChanged = true;
8416
8417 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8418 if (Value.isInvalid())
8419 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008420
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008421 if (Value.get() != OrigElement.Value)
8422 ArgChanged = true;
8423
Chad Rosier4a9d7952012-08-08 18:46:20 +00008424 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008425 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8426 };
8427 Elements.push_back(Expansion);
8428 continue;
8429 }
8430
8431 // Record right away that the argument was changed. This needs
8432 // to happen even if the array expands to nothing.
8433 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008434
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008435 // The transform has determined that we should perform an elementwise
8436 // expansion of the pattern. Do so.
8437 for (unsigned I = 0; I != *NumExpansions; ++I) {
8438 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8439 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8440 if (Key.isInvalid())
8441 return ExprError();
8442
8443 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8444 if (Value.isInvalid())
8445 return ExprError();
8446
Chad Rosier4a9d7952012-08-08 18:46:20 +00008447 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008448 Key.get(), Value.get(), SourceLocation(), NumExpansions
8449 };
8450
8451 // If any unexpanded parameter packs remain, we still have a
8452 // pack expansion.
8453 if (Key.get()->containsUnexpandedParameterPack() ||
8454 Value.get()->containsUnexpandedParameterPack())
8455 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008456
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008457 Elements.push_back(Element);
8458 }
8459
8460 // We've finished with this pack expansion.
8461 continue;
8462 }
8463
8464 // Transform and check key.
8465 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8466 if (Key.isInvalid())
8467 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008468
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008469 if (Key.get() != OrigElement.Key)
8470 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008471
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008472 // Transform and check value.
8473 ExprResult Value
8474 = getDerived().TransformExpr(OrigElement.Value);
8475 if (Value.isInvalid())
8476 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008477
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008478 if (Value.get() != OrigElement.Value)
8479 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008480
8481 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008482 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8483 };
8484 Elements.push_back(Element);
8485 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008486
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008487 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8488 return SemaRef.MaybeBindToTemporary(E);
8489
8490 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8491 Elements.data(),
8492 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008493}
8494
Mike Stump1eb44332009-09-09 15:08:12 +00008495template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008496ExprResult
John McCall454feb92009-12-08 09:21:05 +00008497TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008498 TypeSourceInfo *EncodedTypeInfo
8499 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8500 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008501 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008502
Douglas Gregorb98b1992009-08-11 05:31:07 +00008503 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008504 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008505 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008506
8507 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008508 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008509 E->getRParenLoc());
8510}
Mike Stump1eb44332009-09-09 15:08:12 +00008511
Douglas Gregorb98b1992009-08-11 05:31:07 +00008512template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008513ExprResult TreeTransform<Derived>::
8514TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8515 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8516 if (result.isInvalid()) return ExprError();
8517 Expr *subExpr = result.take();
8518
8519 if (!getDerived().AlwaysRebuild() &&
8520 subExpr == E->getSubExpr())
8521 return SemaRef.Owned(E);
8522
8523 return SemaRef.Owned(new(SemaRef.Context)
8524 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8525}
8526
8527template<typename Derived>
8528ExprResult TreeTransform<Derived>::
8529TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008530 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008531 = getDerived().TransformType(E->getTypeInfoAsWritten());
8532 if (!TSInfo)
8533 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008534
John McCallf85e1932011-06-15 23:02:42 +00008535 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008536 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008537 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008538
John McCallf85e1932011-06-15 23:02:42 +00008539 if (!getDerived().AlwaysRebuild() &&
8540 TSInfo == E->getTypeInfoAsWritten() &&
8541 Result.get() == E->getSubExpr())
8542 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008543
John McCallf85e1932011-06-15 23:02:42 +00008544 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008545 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008546 Result.get());
8547}
8548
8549template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008550ExprResult
John McCall454feb92009-12-08 09:21:05 +00008551TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008552 // Transform arguments.
8553 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008554 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008555 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008556 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008557 &ArgChanged))
8558 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008559
Douglas Gregor92e986e2010-04-22 16:44:27 +00008560 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8561 // Class message: transform the receiver type.
8562 TypeSourceInfo *ReceiverTypeInfo
8563 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8564 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008565 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008566
Douglas Gregor92e986e2010-04-22 16:44:27 +00008567 // If nothing changed, just retain the existing message send.
8568 if (!getDerived().AlwaysRebuild() &&
8569 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008570 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008571
8572 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008573 SmallVector<SourceLocation, 16> SelLocs;
8574 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008575 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8576 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008577 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008578 E->getMethodDecl(),
8579 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008580 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008581 E->getRightLoc());
8582 }
8583
8584 // Instance message: transform the receiver
8585 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8586 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008587 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008588 = getDerived().TransformExpr(E->getInstanceReceiver());
8589 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008590 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008591
8592 // If nothing changed, just retain the existing message send.
8593 if (!getDerived().AlwaysRebuild() &&
8594 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008595 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008596
Douglas Gregor92e986e2010-04-22 16:44:27 +00008597 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008598 SmallVector<SourceLocation, 16> SelLocs;
8599 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008600 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008601 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008602 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008603 E->getMethodDecl(),
8604 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008605 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008606 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008607}
8608
Mike Stump1eb44332009-09-09 15:08:12 +00008609template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008610ExprResult
John McCall454feb92009-12-08 09:21:05 +00008611TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008612 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008613}
8614
Mike Stump1eb44332009-09-09 15:08:12 +00008615template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008616ExprResult
John McCall454feb92009-12-08 09:21:05 +00008617TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008618 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008619}
8620
Mike Stump1eb44332009-09-09 15:08:12 +00008621template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008622ExprResult
John McCall454feb92009-12-08 09:21:05 +00008623TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008624 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008625 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008626 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008627 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008628
8629 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008630
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008631 // If nothing changed, just retain the existing expression.
8632 if (!getDerived().AlwaysRebuild() &&
8633 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008634 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008635
John McCall9ae2f072010-08-23 23:25:46 +00008636 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008637 E->getLocation(),
8638 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008639}
8640
Mike Stump1eb44332009-09-09 15:08:12 +00008641template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008642ExprResult
John McCall454feb92009-12-08 09:21:05 +00008643TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008644 // 'super' and types never change. Property never changes. Just
8645 // retain the existing expression.
8646 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008647 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008648
Douglas Gregore3303542010-04-26 20:47:02 +00008649 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008650 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008651 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008652 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008653
Douglas Gregore3303542010-04-26 20:47:02 +00008654 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008655
Douglas Gregore3303542010-04-26 20:47:02 +00008656 // If nothing changed, just retain the existing expression.
8657 if (!getDerived().AlwaysRebuild() &&
8658 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008659 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008660
John McCall12f78a62010-12-02 01:19:52 +00008661 if (E->isExplicitProperty())
8662 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8663 E->getExplicitProperty(),
8664 E->getLocation());
8665
8666 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008667 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008668 E->getImplicitPropertyGetter(),
8669 E->getImplicitPropertySetter(),
8670 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008671}
8672
Mike Stump1eb44332009-09-09 15:08:12 +00008673template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008674ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008675TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8676 // Transform the base expression.
8677 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8678 if (Base.isInvalid())
8679 return ExprError();
8680
8681 // Transform the key expression.
8682 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8683 if (Key.isInvalid())
8684 return ExprError();
8685
8686 // If nothing changed, just retain the existing expression.
8687 if (!getDerived().AlwaysRebuild() &&
8688 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8689 return SemaRef.Owned(E);
8690
Chad Rosier4a9d7952012-08-08 18:46:20 +00008691 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008692 Base.get(), Key.get(),
8693 E->getAtIndexMethodDecl(),
8694 E->setAtIndexMethodDecl());
8695}
8696
8697template<typename Derived>
8698ExprResult
John McCall454feb92009-12-08 09:21:05 +00008699TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008700 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008701 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008702 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008703 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008704
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008705 // If nothing changed, just retain the existing expression.
8706 if (!getDerived().AlwaysRebuild() &&
8707 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008708 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008709
John McCall9ae2f072010-08-23 23:25:46 +00008710 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008711 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008712}
8713
Mike Stump1eb44332009-09-09 15:08:12 +00008714template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008715ExprResult
John McCall454feb92009-12-08 09:21:05 +00008716TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008717 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008718 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008719 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008720 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008721 SubExprs, &ArgumentChanged))
8722 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008723
Douglas Gregorb98b1992009-08-11 05:31:07 +00008724 if (!getDerived().AlwaysRebuild() &&
8725 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008726 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008727
Douglas Gregorb98b1992009-08-11 05:31:07 +00008728 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008729 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008730 E->getRParenLoc());
8731}
8732
Mike Stump1eb44332009-09-09 15:08:12 +00008733template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008734ExprResult
John McCall454feb92009-12-08 09:21:05 +00008735TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008736 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008737
John McCallc6ac9c32011-02-04 18:33:18 +00008738 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8739 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8740
8741 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008742 blockScope->TheDecl->setBlockMissingReturnType(
8743 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008744
Chris Lattner686775d2011-07-20 06:58:45 +00008745 SmallVector<ParmVarDecl*, 4> params;
8746 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008747
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008748 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008749 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8750 oldBlock->param_begin(),
8751 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008752 0, paramTypes, &params)) {
8753 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008754 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008755 }
John McCallc6ac9c32011-02-04 18:33:18 +00008756
8757 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008758 QualType exprResultType =
8759 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008760
8761 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008762 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008763 getSema().Diag(E->getCaretLocation(),
8764 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008765 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008766 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008767 return ExprError();
8768 }
John McCall711c52b2011-01-05 12:14:39 +00008769
John McCallc6ac9c32011-02-04 18:33:18 +00008770 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008771 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008772 paramTypes.data(),
8773 paramTypes.size(),
8774 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008775 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008776 exprFunctionType->getExtInfo());
8777 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008778
8779 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008780 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008781 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008782
8783 if (!oldBlock->blockMissingReturnType()) {
8784 blockScope->HasImplicitReturnType = false;
8785 blockScope->ReturnType = exprResultType;
8786 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008787
John McCall711c52b2011-01-05 12:14:39 +00008788 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008789 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008790 if (body.isInvalid()) {
8791 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008792 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008793 }
John McCall711c52b2011-01-05 12:14:39 +00008794
John McCallc6ac9c32011-02-04 18:33:18 +00008795#ifndef NDEBUG
8796 // In builds with assertions, make sure that we captured everything we
8797 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008798 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8799 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8800 e = oldBlock->capture_end(); i != e; ++i) {
8801 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008802
Douglas Gregorfc921372011-05-20 15:32:55 +00008803 // Ignore parameter packs.
8804 if (isa<ParmVarDecl>(oldCapture) &&
8805 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8806 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008807
Douglas Gregorfc921372011-05-20 15:32:55 +00008808 VarDecl *newCapture =
8809 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8810 oldCapture));
8811 assert(blockScope->CaptureMap.count(newCapture));
8812 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008813 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008814 }
8815#endif
8816
8817 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8818 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008819}
8820
Mike Stump1eb44332009-09-09 15:08:12 +00008821template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008822ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008823TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008824 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008825}
Eli Friedman276b0612011-10-11 02:20:01 +00008826
8827template<typename Derived>
8828ExprResult
8829TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008830 QualType RetTy = getDerived().TransformType(E->getType());
8831 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008832 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008833 SubExprs.reserve(E->getNumSubExprs());
8834 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8835 SubExprs, &ArgumentChanged))
8836 return ExprError();
8837
8838 if (!getDerived().AlwaysRebuild() &&
8839 !ArgumentChanged)
8840 return SemaRef.Owned(E);
8841
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008842 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008843 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008844}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008845
Douglas Gregorb98b1992009-08-11 05:31:07 +00008846//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008847// Type reconstruction
8848//===----------------------------------------------------------------------===//
8849
Mike Stump1eb44332009-09-09 15:08:12 +00008850template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008851QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8852 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008853 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008854 getDerived().getBaseEntity());
8855}
8856
Mike Stump1eb44332009-09-09 15:08:12 +00008857template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008858QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8859 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008860 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008861 getDerived().getBaseEntity());
8862}
8863
Mike Stump1eb44332009-09-09 15:08:12 +00008864template<typename Derived>
8865QualType
John McCall85737a72009-10-30 00:06:24 +00008866TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8867 bool WrittenAsLValue,
8868 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008869 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008870 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008871}
8872
8873template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008874QualType
John McCall85737a72009-10-30 00:06:24 +00008875TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8876 QualType ClassType,
8877 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008878 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008879 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008880}
8881
8882template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008883QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008884TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8885 ArrayType::ArraySizeModifier SizeMod,
8886 const llvm::APInt *Size,
8887 Expr *SizeExpr,
8888 unsigned IndexTypeQuals,
8889 SourceRange BracketsRange) {
8890 if (SizeExpr || !Size)
8891 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8892 IndexTypeQuals, BracketsRange,
8893 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008894
8895 QualType Types[] = {
8896 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8897 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8898 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008899 };
8900 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8901 QualType SizeType;
8902 for (unsigned I = 0; I != NumTypes; ++I)
8903 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8904 SizeType = Types[I];
8905 break;
8906 }
Mike Stump1eb44332009-09-09 15:08:12 +00008907
Eli Friedman01f276d2012-01-25 23:20:27 +00008908 // Note that we can return a VariableArrayType here in the case where
8909 // the element type was a dependent VariableArrayType.
8910 IntegerLiteral *ArraySize
8911 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8912 /*FIXME*/BracketsRange.getBegin());
8913 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008914 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008915 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008916}
Mike Stump1eb44332009-09-09 15:08:12 +00008917
Douglas Gregor577f75a2009-08-04 16:50:30 +00008918template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008919QualType
8920TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008921 ArrayType::ArraySizeModifier SizeMod,
8922 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008923 unsigned IndexTypeQuals,
8924 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008925 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008926 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008927}
8928
8929template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008930QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008931TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008932 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008933 unsigned IndexTypeQuals,
8934 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008935 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008936 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008937}
Mike Stump1eb44332009-09-09 15:08:12 +00008938
Douglas Gregor577f75a2009-08-04 16:50:30 +00008939template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008940QualType
8941TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008942 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008943 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008944 unsigned IndexTypeQuals,
8945 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008946 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008947 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008948 IndexTypeQuals, BracketsRange);
8949}
8950
8951template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008952QualType
8953TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008954 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008955 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008956 unsigned IndexTypeQuals,
8957 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008958 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008959 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008960 IndexTypeQuals, BracketsRange);
8961}
8962
8963template<typename Derived>
8964QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008965 unsigned NumElements,
8966 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008967 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008968 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008969}
Mike Stump1eb44332009-09-09 15:08:12 +00008970
Douglas Gregor577f75a2009-08-04 16:50:30 +00008971template<typename Derived>
8972QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8973 unsigned NumElements,
8974 SourceLocation AttributeLoc) {
8975 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8976 NumElements, true);
8977 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008978 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8979 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008980 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008981}
Mike Stump1eb44332009-09-09 15:08:12 +00008982
Douglas Gregor577f75a2009-08-04 16:50:30 +00008983template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008984QualType
8985TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008986 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008987 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008988 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008989}
Mike Stump1eb44332009-09-09 15:08:12 +00008990
Douglas Gregor577f75a2009-08-04 16:50:30 +00008991template<typename Derived>
8992QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008993 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008994 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008995 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008996 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00008997 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008998 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008999 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00009000 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009001 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009002 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009003 getDerived().getBaseEntity(),
9004 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009005}
Mike Stump1eb44332009-09-09 15:08:12 +00009006
Douglas Gregor577f75a2009-08-04 16:50:30 +00009007template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009008QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9009 return SemaRef.Context.getFunctionNoProtoType(T);
9010}
9011
9012template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009013QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9014 assert(D && "no decl found");
9015 if (D->isInvalidDecl()) return QualType();
9016
Douglas Gregor92e986e2010-04-22 16:44:27 +00009017 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009018 TypeDecl *Ty;
9019 if (isa<UsingDecl>(D)) {
9020 UsingDecl *Using = cast<UsingDecl>(D);
9021 assert(Using->isTypeName() &&
9022 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9023
9024 // A valid resolved using typename decl points to exactly one type decl.
9025 assert(++Using->shadow_begin() == Using->shadow_end());
9026 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009027
John McCalled976492009-12-04 22:46:56 +00009028 } else {
9029 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9030 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9031 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9032 }
9033
9034 return SemaRef.Context.getTypeDeclType(Ty);
9035}
9036
9037template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009038QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9039 SourceLocation Loc) {
9040 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009041}
9042
9043template<typename Derived>
9044QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9045 return SemaRef.Context.getTypeOfType(Underlying);
9046}
9047
9048template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009049QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9050 SourceLocation Loc) {
9051 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009052}
9053
9054template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009055QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9056 UnaryTransformType::UTTKind UKind,
9057 SourceLocation Loc) {
9058 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9059}
9060
9061template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009062QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009063 TemplateName Template,
9064 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009065 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009066 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009067}
Mike Stump1eb44332009-09-09 15:08:12 +00009068
Douglas Gregordcee1a12009-08-06 05:28:30 +00009069template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009070QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9071 SourceLocation KWLoc) {
9072 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9073}
9074
9075template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009076TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009077TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009078 bool TemplateKW,
9079 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009080 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009081 Template);
9082}
9083
9084template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009085TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009086TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9087 const IdentifierInfo &Name,
9088 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009089 QualType ObjectType,
9090 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009091 UnqualifiedId TemplateName;
9092 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009093 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009094 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009095 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009096 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009097 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009098 /*EnteringContext=*/false,
9099 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009100 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009101}
Mike Stump1eb44332009-09-09 15:08:12 +00009102
Douglas Gregorb98b1992009-08-11 05:31:07 +00009103template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009104TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009105TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009106 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009107 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009108 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009109 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009110 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009111 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009112 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009113 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009114 Sema::TemplateTy Template;
9115 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009116 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009117 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009118 /*EnteringContext=*/false,
9119 Template);
9120 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009121}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009122
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009123template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009124ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009125TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9126 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009127 Expr *OrigCallee,
9128 Expr *First,
9129 Expr *Second) {
9130 Expr *Callee = OrigCallee->IgnoreParenCasts();
9131 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009132
Douglas Gregorb98b1992009-08-11 05:31:07 +00009133 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009134 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009135 if (!First->getType()->isOverloadableType() &&
9136 !Second->getType()->isOverloadableType())
9137 return getSema().CreateBuiltinArraySubscriptExpr(First,
9138 Callee->getLocStart(),
9139 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009140 } else if (Op == OO_Arrow) {
9141 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009142 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9143 } else if (Second == 0 || isPostIncDec) {
9144 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009145 // The argument is not of overloadable type, so try to create a
9146 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009147 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009148 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009149
John McCall9ae2f072010-08-23 23:25:46 +00009150 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009151 }
9152 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009153 if (!First->getType()->isOverloadableType() &&
9154 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009155 // Neither of the arguments is an overloadable type, so try to
9156 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009157 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009158 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009159 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009160 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009161 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009162
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009163 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009164 }
9165 }
Mike Stump1eb44332009-09-09 15:08:12 +00009166
9167 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009168 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009169 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009170
John McCall9ae2f072010-08-23 23:25:46 +00009171 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009172 assert(ULE->requiresADL());
9173
9174 // FIXME: Do we have to check
9175 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009176 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009177 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009178 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00009179 }
Mike Stump1eb44332009-09-09 15:08:12 +00009180
Douglas Gregorb98b1992009-08-11 05:31:07 +00009181 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009182 Expr *Args[2] = { First, Second };
9183 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009184
Douglas Gregorb98b1992009-08-11 05:31:07 +00009185 // Create the overloaded operator invocation for unary operators.
9186 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009187 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009188 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009189 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009190 }
Mike Stump1eb44332009-09-09 15:08:12 +00009191
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009192 if (Op == OO_Subscript) {
9193 SourceLocation LBrace;
9194 SourceLocation RBrace;
9195
9196 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9197 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9198 LBrace = SourceLocation::getFromRawEncoding(
9199 NameLoc.CXXOperatorName.BeginOpNameLoc);
9200 RBrace = SourceLocation::getFromRawEncoding(
9201 NameLoc.CXXOperatorName.EndOpNameLoc);
9202 } else {
9203 LBrace = Callee->getLocStart();
9204 RBrace = OpLoc;
9205 }
9206
9207 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9208 First, Second);
9209 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009210
Douglas Gregorb98b1992009-08-11 05:31:07 +00009211 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009212 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009213 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009214 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9215 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009216 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009217
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009218 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009219}
Mike Stump1eb44332009-09-09 15:08:12 +00009220
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009221template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009222ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009223TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009224 SourceLocation OperatorLoc,
9225 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009226 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009227 TypeSourceInfo *ScopeType,
9228 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009229 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009230 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009231 QualType BaseType = Base->getType();
9232 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009233 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009234 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009235 !BaseType->getAs<PointerType>()->getPointeeType()
9236 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009237 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009238 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009239 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009240 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009241 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009242 /*FIXME?*/true);
9243 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009244
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009245 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009246 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9247 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9248 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9249 NameInfo.setNamedTypeInfo(DestroyedType);
9250
Richard Smith6314db92012-05-15 06:15:11 +00009251 // The scope type is now known to be a valid nested name specifier
9252 // component. Tack it on to the end of the nested name specifier.
9253 if (ScopeType)
9254 SS.Extend(SemaRef.Context, SourceLocation(),
9255 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009256
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009257 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009258 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009259 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009260 SS, TemplateKWLoc,
9261 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009262 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009263 /*TemplateArgs*/ 0);
9264}
9265
Douglas Gregor577f75a2009-08-04 16:50:30 +00009266} // end namespace clang
9267
9268#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H