blob: 05a3c611e9f8b0c03229d780dbfca571404fcb54 [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.
John McCall60d7b3a2010-08-24 06:29:42 +00001165 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001166 bool IsSimple,
1167 bool IsVolatile,
1168 unsigned NumOutputs,
1169 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001170 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001171 MultiExprArg Constraints,
1172 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001173 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001174 MultiExprArg Clobbers,
Chad Rosierdf4ee102012-08-20 17:11:53 +00001175 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001176 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001177 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001178 Exprs, AsmString, Clobbers,
Chad Rosierdf4ee102012-08-20 17:11:53 +00001179 RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001180 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001181
Chad Rosier8cd64b42012-06-11 20:47:18 +00001182 /// \brief Build a new MS style inline asm statement.
1183 ///
1184 /// By default, performs semantic analysis to build the new statement.
1185 /// Subclasses may override this routine to provide different behavior.
1186 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc,
Chad Rosier7bd092b2012-08-15 16:53:30 +00001187 SourceLocation LBraceLoc,
Chad Rosier79efe242012-08-07 00:29:06 +00001188 ArrayRef<Token> AsmToks,
Chad Rosier8cd64b42012-06-11 20:47:18 +00001189 SourceLocation EndLoc) {
Chad Rosier7bd092b2012-08-15 16:53:30 +00001190 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001191 }
1192
James Dennett699c9042012-06-15 07:13:21 +00001193 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001194 ///
1195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001197 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001198 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001199 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001200 Stmt *Finally) {
1201 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1202 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001203 }
1204
Douglas Gregorbe270a02010-04-26 17:57:08 +00001205 /// \brief Rebuild an Objective-C exception declaration.
1206 ///
1207 /// By default, performs semantic analysis to build the new declaration.
1208 /// Subclasses may override this routine to provide different behavior.
1209 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1210 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001211 return getSema().BuildObjCExceptionDecl(TInfo, T,
1212 ExceptionDecl->getInnerLocStart(),
1213 ExceptionDecl->getLocation(),
1214 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001215 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001216
James Dennett699c9042012-06-15 07:13:21 +00001217 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001218 ///
1219 /// By default, performs semantic analysis to build the new statement.
1220 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001221 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001222 SourceLocation RParenLoc,
1223 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001224 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001225 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001226 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001227 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001228
James Dennett699c9042012-06-15 07:13:21 +00001229 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001230 ///
1231 /// By default, performs semantic analysis to build the new statement.
1232 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001233 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001234 Stmt *Body) {
1235 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001236 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001237
James Dennett699c9042012-06-15 07:13:21 +00001238 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001239 ///
1240 /// By default, performs semantic analysis to build the new statement.
1241 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001242 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001243 Expr *Operand) {
1244 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001245 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001246
James Dennett699c9042012-06-15 07:13:21 +00001247 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001248 ///
1249 /// By default, performs semantic analysis to build the new statement.
1250 /// Subclasses may override this routine to provide different behavior.
1251 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1252 Expr *object) {
1253 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1254 }
1255
James Dennett699c9042012-06-15 07:13:21 +00001256 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001257 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001258 /// By default, performs semantic analysis to build the new statement.
1259 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001260 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001261 Expr *Object, Stmt *Body) {
1262 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001263 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001264
James Dennett699c9042012-06-15 07:13:21 +00001265 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001266 ///
1267 /// By default, performs semantic analysis to build the new statement.
1268 /// Subclasses may override this routine to provide different behavior.
1269 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1270 Stmt *Body) {
1271 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1272 }
John McCall990567c2011-07-27 01:07:15 +00001273
Douglas Gregorc3203e72010-04-22 23:10:45 +00001274 /// \brief Build a new Objective-C fast enumeration statement.
1275 ///
1276 /// By default, performs semantic analysis to build the new statement.
1277 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001278 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001279 Stmt *Element,
1280 Expr *Collection,
1281 SourceLocation RParenLoc,
1282 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001283 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001284 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001285 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001286 RParenLoc);
1287 if (ForEachStmt.isInvalid())
1288 return StmtError();
1289
1290 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001291 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001292
Douglas Gregor43959a92009-08-20 07:17:43 +00001293 /// \brief Build a new C++ exception declaration.
1294 ///
1295 /// By default, performs semantic analysis to build the new decaration.
1296 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001297 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001298 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001299 SourceLocation StartLoc,
1300 SourceLocation IdLoc,
1301 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001302 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1303 StartLoc, IdLoc, Id);
1304 if (Var)
1305 getSema().CurContext->addDecl(Var);
1306 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001307 }
1308
1309 /// \brief Build a new C++ catch statement.
1310 ///
1311 /// By default, performs semantic analysis to build the new statement.
1312 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001313 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001314 VarDecl *ExceptionDecl,
1315 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001316 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1317 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001318 }
Mike Stump1eb44332009-09-09 15:08:12 +00001319
Douglas Gregor43959a92009-08-20 07:17:43 +00001320 /// \brief Build a new C++ try statement.
1321 ///
1322 /// By default, performs semantic analysis to build the new statement.
1323 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001324 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001325 Stmt *TryBlock,
1326 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001327 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001328 }
Mike Stump1eb44332009-09-09 15:08:12 +00001329
Richard Smithad762fc2011-04-14 22:09:26 +00001330 /// \brief Build a new C++0x range-based for statement.
1331 ///
1332 /// By default, performs semantic analysis to build the new statement.
1333 /// Subclasses may override this routine to provide different behavior.
1334 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1335 SourceLocation ColonLoc,
1336 Stmt *Range, Stmt *BeginEnd,
1337 Expr *Cond, Expr *Inc,
1338 Stmt *LoopVar,
1339 SourceLocation RParenLoc) {
1340 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1341 Cond, Inc, LoopVar, RParenLoc);
1342 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001343
1344 /// \brief Build a new C++0x range-based for statement.
1345 ///
1346 /// By default, performs semantic analysis to build the new statement.
1347 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001348 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001349 bool IsIfExists,
1350 NestedNameSpecifierLoc QualifierLoc,
1351 DeclarationNameInfo NameInfo,
1352 Stmt *Nested) {
1353 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1354 QualifierLoc, NameInfo, Nested);
1355 }
1356
Richard Smithad762fc2011-04-14 22:09:26 +00001357 /// \brief Attach body to a C++0x range-based for statement.
1358 ///
1359 /// By default, performs semantic analysis to finish the new statement.
1360 /// Subclasses may override this routine to provide different behavior.
1361 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1362 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1363 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001364
John Wiegley28bbe4b2011-04-28 01:08:34 +00001365 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1366 SourceLocation TryLoc,
1367 Stmt *TryBlock,
1368 Stmt *Handler) {
1369 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1370 }
1371
1372 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1373 Expr *FilterExpr,
1374 Stmt *Block) {
1375 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1376 }
1377
1378 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1379 Stmt *Block) {
1380 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1381 }
1382
Douglas Gregorb98b1992009-08-11 05:31:07 +00001383 /// \brief Build a new expression that references a declaration.
1384 ///
1385 /// By default, performs semantic analysis to build the new expression.
1386 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001387 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001388 LookupResult &R,
1389 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001390 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1391 }
1392
1393
1394 /// \brief Build a new expression that references a declaration.
1395 ///
1396 /// By default, performs semantic analysis to build the new expression.
1397 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001398 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001399 ValueDecl *VD,
1400 const DeclarationNameInfo &NameInfo,
1401 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001402 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001403 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001404
1405 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001406
1407 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001408 }
Mike Stump1eb44332009-09-09 15:08:12 +00001409
Douglas Gregorb98b1992009-08-11 05:31:07 +00001410 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001411 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001412 /// By default, performs semantic analysis to build the new expression.
1413 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001414 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001416 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001417 }
1418
Douglas Gregora71d8192009-09-04 17:36:40 +00001419 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001420 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001421 /// By default, performs semantic analysis to build the new expression.
1422 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001423 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001424 SourceLocation OperatorLoc,
1425 bool isArrow,
1426 CXXScopeSpec &SS,
1427 TypeSourceInfo *ScopeType,
1428 SourceLocation CCLoc,
1429 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001430 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001431
Douglas Gregorb98b1992009-08-11 05:31:07 +00001432 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001433 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001434 /// By default, performs semantic analysis to build the new expression.
1435 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001436 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001437 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001438 Expr *SubExpr) {
1439 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001440 }
Mike Stump1eb44332009-09-09 15:08:12 +00001441
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001442 /// \brief Build a new builtin offsetof expression.
1443 ///
1444 /// By default, performs semantic analysis to build the new expression.
1445 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001446 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001447 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001448 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001449 unsigned NumComponents,
1450 SourceLocation RParenLoc) {
1451 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1452 NumComponents, RParenLoc);
1453 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001454
1455 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001456 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001457 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001458 /// By default, performs semantic analysis to build the new expression.
1459 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001460 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1461 SourceLocation OpLoc,
1462 UnaryExprOrTypeTrait ExprKind,
1463 SourceRange R) {
1464 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001465 }
1466
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001467 /// \brief Build a new sizeof, alignof or vec step expression with an
1468 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001469 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001470 /// By default, performs semantic analysis to build the new expression.
1471 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001472 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1473 UnaryExprOrTypeTrait ExprKind,
1474 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001475 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001476 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001477 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001478 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001479
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 return move(Result);
1481 }
Mike Stump1eb44332009-09-09 15:08:12 +00001482
Douglas Gregorb98b1992009-08-11 05:31:07 +00001483 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001484 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001485 /// By default, performs semantic analysis to build the new expression.
1486 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001487 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001488 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001489 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001491 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1492 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 RBracketLoc);
1494 }
1495
1496 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001497 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 /// By default, performs semantic analysis to build the new expression.
1499 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001500 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001501 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001502 SourceLocation RParenLoc,
1503 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001504 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001505 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001506 }
1507
1508 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001509 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001510 /// By default, performs semantic analysis to build the new expression.
1511 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001512 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001513 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001514 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001515 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001516 const DeclarationNameInfo &MemberNameInfo,
1517 ValueDecl *Member,
1518 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001519 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001520 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001521 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1522 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001523 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001524 // We have a reference to an unnamed field. This is always the
1525 // base of an anonymous struct/union member access, i.e. the
1526 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001527 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001528 assert(Member->getType()->isRecordType() &&
1529 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001530
Richard Smith9138b4e2011-10-26 19:06:56 +00001531 BaseResult =
1532 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001533 QualifierLoc.getNestedNameSpecifier(),
1534 FoundDecl, Member);
1535 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001536 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001537 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001538 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001539 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001540 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001541 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001542 cast<FieldDecl>(Member)->getType(),
1543 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001544 return getSema().Owned(ME);
1545 }
Mike Stump1eb44332009-09-09 15:08:12 +00001546
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001547 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001548 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001549
John Wiegley429bb272011-04-08 18:41:53 +00001550 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001551 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001552
John McCall6bb80172010-03-30 21:47:33 +00001553 // FIXME: this involves duplicating earlier analysis in a lot of
1554 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001555 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001556 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001557 R.resolveKind();
1558
John McCall9ae2f072010-08-23 23:25:46 +00001559 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001560 SS, TemplateKWLoc,
1561 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001562 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001563 }
Mike Stump1eb44332009-09-09 15:08:12 +00001564
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001566 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 /// By default, performs semantic analysis to build the new expression.
1568 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001569 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001570 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001571 Expr *LHS, Expr *RHS) {
1572 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001573 }
1574
1575 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001576 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001577 /// By default, performs semantic analysis to build the new expression.
1578 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001579 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001580 SourceLocation QuestionLoc,
1581 Expr *LHS,
1582 SourceLocation ColonLoc,
1583 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001584 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1585 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 }
1587
Douglas Gregorb98b1992009-08-11 05:31:07 +00001588 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001589 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 /// By default, performs semantic analysis to build the new expression.
1591 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001592 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001593 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001595 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001596 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001597 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001598 }
Mike Stump1eb44332009-09-09 15:08:12 +00001599
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001601 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 /// By default, performs semantic analysis to build the new expression.
1603 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001604 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001605 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001606 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001607 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001608 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001609 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001610 }
Mike Stump1eb44332009-09-09 15:08:12 +00001611
Douglas Gregorb98b1992009-08-11 05:31:07 +00001612 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001613 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 /// By default, performs semantic analysis to build the new expression.
1615 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001616 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001617 SourceLocation OpLoc,
1618 SourceLocation AccessorLoc,
1619 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001620
John McCall129e2df2009-11-30 22:42:35 +00001621 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001622 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001623 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001624 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001625 SS, SourceLocation(),
1626 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001627 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001628 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001629 }
Mike Stump1eb44332009-09-09 15:08:12 +00001630
Douglas Gregorb98b1992009-08-11 05:31:07 +00001631 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001632 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001633 /// By default, performs semantic analysis to build the new expression.
1634 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001635 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001636 MultiExprArg Inits,
1637 SourceLocation RBraceLoc,
1638 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001639 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001640 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1641 if (Result.isInvalid() || ResultTy->isDependentType())
1642 return move(Result);
Chad Rosier4a9d7952012-08-08 18:46:20 +00001643
Douglas Gregore48319a2009-11-09 17:16:50 +00001644 // Patch in the result type we were given, which may have been computed
1645 // when the initial InitListExpr was built.
1646 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1647 ILE->setType(ResultTy);
1648 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001649 }
Mike Stump1eb44332009-09-09 15:08:12 +00001650
Douglas Gregorb98b1992009-08-11 05:31:07 +00001651 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001652 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 /// By default, performs semantic analysis to build the new expression.
1654 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001655 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001656 MultiExprArg ArrayExprs,
1657 SourceLocation EqualOrColonLoc,
1658 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001659 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001660 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001662 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001664 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001665
Douglas Gregorb98b1992009-08-11 05:31:07 +00001666 ArrayExprs.release();
1667 return move(Result);
1668 }
Mike Stump1eb44332009-09-09 15:08:12 +00001669
Douglas Gregorb98b1992009-08-11 05:31:07 +00001670 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001671 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001672 /// By default, builds the implicit value initialization without performing
1673 /// any semantic analysis. Subclasses may override this routine to provide
1674 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001675 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001676 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1677 }
Mike Stump1eb44332009-09-09 15:08:12 +00001678
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001680 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001681 /// By default, performs semantic analysis to build the new expression.
1682 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001683 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001684 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001685 SourceLocation RParenLoc) {
1686 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001687 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001688 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001689 }
1690
1691 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001692 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001693 /// By default, performs semantic analysis to build the new expression.
1694 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001695 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001696 MultiExprArg SubExprs,
1697 SourceLocation RParenLoc) {
1698 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001699 }
Mike Stump1eb44332009-09-09 15:08:12 +00001700
Douglas Gregorb98b1992009-08-11 05:31:07 +00001701 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001702 ///
1703 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 /// rather than attempting to map the label statement itself.
1705 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001706 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001707 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001708 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001709 }
Mike Stump1eb44332009-09-09 15:08:12 +00001710
Douglas Gregorb98b1992009-08-11 05:31:07 +00001711 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001712 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 /// By default, performs semantic analysis to build the new expression.
1714 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001715 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001716 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001718 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001719 }
Mike Stump1eb44332009-09-09 15:08:12 +00001720
Douglas Gregorb98b1992009-08-11 05:31:07 +00001721 /// \brief Build a new __builtin_choose_expr expression.
1722 ///
1723 /// By default, performs semantic analysis to build the new expression.
1724 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001725 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001726 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001727 SourceLocation RParenLoc) {
1728 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001729 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001730 RParenLoc);
1731 }
Mike Stump1eb44332009-09-09 15:08:12 +00001732
Peter Collingbournef111d932011-04-15 00:35:48 +00001733 /// \brief Build a new generic selection expression.
1734 ///
1735 /// By default, performs semantic analysis to build the new expression.
1736 /// Subclasses may override this routine to provide different behavior.
1737 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1738 SourceLocation DefaultLoc,
1739 SourceLocation RParenLoc,
1740 Expr *ControllingExpr,
1741 TypeSourceInfo **Types,
1742 Expr **Exprs,
1743 unsigned NumAssocs) {
1744 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1745 ControllingExpr, Types, Exprs,
1746 NumAssocs);
1747 }
1748
Douglas Gregorb98b1992009-08-11 05:31:07 +00001749 /// \brief Build a new overloaded operator call expression.
1750 ///
1751 /// By default, performs semantic analysis to build the new expression.
1752 /// The semantic analysis provides the behavior of template instantiation,
1753 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001754 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 /// argument-dependent lookup, etc. Subclasses may override this routine to
1756 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001757 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001758 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001759 Expr *Callee,
1760 Expr *First,
1761 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001762
1763 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001764 /// reinterpret_cast.
1765 ///
1766 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001767 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001768 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001769 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001770 Stmt::StmtClass Class,
1771 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001772 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001773 SourceLocation RAngleLoc,
1774 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001775 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001776 SourceLocation RParenLoc) {
1777 switch (Class) {
1778 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001779 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001780 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001781 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001782
1783 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001784 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001785 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001786 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001787
Douglas Gregorb98b1992009-08-11 05:31:07 +00001788 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001789 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001790 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001791 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001792 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001793
Douglas Gregorb98b1992009-08-11 05:31:07 +00001794 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001795 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001796 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001797 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001798
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001800 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001802 }
Mike Stump1eb44332009-09-09 15:08:12 +00001803
Douglas Gregorb98b1992009-08-11 05:31:07 +00001804 /// \brief Build a new C++ static_cast expression.
1805 ///
1806 /// By default, performs semantic analysis to build the new expression.
1807 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001808 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001810 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 SourceLocation RAngleLoc,
1812 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001813 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001814 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001815 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001816 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001817 SourceRange(LAngleLoc, RAngleLoc),
1818 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001819 }
1820
1821 /// \brief Build a new C++ dynamic_cast expression.
1822 ///
1823 /// By default, performs semantic analysis to build the new expression.
1824 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001825 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001826 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001827 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001828 SourceLocation RAngleLoc,
1829 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001830 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001831 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001832 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001833 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001834 SourceRange(LAngleLoc, RAngleLoc),
1835 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001836 }
1837
1838 /// \brief Build a new C++ reinterpret_cast expression.
1839 ///
1840 /// By default, performs semantic analysis to build the new expression.
1841 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001842 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001843 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001844 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001845 SourceLocation RAngleLoc,
1846 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001847 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001848 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001849 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001850 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001851 SourceRange(LAngleLoc, RAngleLoc),
1852 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001853 }
1854
1855 /// \brief Build a new C++ const_cast expression.
1856 ///
1857 /// By default, performs semantic analysis to build the new expression.
1858 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001859 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001860 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001861 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001862 SourceLocation RAngleLoc,
1863 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001864 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001865 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001866 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001867 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001868 SourceRange(LAngleLoc, RAngleLoc),
1869 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001870 }
Mike Stump1eb44332009-09-09 15:08:12 +00001871
Douglas Gregorb98b1992009-08-11 05:31:07 +00001872 /// \brief Build a new C++ functional-style cast expression.
1873 ///
1874 /// By default, performs semantic analysis to build the new expression.
1875 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001876 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1877 SourceLocation LParenLoc,
1878 Expr *Sub,
1879 SourceLocation RParenLoc) {
1880 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001881 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001882 RParenLoc);
1883 }
Mike Stump1eb44332009-09-09 15:08:12 +00001884
Douglas Gregorb98b1992009-08-11 05:31:07 +00001885 /// \brief Build a new C++ typeid(type) expression.
1886 ///
1887 /// By default, performs semantic analysis to build the new expression.
1888 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001889 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001890 SourceLocation TypeidLoc,
1891 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001892 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001893 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001894 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001895 }
Mike Stump1eb44332009-09-09 15:08:12 +00001896
Francois Pichet01b7c302010-09-08 12:20:18 +00001897
Douglas Gregorb98b1992009-08-11 05:31:07 +00001898 /// \brief Build a new C++ typeid(expr) expression.
1899 ///
1900 /// By default, performs semantic analysis to build the new expression.
1901 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001902 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001903 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001904 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001905 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001906 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001907 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001908 }
1909
Francois Pichet01b7c302010-09-08 12:20:18 +00001910 /// \brief Build a new C++ __uuidof(type) expression.
1911 ///
1912 /// By default, performs semantic analysis to build the new expression.
1913 /// Subclasses may override this routine to provide different behavior.
1914 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1915 SourceLocation TypeidLoc,
1916 TypeSourceInfo *Operand,
1917 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001918 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001919 RParenLoc);
1920 }
1921
1922 /// \brief Build a new C++ __uuidof(expr) expression.
1923 ///
1924 /// By default, performs semantic analysis to build the new expression.
1925 /// Subclasses may override this routine to provide different behavior.
1926 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1927 SourceLocation TypeidLoc,
1928 Expr *Operand,
1929 SourceLocation RParenLoc) {
1930 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1931 RParenLoc);
1932 }
1933
Douglas Gregorb98b1992009-08-11 05:31:07 +00001934 /// \brief Build a new C++ "this" expression.
1935 ///
1936 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001937 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001938 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001939 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001940 QualType ThisType,
1941 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001942 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001943 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001944 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1945 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001946 }
1947
1948 /// \brief Build a new C++ throw expression.
1949 ///
1950 /// By default, performs semantic analysis to build the new expression.
1951 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001952 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1953 bool IsThrownVariableInScope) {
1954 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001955 }
1956
1957 /// \brief Build a new C++ default-argument expression.
1958 ///
1959 /// By default, builds a new default-argument expression, which does not
1960 /// require any semantic analysis. Subclasses may override this routine to
1961 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001962 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001963 ParmVarDecl *Param) {
1964 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1965 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001966 }
1967
1968 /// \brief Build a new C++ zero-initialization expression.
1969 ///
1970 /// By default, performs semantic analysis to build the new expression.
1971 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001972 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1973 SourceLocation LParenLoc,
1974 SourceLocation RParenLoc) {
1975 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001976 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001977 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001978 }
Mike Stump1eb44332009-09-09 15:08:12 +00001979
Douglas Gregorb98b1992009-08-11 05:31:07 +00001980 /// \brief Build a new C++ "new" expression.
1981 ///
1982 /// By default, performs semantic analysis to build the new expression.
1983 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001984 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001985 bool UseGlobal,
1986 SourceLocation PlacementLParen,
1987 MultiExprArg PlacementArgs,
1988 SourceLocation PlacementRParen,
1989 SourceRange TypeIdParens,
1990 QualType AllocatedType,
1991 TypeSourceInfo *AllocatedTypeInfo,
1992 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001993 SourceRange DirectInitRange,
1994 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001995 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001996 PlacementLParen,
1997 move(PlacementArgs),
1998 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001999 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002000 AllocatedType,
2001 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002002 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002003 DirectInitRange,
2004 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002005 }
Mike Stump1eb44332009-09-09 15:08:12 +00002006
Douglas Gregorb98b1992009-08-11 05:31:07 +00002007 /// \brief Build a new C++ "delete" expression.
2008 ///
2009 /// By default, performs semantic analysis to build the new expression.
2010 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002011 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002012 bool IsGlobalDelete,
2013 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002014 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002015 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002016 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002017 }
Mike Stump1eb44332009-09-09 15:08:12 +00002018
Douglas Gregorb98b1992009-08-11 05:31:07 +00002019 /// \brief Build a new unary type trait expression.
2020 ///
2021 /// By default, performs semantic analysis to build the new expression.
2022 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002023 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002024 SourceLocation StartLoc,
2025 TypeSourceInfo *T,
2026 SourceLocation RParenLoc) {
2027 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002028 }
2029
Francois Pichet6ad6f282010-12-07 00:08:36 +00002030 /// \brief Build a new binary type trait expression.
2031 ///
2032 /// By default, performs semantic analysis to build the new expression.
2033 /// Subclasses may override this routine to provide different behavior.
2034 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2035 SourceLocation StartLoc,
2036 TypeSourceInfo *LhsT,
2037 TypeSourceInfo *RhsT,
2038 SourceLocation RParenLoc) {
2039 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2040 }
2041
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002042 /// \brief Build a new type trait expression.
2043 ///
2044 /// By default, performs semantic analysis to build the new expression.
2045 /// Subclasses may override this routine to provide different behavior.
2046 ExprResult RebuildTypeTrait(TypeTrait Trait,
2047 SourceLocation StartLoc,
2048 ArrayRef<TypeSourceInfo *> Args,
2049 SourceLocation RParenLoc) {
2050 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2051 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002052
John Wiegley21ff2e52011-04-28 00:16:57 +00002053 /// \brief Build a new array type trait expression.
2054 ///
2055 /// By default, performs semantic analysis to build the new expression.
2056 /// Subclasses may override this routine to provide different behavior.
2057 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2058 SourceLocation StartLoc,
2059 TypeSourceInfo *TSInfo,
2060 Expr *DimExpr,
2061 SourceLocation RParenLoc) {
2062 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2063 }
2064
John Wiegley55262202011-04-25 06:54:41 +00002065 /// \brief Build a new expression trait expression.
2066 ///
2067 /// By default, performs semantic analysis to build the new expression.
2068 /// Subclasses may override this routine to provide different behavior.
2069 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2070 SourceLocation StartLoc,
2071 Expr *Queried,
2072 SourceLocation RParenLoc) {
2073 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2074 }
2075
Mike Stump1eb44332009-09-09 15:08:12 +00002076 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002077 /// expression.
2078 ///
2079 /// By default, performs semantic analysis to build the new expression.
2080 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002081 ExprResult RebuildDependentScopeDeclRefExpr(
2082 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002083 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002084 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002085 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002086 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002087 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002088
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002089 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002090 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002091 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002092
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002093 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002094 }
2095
2096 /// \brief Build a new template-id expression.
2097 ///
2098 /// By default, performs semantic analysis to build the new expression.
2099 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002100 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002101 SourceLocation TemplateKWLoc,
2102 LookupResult &R,
2103 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002104 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002105 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2106 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002107 }
2108
2109 /// \brief Build a new object-construction expression.
2110 ///
2111 /// By default, performs semantic analysis to build the new expression.
2112 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002113 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002114 SourceLocation Loc,
2115 CXXConstructorDecl *Constructor,
2116 bool IsElidable,
2117 MultiExprArg Args,
2118 bool HadMultipleCandidates,
2119 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002120 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002121 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002122 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002123 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002124 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002125 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002126
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002127 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002128 move_arg(ConvertedArgs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002129 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002130 RequiresZeroInit, ConstructKind,
2131 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002132 }
2133
2134 /// \brief Build a new object-construction expression.
2135 ///
2136 /// By default, performs semantic analysis to build the new expression.
2137 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002138 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2139 SourceLocation LParenLoc,
2140 MultiExprArg Args,
2141 SourceLocation RParenLoc) {
2142 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002143 LParenLoc,
2144 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002145 RParenLoc);
2146 }
2147
2148 /// \brief Build a new object-construction expression.
2149 ///
2150 /// By default, performs semantic analysis to build the new expression.
2151 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002152 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2153 SourceLocation LParenLoc,
2154 MultiExprArg Args,
2155 SourceLocation RParenLoc) {
2156 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002157 LParenLoc,
2158 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002159 RParenLoc);
2160 }
Mike Stump1eb44332009-09-09 15:08:12 +00002161
Douglas Gregorb98b1992009-08-11 05:31:07 +00002162 /// \brief Build a new member reference expression.
2163 ///
2164 /// By default, performs semantic analysis to build the new expression.
2165 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002166 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002167 QualType BaseType,
2168 bool IsArrow,
2169 SourceLocation OperatorLoc,
2170 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002171 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002172 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002173 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002174 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002175 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002176 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002177
John McCall9ae2f072010-08-23 23:25:46 +00002178 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002179 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002180 SS, TemplateKWLoc,
2181 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002182 MemberNameInfo,
2183 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002184 }
2185
John McCall129e2df2009-11-30 22:42:35 +00002186 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002187 ///
2188 /// By default, performs semantic analysis to build the new expression.
2189 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002190 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2191 SourceLocation OperatorLoc,
2192 bool IsArrow,
2193 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002194 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002195 NamedDecl *FirstQualifierInScope,
2196 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002197 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002198 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002199 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002200
John McCall9ae2f072010-08-23 23:25:46 +00002201 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002202 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002203 SS, TemplateKWLoc,
2204 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002205 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002206 }
Mike Stump1eb44332009-09-09 15:08:12 +00002207
Sebastian Redl2e156222010-09-10 20:55:43 +00002208 /// \brief Build a new noexcept expression.
2209 ///
2210 /// By default, performs semantic analysis to build the new expression.
2211 /// Subclasses may override this routine to provide different behavior.
2212 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2213 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2214 }
2215
Douglas Gregoree8aff02011-01-04 17:33:58 +00002216 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002217 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2218 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002219 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002220 llvm::Optional<unsigned> Length) {
2221 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002222 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2223 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002224 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002225
2226 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2227 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002228 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002229 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002230
Patrick Beardeb382ec2012-04-19 00:25:12 +00002231 /// \brief Build a new Objective-C boxed expression.
2232 ///
2233 /// By default, performs semantic analysis to build the new expression.
2234 /// Subclasses may override this routine to provide different behavior.
2235 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2236 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2237 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002238
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002239 /// \brief Build a new Objective-C array literal.
2240 ///
2241 /// By default, performs semantic analysis to build the new expression.
2242 /// Subclasses may override this routine to provide different behavior.
2243 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2244 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002245 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002246 MultiExprArg(Elements, NumElements));
2247 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002248
2249 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002250 Expr *Base, Expr *Key,
2251 ObjCMethodDecl *getterMethod,
2252 ObjCMethodDecl *setterMethod) {
2253 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2254 getterMethod, setterMethod);
2255 }
2256
2257 /// \brief Build a new Objective-C dictionary literal.
2258 ///
2259 /// By default, performs semantic analysis to build the new expression.
2260 /// Subclasses may override this routine to provide different behavior.
2261 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2262 ObjCDictionaryElement *Elements,
2263 unsigned NumElements) {
2264 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2265 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002266
James Dennett699c9042012-06-15 07:13:21 +00002267 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002268 ///
2269 /// By default, performs semantic analysis to build the new expression.
2270 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002271 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002272 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002273 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002274 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002275 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002276 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002277
Douglas Gregor92e986e2010-04-22 16:44:27 +00002278 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002279 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002280 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002281 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002282 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002283 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002284 MultiExprArg Args,
2285 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002286 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2287 ReceiverTypeInfo->getType(),
2288 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002289 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002290 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002291 }
2292
2293 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002294 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002295 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002296 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002297 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002298 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002299 MultiExprArg Args,
2300 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002301 return SemaRef.BuildInstanceMessage(Receiver,
2302 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002303 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002304 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002305 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002306 }
2307
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002308 /// \brief Build a new Objective-C ivar reference expression.
2309 ///
2310 /// By default, performs semantic analysis to build the new expression.
2311 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002312 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002313 SourceLocation IvarLoc,
2314 bool IsArrow, bool IsFreeIvar) {
2315 // FIXME: We lose track of the IsFreeIvar bit.
2316 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002317 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002318 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2319 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002320 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002321 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002322 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002323 false);
John Wiegley429bb272011-04-08 18:41:53 +00002324 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002325 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002326
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002327 if (Result.get())
2328 return move(Result);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002329
John Wiegley429bb272011-04-08 18:41:53 +00002330 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002331 /*FIXME:*/IvarLoc, IsArrow,
2332 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002333 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002334 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002335 /*TemplateArgs=*/0);
2336 }
Douglas Gregore3303542010-04-26 20:47:02 +00002337
2338 /// \brief Build a new Objective-C property reference expression.
2339 ///
2340 /// By default, performs semantic analysis to build the new expression.
2341 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002342 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002343 ObjCPropertyDecl *Property,
2344 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002345 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002346 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002347 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2348 Sema::LookupMemberName);
2349 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002350 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002351 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002352 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002353 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002354 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002355
Douglas Gregore3303542010-04-26 20:47:02 +00002356 if (Result.get())
2357 return move(Result);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002358
John Wiegley429bb272011-04-08 18:41:53 +00002359 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002360 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002361 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002362 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002363 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002364 /*TemplateArgs=*/0);
2365 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002366
John McCall12f78a62010-12-02 01:19:52 +00002367 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002368 ///
2369 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002370 /// Subclasses may override this routine to provide different behavior.
2371 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2372 ObjCMethodDecl *Getter,
2373 ObjCMethodDecl *Setter,
2374 SourceLocation PropertyLoc) {
2375 // Since these expressions can only be value-dependent, we do not
2376 // need to perform semantic analysis again.
2377 return Owned(
2378 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2379 VK_LValue, OK_ObjCProperty,
2380 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002381 }
2382
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002383 /// \brief Build a new Objective-C "isa" expression.
2384 ///
2385 /// By default, performs semantic analysis to build the new expression.
2386 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002387 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002388 bool IsArrow) {
2389 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002390 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002391 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2392 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002393 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002394 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002395 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002396 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002397 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002398
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002399 if (Result.get())
2400 return move(Result);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002401
John Wiegley429bb272011-04-08 18:41:53 +00002402 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002403 /*FIXME:*/IsaLoc, IsArrow,
2404 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002405 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002406 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002407 /*TemplateArgs=*/0);
2408 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002409
Douglas Gregorb98b1992009-08-11 05:31:07 +00002410 /// \brief Build a new shuffle vector expression.
2411 ///
2412 /// By default, performs semantic analysis to build the new expression.
2413 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002414 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002415 MultiExprArg SubExprs,
2416 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002417 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002418 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002419 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2420 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2421 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2422 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002423
Douglas Gregorb98b1992009-08-11 05:31:07 +00002424 // Build a reference to the __builtin_shufflevector builtin
2425 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002426 ExprResult Callee
John McCallf4b88a42012-03-10 09:33:50 +00002427 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false,
2428 Builtin->getType(),
John Wiegley429bb272011-04-08 18:41:53 +00002429 VK_LValue, BuiltinLoc));
2430 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2431 if (Callee.isInvalid())
2432 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002433
2434 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002435 unsigned NumSubExprs = SubExprs.size();
2436 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002437 ExprResult TheCall = SemaRef.Owned(
2438 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002439 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002440 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002441 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002442 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002443
Douglas Gregorb98b1992009-08-11 05:31:07 +00002444 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002445 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002446 }
John McCall43fed0d2010-11-12 08:19:04 +00002447
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002448 /// \brief Build a new template argument pack expansion.
2449 ///
2450 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002451 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002452 /// different behavior.
2453 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002454 SourceLocation EllipsisLoc,
2455 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002456 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002457 case TemplateArgument::Expression: {
2458 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002459 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2460 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002461 if (Result.isInvalid())
2462 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002463
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002464 return TemplateArgumentLoc(Result.get(), Result.get());
2465 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002466
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002467 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002468 return TemplateArgumentLoc(TemplateArgument(
2469 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002470 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002471 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002472 Pattern.getTemplateNameLoc(),
2473 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002474
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002475 case TemplateArgument::Null:
2476 case TemplateArgument::Integral:
2477 case TemplateArgument::Declaration:
2478 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002479 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002480 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002481
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002482 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002483 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002484 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002485 EllipsisLoc,
2486 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002487 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2488 Expansion);
2489 break;
2490 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002491
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002492 return TemplateArgumentLoc();
2493 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002494
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002495 /// \brief Build a new expression pack expansion.
2496 ///
2497 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002498 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002499 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002500 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2501 llvm::Optional<unsigned> NumExpansions) {
2502 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002503 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002504
2505 /// \brief Build a new atomic operation expression.
2506 ///
2507 /// By default, performs semantic analysis to build the new expression.
2508 /// Subclasses may override this routine to provide different behavior.
2509 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2510 MultiExprArg SubExprs,
2511 QualType RetTy,
2512 AtomicExpr::AtomicOp Op,
2513 SourceLocation RParenLoc) {
2514 // Just create the expression; there is not any interesting semantic
2515 // analysis here because we can't actually build an AtomicExpr until
2516 // we are sure it is semantically sound.
2517 unsigned NumSubExprs = SubExprs.size();
2518 Expr **Subs = (Expr **)SubExprs.release();
2519 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2520 NumSubExprs, RetTy, Op,
2521 RParenLoc);
2522 }
2523
John McCall43fed0d2010-11-12 08:19:04 +00002524private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002525 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2526 QualType ObjectType,
2527 NamedDecl *FirstQualifierInScope,
2528 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002529
2530 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2531 QualType ObjectType,
2532 NamedDecl *FirstQualifierInScope,
2533 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002534};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002535
Douglas Gregor43959a92009-08-20 07:17:43 +00002536template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002537StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002538 if (!S)
2539 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002540
Douglas Gregor43959a92009-08-20 07:17:43 +00002541 switch (S->getStmtClass()) {
2542 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002543
Douglas Gregor43959a92009-08-20 07:17:43 +00002544 // Transform individual statement nodes
2545#define STMT(Node, Parent) \
2546 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002547#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002548#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002549#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002550
Douglas Gregor43959a92009-08-20 07:17:43 +00002551 // Transform expressions by calling TransformExpr.
2552#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002553#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002554#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002555#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002556 {
John McCall60d7b3a2010-08-24 06:29:42 +00002557 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002558 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002559 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002560
John McCall9ae2f072010-08-23 23:25:46 +00002561 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002562 }
Mike Stump1eb44332009-09-09 15:08:12 +00002563 }
2564
John McCall3fa5cae2010-10-26 07:05:15 +00002565 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002566}
Mike Stump1eb44332009-09-09 15:08:12 +00002567
2568
Douglas Gregor670444e2009-08-04 22:27:00 +00002569template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002570ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002571 if (!E)
2572 return SemaRef.Owned(E);
2573
2574 switch (E->getStmtClass()) {
2575 case Stmt::NoStmtClass: break;
2576#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002577#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002578#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002579 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002580#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002581 }
2582
John McCall3fa5cae2010-10-26 07:05:15 +00002583 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002584}
2585
2586template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002587bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2588 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002589 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002590 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002591 bool *ArgChanged) {
2592 for (unsigned I = 0; I != NumInputs; ++I) {
2593 // If requested, drop call arguments that need to be dropped.
2594 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2595 if (ArgChanged)
2596 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002597
Douglas Gregoraa165f82011-01-03 19:04:46 +00002598 break;
2599 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002600
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002601 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2602 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002603
Chris Lattner686775d2011-07-20 06:58:45 +00002604 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002605 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2606 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002607
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002608 // Determine whether the set of unexpanded parameter packs can and should
2609 // be expanded.
2610 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002611 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002612 llvm::Optional<unsigned> OrigNumExpansions
2613 = Expansion->getNumExpansions();
2614 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002615 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2616 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002617 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002618 Expand, RetainExpansion,
2619 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002620 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002621
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002622 if (!Expand) {
2623 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002624 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002625 // expansion.
2626 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2627 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2628 if (OutPattern.isInvalid())
2629 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002630
2631 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002632 Expansion->getEllipsisLoc(),
2633 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002634 if (Out.isInvalid())
2635 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002636
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002637 if (ArgChanged)
2638 *ArgChanged = true;
2639 Outputs.push_back(Out.get());
2640 continue;
2641 }
John McCallc8fc90a2011-07-06 07:30:07 +00002642
2643 // Record right away that the argument was changed. This needs
2644 // to happen even if the array expands to nothing.
2645 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002646
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002647 // The transform has determined that we should perform an elementwise
2648 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002649 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002650 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2651 ExprResult Out = getDerived().TransformExpr(Pattern);
2652 if (Out.isInvalid())
2653 return true;
2654
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002655 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002656 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2657 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002658 if (Out.isInvalid())
2659 return true;
2660 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002661
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002662 Outputs.push_back(Out.get());
2663 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002664
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002665 continue;
2666 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002667
Douglas Gregoraa165f82011-01-03 19:04:46 +00002668 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2669 if (Result.isInvalid())
2670 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002671
Douglas Gregoraa165f82011-01-03 19:04:46 +00002672 if (Result.get() != Inputs[I] && ArgChanged)
2673 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002674
2675 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002676 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002677
Douglas Gregoraa165f82011-01-03 19:04:46 +00002678 return false;
2679}
2680
2681template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002682NestedNameSpecifierLoc
2683TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2684 NestedNameSpecifierLoc NNS,
2685 QualType ObjectType,
2686 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002687 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002688 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002689 Qualifier = Qualifier.getPrefix())
2690 Qualifiers.push_back(Qualifier);
2691
2692 CXXScopeSpec SS;
2693 while (!Qualifiers.empty()) {
2694 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2695 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002696
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002697 switch (QNNS->getKind()) {
2698 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002699 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002700 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002701 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002702 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002703 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002704 FirstQualifierInScope, false))
2705 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002706
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002707 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002708
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002709 case NestedNameSpecifier::Namespace: {
2710 NamespaceDecl *NS
2711 = cast_or_null<NamespaceDecl>(
2712 getDerived().TransformDecl(
2713 Q.getLocalBeginLoc(),
2714 QNNS->getAsNamespace()));
2715 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2716 break;
2717 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002718
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002719 case NestedNameSpecifier::NamespaceAlias: {
2720 NamespaceAliasDecl *Alias
2721 = cast_or_null<NamespaceAliasDecl>(
2722 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2723 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002724 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002725 Q.getLocalEndLoc());
2726 break;
2727 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002728
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002729 case NestedNameSpecifier::Global:
2730 // There is no meaningful transformation that one could perform on the
2731 // global scope.
2732 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2733 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002734
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002735 case NestedNameSpecifier::TypeSpecWithTemplate:
2736 case NestedNameSpecifier::TypeSpec: {
2737 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2738 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002739
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002740 if (!TL)
2741 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002742
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002743 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00002744 (SemaRef.getLangOpts().CPlusPlus0x &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002745 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002746 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002747 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002748 if (TL.getType()->isEnumeralType())
2749 SemaRef.Diag(TL.getBeginLoc(),
2750 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002751 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2752 Q.getLocalEndLoc());
2753 break;
2754 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002755 // If the nested-name-specifier is an invalid type def, don't emit an
2756 // error because a previous error should have already been emitted.
2757 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2758 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002759 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002760 << TL.getType() << SS.getRange();
2761 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002762 return NestedNameSpecifierLoc();
2763 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002764 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002765
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002766 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002767 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002768 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002769 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002770
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002771 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002772 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002773 !getDerived().AlwaysRebuild())
2774 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002775
2776 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002777 // nested-name-specifier, do so.
2778 if (SS.location_size() == NNS.getDataLength() &&
2779 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2780 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2781
2782 // Allocate new nested-name-specifier location information.
2783 return SS.getWithLocInContext(SemaRef.Context);
2784}
2785
2786template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002787DeclarationNameInfo
2788TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002789::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002790 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002791 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002792 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002793
2794 switch (Name.getNameKind()) {
2795 case DeclarationName::Identifier:
2796 case DeclarationName::ObjCZeroArgSelector:
2797 case DeclarationName::ObjCOneArgSelector:
2798 case DeclarationName::ObjCMultiArgSelector:
2799 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002800 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002801 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002802 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002803
Douglas Gregor81499bb2009-09-03 22:13:48 +00002804 case DeclarationName::CXXConstructorName:
2805 case DeclarationName::CXXDestructorName:
2806 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002807 TypeSourceInfo *NewTInfo;
2808 CanQualType NewCanTy;
2809 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002810 NewTInfo = getDerived().TransformType(OldTInfo);
2811 if (!NewTInfo)
2812 return DeclarationNameInfo();
2813 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002814 }
2815 else {
2816 NewTInfo = 0;
2817 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002818 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002819 if (NewT.isNull())
2820 return DeclarationNameInfo();
2821 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2822 }
Mike Stump1eb44332009-09-09 15:08:12 +00002823
Abramo Bagnara25777432010-08-11 22:01:17 +00002824 DeclarationName NewName
2825 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2826 NewCanTy);
2827 DeclarationNameInfo NewNameInfo(NameInfo);
2828 NewNameInfo.setName(NewName);
2829 NewNameInfo.setNamedTypeInfo(NewTInfo);
2830 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002831 }
Mike Stump1eb44332009-09-09 15:08:12 +00002832 }
2833
David Blaikieb219cfc2011-09-23 05:06:16 +00002834 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002835}
2836
2837template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002838TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002839TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2840 TemplateName Name,
2841 SourceLocation NameLoc,
2842 QualType ObjectType,
2843 NamedDecl *FirstQualifierInScope) {
2844 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2845 TemplateDecl *Template = QTN->getTemplateDecl();
2846 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002847
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002848 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002849 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002850 Template));
2851 if (!TransTemplate)
2852 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002853
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002854 if (!getDerived().AlwaysRebuild() &&
2855 SS.getScopeRep() == QTN->getQualifier() &&
2856 TransTemplate == Template)
2857 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002858
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002859 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2860 TransTemplate);
2861 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002862
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002863 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2864 if (SS.getScopeRep()) {
2865 // These apply to the scope specifier, not the template.
2866 ObjectType = QualType();
2867 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002868 }
2869
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002870 if (!getDerived().AlwaysRebuild() &&
2871 SS.getScopeRep() == DTN->getQualifier() &&
2872 ObjectType.isNull())
2873 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002874
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002875 if (DTN->isIdentifier()) {
2876 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002877 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002878 NameLoc,
2879 ObjectType,
2880 FirstQualifierInScope);
2881 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002882
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002883 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2884 ObjectType);
2885 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002886
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002887 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2888 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002889 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002890 Template));
2891 if (!TransTemplate)
2892 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002893
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002894 if (!getDerived().AlwaysRebuild() &&
2895 TransTemplate == Template)
2896 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002897
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002898 return TemplateName(TransTemplate);
2899 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002900
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002901 if (SubstTemplateTemplateParmPackStorage *SubstPack
2902 = Name.getAsSubstTemplateTemplateParmPack()) {
2903 TemplateTemplateParmDecl *TransParam
2904 = cast_or_null<TemplateTemplateParmDecl>(
2905 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2906 if (!TransParam)
2907 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002908
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002909 if (!getDerived().AlwaysRebuild() &&
2910 TransParam == SubstPack->getParameterPack())
2911 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002912
2913 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002914 SubstPack->getArgumentPack());
2915 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002916
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002917 // These should be getting filtered out before they reach the AST.
2918 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002919}
2920
2921template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002922void TreeTransform<Derived>::InventTemplateArgumentLoc(
2923 const TemplateArgument &Arg,
2924 TemplateArgumentLoc &Output) {
2925 SourceLocation Loc = getDerived().getBaseLocation();
2926 switch (Arg.getKind()) {
2927 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002928 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002929 break;
2930
2931 case TemplateArgument::Type:
2932 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002933 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002934
John McCall833ca992009-10-29 08:12:44 +00002935 break;
2936
Douglas Gregor788cd062009-11-11 01:00:40 +00002937 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002938 case TemplateArgument::TemplateExpansion: {
2939 NestedNameSpecifierLocBuilder Builder;
2940 TemplateName Template = Arg.getAsTemplate();
2941 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2942 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2943 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2944 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002945
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002946 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002947 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002948 Builder.getWithLocInContext(SemaRef.Context),
2949 Loc);
2950 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00002951 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002952 Builder.getWithLocInContext(SemaRef.Context),
2953 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002954
Douglas Gregor788cd062009-11-11 01:00:40 +00002955 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002956 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002957
John McCall833ca992009-10-29 08:12:44 +00002958 case TemplateArgument::Expression:
2959 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2960 break;
2961
2962 case TemplateArgument::Declaration:
2963 case TemplateArgument::Integral:
2964 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002965 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002966 break;
2967 }
2968}
2969
2970template<typename Derived>
2971bool TreeTransform<Derived>::TransformTemplateArgument(
2972 const TemplateArgumentLoc &Input,
2973 TemplateArgumentLoc &Output) {
2974 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002975 switch (Arg.getKind()) {
2976 case TemplateArgument::Null:
2977 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002978 Output = Input;
2979 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002980
Douglas Gregor670444e2009-08-04 22:27:00 +00002981 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002982 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002983 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002984 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002985
2986 DI = getDerived().TransformType(DI);
2987 if (!DI) return true;
2988
2989 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2990 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002991 }
Mike Stump1eb44332009-09-09 15:08:12 +00002992
Douglas Gregor670444e2009-08-04 22:27:00 +00002993 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002994 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002995 DeclarationName Name;
2996 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2997 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002998 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002999 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00003000 if (!D) return true;
3001
John McCall828bff22009-10-29 18:45:58 +00003002 Expr *SourceExpr = Input.getSourceDeclExpression();
3003 if (SourceExpr) {
3004 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003005 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00003006 ExprResult E = getDerived().TransformExpr(SourceExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003007 E = SemaRef.ActOnConstantExpression(E);
John McCall9ae2f072010-08-23 23:25:46 +00003008 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00003009 }
3010
3011 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00003012 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003013 }
Mike Stump1eb44332009-09-09 15:08:12 +00003014
Douglas Gregor788cd062009-11-11 01:00:40 +00003015 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003016 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3017 if (QualifierLoc) {
3018 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3019 if (!QualifierLoc)
3020 return true;
3021 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003022
Douglas Gregor1d752d72011-03-02 18:46:51 +00003023 CXXScopeSpec SS;
3024 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003025 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003026 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3027 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003028 if (Template.isNull())
3029 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003030
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003031 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003032 Input.getTemplateNameLoc());
3033 return false;
3034 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003035
3036 case TemplateArgument::TemplateExpansion:
3037 llvm_unreachable("Caller should expand pack expansions");
3038
Douglas Gregor670444e2009-08-04 22:27:00 +00003039 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003040 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003041 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003042 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003043
John McCall833ca992009-10-29 08:12:44 +00003044 Expr *InputExpr = Input.getSourceExpression();
3045 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3046
Chris Lattner223de242011-04-25 20:37:58 +00003047 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003048 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003049 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003050 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003051 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003052 }
Mike Stump1eb44332009-09-09 15:08:12 +00003053
Douglas Gregor670444e2009-08-04 22:27:00 +00003054 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00003055 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00003056 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00003057 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00003058 AEnd = Arg.pack_end();
3059 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00003060
John McCall833ca992009-10-29 08:12:44 +00003061 // FIXME: preserve source information here when we start
3062 // caring about parameter packs.
3063
John McCall828bff22009-10-29 18:45:58 +00003064 TemplateArgumentLoc InputArg;
3065 TemplateArgumentLoc OutputArg;
3066 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3067 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00003068 return true;
3069
John McCall828bff22009-10-29 18:45:58 +00003070 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00003071 }
Douglas Gregor910f8002010-11-07 23:05:16 +00003072
3073 TemplateArgument *TransformedArgsPtr
3074 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3075 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3076 TransformedArgsPtr);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003077 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3078 TransformedArgs.size()),
Douglas Gregor910f8002010-11-07 23:05:16 +00003079 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003080 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003081 }
3082 }
Mike Stump1eb44332009-09-09 15:08:12 +00003083
Douglas Gregor670444e2009-08-04 22:27:00 +00003084 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003085 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003086}
3087
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003088/// \brief Iterator adaptor that invents template argument location information
3089/// for each of the template arguments in its underlying iterator.
3090template<typename Derived, typename InputIterator>
3091class TemplateArgumentLocInventIterator {
3092 TreeTransform<Derived> &Self;
3093 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003094
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003095public:
3096 typedef TemplateArgumentLoc value_type;
3097 typedef TemplateArgumentLoc reference;
3098 typedef typename std::iterator_traits<InputIterator>::difference_type
3099 difference_type;
3100 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003101
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003102 class pointer {
3103 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003104
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003105 public:
3106 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003107
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003108 const TemplateArgumentLoc *operator->() const { return &Arg; }
3109 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003110
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003111 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003112
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003113 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3114 InputIterator Iter)
3115 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003116
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003117 TemplateArgumentLocInventIterator &operator++() {
3118 ++Iter;
3119 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003120 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003121
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003122 TemplateArgumentLocInventIterator operator++(int) {
3123 TemplateArgumentLocInventIterator Old(*this);
3124 ++(*this);
3125 return Old;
3126 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003127
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003128 reference operator*() const {
3129 TemplateArgumentLoc Result;
3130 Self.InventTemplateArgumentLoc(*Iter, Result);
3131 return Result;
3132 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003133
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003134 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003135
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003136 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3137 const TemplateArgumentLocInventIterator &Y) {
3138 return X.Iter == Y.Iter;
3139 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003140
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003141 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3142 const TemplateArgumentLocInventIterator &Y) {
3143 return X.Iter != Y.Iter;
3144 }
3145};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003146
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003147template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003148template<typename InputIterator>
3149bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3150 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003151 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003152 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003153 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003154 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003155
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003156 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3157 // Unpack argument packs, which we translate them into separate
3158 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003159 // FIXME: We could do much better if we could guarantee that the
3160 // TemplateArgumentLocInfo for the pack expansion would be usable for
3161 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003162 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003163 TemplateArgument::pack_iterator>
3164 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003165 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003166 In.getArgument().pack_begin()),
3167 PackLocIterator(*this,
3168 In.getArgument().pack_end()),
3169 Outputs))
3170 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003171
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003172 continue;
3173 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003174
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003175 if (In.getArgument().isPackExpansion()) {
3176 // We have a pack expansion, for which we will be substituting into
3177 // the pattern.
3178 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003179 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003180 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003181 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003182 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003183
Chris Lattner686775d2011-07-20 06:58:45 +00003184 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003185 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3186 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003187
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003188 // Determine whether the set of unexpanded parameter packs can and should
3189 // be expanded.
3190 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003191 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003192 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003193 if (getDerived().TryExpandParameterPacks(Ellipsis,
3194 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003195 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003196 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003197 RetainExpansion,
3198 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003199 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003200
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003201 if (!Expand) {
3202 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003203 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003204 // expansion.
3205 TemplateArgumentLoc OutPattern;
3206 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3207 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3208 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003209
Douglas Gregorcded4f62011-01-14 17:04:44 +00003210 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3211 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003212 if (Out.getArgument().isNull())
3213 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003214
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003215 Outputs.addArgument(Out);
3216 continue;
3217 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003218
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003219 // The transform has determined that we should perform an elementwise
3220 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003221 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003222 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3223
3224 if (getDerived().TransformTemplateArgument(Pattern, Out))
3225 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003226
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003227 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003228 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3229 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003230 if (Out.getArgument().isNull())
3231 return true;
3232 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003233
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003234 Outputs.addArgument(Out);
3235 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003236
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003237 // If we're supposed to retain a pack expansion, do so by temporarily
3238 // forgetting the partially-substituted parameter pack.
3239 if (RetainExpansion) {
3240 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003241
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003242 if (getDerived().TransformTemplateArgument(Pattern, Out))
3243 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003244
Douglas Gregorcded4f62011-01-14 17:04:44 +00003245 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3246 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003247 if (Out.getArgument().isNull())
3248 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003249
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003250 Outputs.addArgument(Out);
3251 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003252
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003253 continue;
3254 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003255
3256 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003257 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003258 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003259
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003260 Outputs.addArgument(Out);
3261 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003262
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003263 return false;
3264
3265}
3266
Douglas Gregor577f75a2009-08-04 16:50:30 +00003267//===----------------------------------------------------------------------===//
3268// Type transformation
3269//===----------------------------------------------------------------------===//
3270
3271template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003272QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003273 if (getDerived().AlreadyTransformed(T))
3274 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003275
John McCalla2becad2009-10-21 00:40:46 +00003276 // Temporary workaround. All of these transformations should
3277 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003278 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3279 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003280
John McCall43fed0d2010-11-12 08:19:04 +00003281 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003282
John McCalla2becad2009-10-21 00:40:46 +00003283 if (!NewDI)
3284 return QualType();
3285
3286 return NewDI->getType();
3287}
3288
3289template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003290TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003291 // Refine the base location to the type's location.
3292 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3293 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003294 if (getDerived().AlreadyTransformed(DI->getType()))
3295 return DI;
3296
3297 TypeLocBuilder TLB;
3298
3299 TypeLoc TL = DI->getTypeLoc();
3300 TLB.reserve(TL.getFullDataSize());
3301
John McCall43fed0d2010-11-12 08:19:04 +00003302 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003303 if (Result.isNull())
3304 return 0;
3305
John McCalla93c9342009-12-07 02:54:59 +00003306 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003307}
3308
3309template<typename Derived>
3310QualType
John McCall43fed0d2010-11-12 08:19:04 +00003311TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003312 switch (T.getTypeLocClass()) {
3313#define ABSTRACT_TYPELOC(CLASS, PARENT)
3314#define TYPELOC(CLASS, PARENT) \
3315 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003316 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003317#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003318 }
Mike Stump1eb44332009-09-09 15:08:12 +00003319
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003320 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003321}
3322
3323/// FIXME: By default, this routine adds type qualifiers only to types
3324/// that can have qualifiers, and silently suppresses those qualifiers
3325/// that are not permitted (e.g., qualifiers on reference or function
3326/// types). This is the right thing for template instantiation, but
3327/// probably not for other clients.
3328template<typename Derived>
3329QualType
3330TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003331 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003332 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003333
John McCall43fed0d2010-11-12 08:19:04 +00003334 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003335 if (Result.isNull())
3336 return QualType();
3337
3338 // Silently suppress qualifiers if the result type can't be qualified.
3339 // FIXME: this is the right thing for template instantiation, but
3340 // probably not for other clients.
3341 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003342 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003343
John McCallf85e1932011-06-15 23:02:42 +00003344 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003345 // resulting type.
3346 if (Quals.hasObjCLifetime()) {
3347 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3348 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003349 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003350 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003351 // A lifetime qualifier applied to a substituted template parameter
3352 // overrides the lifetime qualifier from the template argument.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003353 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003354 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3355 QualType Replacement = SubstTypeParam->getReplacementType();
3356 Qualifiers Qs = Replacement.getQualifiers();
3357 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003358 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003359 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3360 Qs);
3361 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003362 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003363 Replacement);
3364 TLB.TypeWasModifiedSafely(Result);
3365 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003366 // Otherwise, complain about the addition of a qualifier to an
3367 // already-qualified type.
3368 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003369 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003370 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003371
Douglas Gregore559ca12011-06-17 22:11:49 +00003372 Quals.removeObjCLifetime();
3373 }
3374 }
3375 }
John McCall28654742010-06-05 06:41:15 +00003376 if (!Quals.empty()) {
3377 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3378 TLB.push<QualifiedTypeLoc>(Result);
3379 // No location information to preserve.
3380 }
John McCalla2becad2009-10-21 00:40:46 +00003381
3382 return Result;
3383}
3384
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003385template<typename Derived>
3386TypeLoc
3387TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3388 QualType ObjectType,
3389 NamedDecl *UnqualLookup,
3390 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003391 QualType T = TL.getType();
3392 if (getDerived().AlreadyTransformed(T))
3393 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003394
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003395 TypeLocBuilder TLB;
3396 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003397
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003398 if (isa<TemplateSpecializationType>(T)) {
3399 TemplateSpecializationTypeLoc SpecTL
3400 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003401
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003402 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003403 getDerived().TransformTemplateName(SS,
3404 SpecTL.getTypePtr()->getTemplateName(),
3405 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003406 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003407 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003408 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003409
3410 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003411 Template);
3412 } else if (isa<DependentTemplateSpecializationType>(T)) {
3413 DependentTemplateSpecializationTypeLoc SpecTL
3414 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003415
Douglas Gregora88f09f2011-02-28 17:23:35 +00003416 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003417 = getDerived().RebuildTemplateName(SS,
3418 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003419 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003420 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003421 if (Template.isNull())
3422 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003423
3424 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003425 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003426 Template,
3427 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003428 } else {
3429 // Nothing special needs to be done for these.
3430 Result = getDerived().TransformType(TLB, TL);
3431 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003432
3433 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003434 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003435
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003436 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3437}
3438
Douglas Gregorb71d8212011-03-02 18:32:08 +00003439template<typename Derived>
3440TypeSourceInfo *
3441TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3442 QualType ObjectType,
3443 NamedDecl *UnqualLookup,
3444 CXXScopeSpec &SS) {
3445 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003446
Douglas Gregorb71d8212011-03-02 18:32:08 +00003447 QualType T = TSInfo->getType();
3448 if (getDerived().AlreadyTransformed(T))
3449 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003450
Douglas Gregorb71d8212011-03-02 18:32:08 +00003451 TypeLocBuilder TLB;
3452 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003453
Douglas Gregorb71d8212011-03-02 18:32:08 +00003454 TypeLoc TL = TSInfo->getTypeLoc();
3455 if (isa<TemplateSpecializationType>(T)) {
3456 TemplateSpecializationTypeLoc SpecTL
3457 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003458
Douglas Gregorb71d8212011-03-02 18:32:08 +00003459 TemplateName Template
3460 = getDerived().TransformTemplateName(SS,
3461 SpecTL.getTypePtr()->getTemplateName(),
3462 SpecTL.getTemplateNameLoc(),
3463 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003464 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003465 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003466
3467 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003468 Template);
3469 } else if (isa<DependentTemplateSpecializationType>(T)) {
3470 DependentTemplateSpecializationTypeLoc SpecTL
3471 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003472
Douglas Gregorb71d8212011-03-02 18:32:08 +00003473 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003474 = getDerived().RebuildTemplateName(SS,
3475 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003476 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003477 ObjectType, UnqualLookup);
3478 if (Template.isNull())
3479 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003480
3481 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003482 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003483 Template,
3484 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003485 } else {
3486 // Nothing special needs to be done for these.
3487 Result = getDerived().TransformType(TLB, TL);
3488 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003489
3490 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003491 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003492
Douglas Gregorb71d8212011-03-02 18:32:08 +00003493 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3494}
3495
John McCalla2becad2009-10-21 00:40:46 +00003496template <class TyLoc> static inline
3497QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3498 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3499 NewT.setNameLoc(T.getNameLoc());
3500 return T.getType();
3501}
3502
John McCalla2becad2009-10-21 00:40:46 +00003503template<typename Derived>
3504QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003505 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003506 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3507 NewT.setBuiltinLoc(T.getBuiltinLoc());
3508 if (T.needsExtraLocalData())
3509 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3510 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003511}
Mike Stump1eb44332009-09-09 15:08:12 +00003512
Douglas Gregor577f75a2009-08-04 16:50:30 +00003513template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003514QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003515 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003516 // FIXME: recurse?
3517 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003518}
Mike Stump1eb44332009-09-09 15:08:12 +00003519
Douglas Gregor577f75a2009-08-04 16:50:30 +00003520template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003521QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003522 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003523 QualType PointeeType
3524 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003525 if (PointeeType.isNull())
3526 return QualType();
3527
3528 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003529 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003530 // A dependent pointer type 'T *' has is being transformed such
3531 // that an Objective-C class type is being replaced for 'T'. The
3532 // resulting pointer type is an ObjCObjectPointerType, not a
3533 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003534 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003535
John McCallc12c5bb2010-05-15 11:32:37 +00003536 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3537 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003538 return Result;
3539 }
John McCall43fed0d2010-11-12 08:19:04 +00003540
Douglas Gregor92e986e2010-04-22 16:44:27 +00003541 if (getDerived().AlwaysRebuild() ||
3542 PointeeType != TL.getPointeeLoc().getType()) {
3543 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3544 if (Result.isNull())
3545 return QualType();
3546 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003547
John McCallf85e1932011-06-15 23:02:42 +00003548 // Objective-C ARC can add lifetime qualifiers to the type that we're
3549 // pointing to.
3550 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003551
Douglas Gregor92e986e2010-04-22 16:44:27 +00003552 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3553 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003554 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003555}
Mike Stump1eb44332009-09-09 15:08:12 +00003556
3557template<typename Derived>
3558QualType
John McCalla2becad2009-10-21 00:40:46 +00003559TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003560 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003561 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003562 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3563 if (PointeeType.isNull())
3564 return QualType();
3565
3566 QualType Result = TL.getType();
3567 if (getDerived().AlwaysRebuild() ||
3568 PointeeType != TL.getPointeeLoc().getType()) {
3569 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003570 TL.getSigilLoc());
3571 if (Result.isNull())
3572 return QualType();
3573 }
3574
Douglas Gregor39968ad2010-04-22 16:50:51 +00003575 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003576 NewT.setSigilLoc(TL.getSigilLoc());
3577 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003578}
3579
John McCall85737a72009-10-30 00:06:24 +00003580/// Transforms a reference type. Note that somewhat paradoxically we
3581/// don't care whether the type itself is an l-value type or an r-value
3582/// type; we only care if the type was *written* as an l-value type
3583/// or an r-value type.
3584template<typename Derived>
3585QualType
3586TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003587 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003588 const ReferenceType *T = TL.getTypePtr();
3589
3590 // Note that this works with the pointee-as-written.
3591 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3592 if (PointeeType.isNull())
3593 return QualType();
3594
3595 QualType Result = TL.getType();
3596 if (getDerived().AlwaysRebuild() ||
3597 PointeeType != T->getPointeeTypeAsWritten()) {
3598 Result = getDerived().RebuildReferenceType(PointeeType,
3599 T->isSpelledAsLValue(),
3600 TL.getSigilLoc());
3601 if (Result.isNull())
3602 return QualType();
3603 }
3604
John McCallf85e1932011-06-15 23:02:42 +00003605 // Objective-C ARC can add lifetime qualifiers to the type that we're
3606 // referring to.
3607 TLB.TypeWasModifiedSafely(
3608 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3609
John McCall85737a72009-10-30 00:06:24 +00003610 // r-value references can be rebuilt as l-value references.
3611 ReferenceTypeLoc NewTL;
3612 if (isa<LValueReferenceType>(Result))
3613 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3614 else
3615 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3616 NewTL.setSigilLoc(TL.getSigilLoc());
3617
3618 return Result;
3619}
3620
Mike Stump1eb44332009-09-09 15:08:12 +00003621template<typename Derived>
3622QualType
John McCalla2becad2009-10-21 00:40:46 +00003623TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003624 LValueReferenceTypeLoc TL) {
3625 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003626}
3627
Mike Stump1eb44332009-09-09 15:08:12 +00003628template<typename Derived>
3629QualType
John McCalla2becad2009-10-21 00:40:46 +00003630TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003631 RValueReferenceTypeLoc TL) {
3632 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003633}
Mike Stump1eb44332009-09-09 15:08:12 +00003634
Douglas Gregor577f75a2009-08-04 16:50:30 +00003635template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003636QualType
John McCalla2becad2009-10-21 00:40:46 +00003637TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003638 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003639 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003640 if (PointeeType.isNull())
3641 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003642
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003643 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3644 TypeSourceInfo* NewClsTInfo = 0;
3645 if (OldClsTInfo) {
3646 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3647 if (!NewClsTInfo)
3648 return QualType();
3649 }
3650
3651 const MemberPointerType *T = TL.getTypePtr();
3652 QualType OldClsType = QualType(T->getClass(), 0);
3653 QualType NewClsType;
3654 if (NewClsTInfo)
3655 NewClsType = NewClsTInfo->getType();
3656 else {
3657 NewClsType = getDerived().TransformType(OldClsType);
3658 if (NewClsType.isNull())
3659 return QualType();
3660 }
Mike Stump1eb44332009-09-09 15:08:12 +00003661
John McCalla2becad2009-10-21 00:40:46 +00003662 QualType Result = TL.getType();
3663 if (getDerived().AlwaysRebuild() ||
3664 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003665 NewClsType != OldClsType) {
3666 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003667 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003668 if (Result.isNull())
3669 return QualType();
3670 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003671
John McCalla2becad2009-10-21 00:40:46 +00003672 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3673 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003674 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003675
3676 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003677}
3678
Mike Stump1eb44332009-09-09 15:08:12 +00003679template<typename Derived>
3680QualType
John McCalla2becad2009-10-21 00:40:46 +00003681TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003682 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003683 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003684 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003685 if (ElementType.isNull())
3686 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003687
John McCalla2becad2009-10-21 00:40:46 +00003688 QualType Result = TL.getType();
3689 if (getDerived().AlwaysRebuild() ||
3690 ElementType != T->getElementType()) {
3691 Result = getDerived().RebuildConstantArrayType(ElementType,
3692 T->getSizeModifier(),
3693 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003694 T->getIndexTypeCVRQualifiers(),
3695 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003696 if (Result.isNull())
3697 return QualType();
3698 }
Eli Friedman457a3772012-01-25 22:19:07 +00003699
3700 // We might have either a ConstantArrayType or a VariableArrayType now:
3701 // a ConstantArrayType is allowed to have an element type which is a
3702 // VariableArrayType if the type is dependent. Fortunately, all array
3703 // types have the same location layout.
3704 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003705 NewTL.setLBracketLoc(TL.getLBracketLoc());
3706 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003707
John McCalla2becad2009-10-21 00:40:46 +00003708 Expr *Size = TL.getSizeExpr();
3709 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003710 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3711 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003712 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003713 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003714 }
3715 NewTL.setSizeExpr(Size);
3716
3717 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003718}
Mike Stump1eb44332009-09-09 15:08:12 +00003719
Douglas Gregor577f75a2009-08-04 16:50:30 +00003720template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003721QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003722 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003723 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003724 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003725 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003726 if (ElementType.isNull())
3727 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003728
John McCalla2becad2009-10-21 00:40:46 +00003729 QualType Result = TL.getType();
3730 if (getDerived().AlwaysRebuild() ||
3731 ElementType != T->getElementType()) {
3732 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003733 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003734 T->getIndexTypeCVRQualifiers(),
3735 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003736 if (Result.isNull())
3737 return QualType();
3738 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003739
John McCalla2becad2009-10-21 00:40:46 +00003740 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3741 NewTL.setLBracketLoc(TL.getLBracketLoc());
3742 NewTL.setRBracketLoc(TL.getRBracketLoc());
3743 NewTL.setSizeExpr(0);
3744
3745 return Result;
3746}
3747
3748template<typename Derived>
3749QualType
3750TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003751 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003752 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003753 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3754 if (ElementType.isNull())
3755 return QualType();
3756
John McCall60d7b3a2010-08-24 06:29:42 +00003757 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003758 = getDerived().TransformExpr(T->getSizeExpr());
3759 if (SizeResult.isInvalid())
3760 return QualType();
3761
John McCall9ae2f072010-08-23 23:25:46 +00003762 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003763
3764 QualType Result = TL.getType();
3765 if (getDerived().AlwaysRebuild() ||
3766 ElementType != T->getElementType() ||
3767 Size != T->getSizeExpr()) {
3768 Result = getDerived().RebuildVariableArrayType(ElementType,
3769 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003770 Size,
John McCalla2becad2009-10-21 00:40:46 +00003771 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003772 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003773 if (Result.isNull())
3774 return QualType();
3775 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003776
John McCalla2becad2009-10-21 00:40:46 +00003777 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3778 NewTL.setLBracketLoc(TL.getLBracketLoc());
3779 NewTL.setRBracketLoc(TL.getRBracketLoc());
3780 NewTL.setSizeExpr(Size);
3781
3782 return Result;
3783}
3784
3785template<typename Derived>
3786QualType
3787TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003788 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003789 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003790 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3791 if (ElementType.isNull())
3792 return QualType();
3793
Richard Smithf6702a32011-12-20 02:08:33 +00003794 // Array bounds are constant expressions.
3795 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3796 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003797
John McCall3b657512011-01-19 10:06:00 +00003798 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3799 Expr *origSize = TL.getSizeExpr();
3800 if (!origSize) origSize = T->getSizeExpr();
3801
3802 ExprResult sizeResult
3803 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003804 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003805 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003806 return QualType();
3807
John McCall3b657512011-01-19 10:06:00 +00003808 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003809
3810 QualType Result = TL.getType();
3811 if (getDerived().AlwaysRebuild() ||
3812 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003813 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003814 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3815 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003816 size,
John McCalla2becad2009-10-21 00:40:46 +00003817 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003818 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003819 if (Result.isNull())
3820 return QualType();
3821 }
John McCalla2becad2009-10-21 00:40:46 +00003822
3823 // We might have any sort of array type now, but fortunately they
3824 // all have the same location layout.
3825 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3826 NewTL.setLBracketLoc(TL.getLBracketLoc());
3827 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003828 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003829
3830 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003831}
Mike Stump1eb44332009-09-09 15:08:12 +00003832
3833template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003834QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003835 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003836 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003837 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003838
3839 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003840 QualType ElementType = getDerived().TransformType(T->getElementType());
3841 if (ElementType.isNull())
3842 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003843
Richard Smithf6702a32011-12-20 02:08:33 +00003844 // Vector sizes are constant expressions.
3845 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3846 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003847
John McCall60d7b3a2010-08-24 06:29:42 +00003848 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003849 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003850 if (Size.isInvalid())
3851 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003852
John McCalla2becad2009-10-21 00:40:46 +00003853 QualType Result = TL.getType();
3854 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003855 ElementType != T->getElementType() ||
3856 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003857 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003858 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003859 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003860 if (Result.isNull())
3861 return QualType();
3862 }
John McCalla2becad2009-10-21 00:40:46 +00003863
3864 // Result might be dependent or not.
3865 if (isa<DependentSizedExtVectorType>(Result)) {
3866 DependentSizedExtVectorTypeLoc NewTL
3867 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3868 NewTL.setNameLoc(TL.getNameLoc());
3869 } else {
3870 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3871 NewTL.setNameLoc(TL.getNameLoc());
3872 }
3873
3874 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003875}
Mike Stump1eb44332009-09-09 15:08:12 +00003876
3877template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003878QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003879 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003880 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003881 QualType ElementType = getDerived().TransformType(T->getElementType());
3882 if (ElementType.isNull())
3883 return QualType();
3884
John McCalla2becad2009-10-21 00:40:46 +00003885 QualType Result = TL.getType();
3886 if (getDerived().AlwaysRebuild() ||
3887 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003888 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003889 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003890 if (Result.isNull())
3891 return QualType();
3892 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003893
John McCalla2becad2009-10-21 00:40:46 +00003894 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3895 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003896
John McCalla2becad2009-10-21 00:40:46 +00003897 return Result;
3898}
3899
3900template<typename Derived>
3901QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003902 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003903 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003904 QualType ElementType = getDerived().TransformType(T->getElementType());
3905 if (ElementType.isNull())
3906 return QualType();
3907
3908 QualType Result = TL.getType();
3909 if (getDerived().AlwaysRebuild() ||
3910 ElementType != T->getElementType()) {
3911 Result = getDerived().RebuildExtVectorType(ElementType,
3912 T->getNumElements(),
3913 /*FIXME*/ SourceLocation());
3914 if (Result.isNull())
3915 return QualType();
3916 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003917
John McCalla2becad2009-10-21 00:40:46 +00003918 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3919 NewTL.setNameLoc(TL.getNameLoc());
3920
3921 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003922}
Mike Stump1eb44332009-09-09 15:08:12 +00003923
3924template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003925ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003926TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003927 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003928 llvm::Optional<unsigned> NumExpansions,
3929 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003930 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003931 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003932
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003933 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003934 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003935 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003936 TypeLoc OldTL = OldDI->getTypeLoc();
3937 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003938
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003939 TypeLocBuilder TLB;
3940 TypeLoc NewTL = OldDI->getTypeLoc();
3941 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003942
3943 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003944 OldExpansionTL.getPatternLoc());
3945 if (Result.isNull())
3946 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003947
3948 Result = RebuildPackExpansionType(Result,
3949 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003950 OldExpansionTL.getEllipsisLoc(),
3951 NumExpansions);
3952 if (Result.isNull())
3953 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003954
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003955 PackExpansionTypeLoc NewExpansionTL
3956 = TLB.push<PackExpansionTypeLoc>(Result);
3957 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3958 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3959 } else
3960 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003961 if (!NewDI)
3962 return 0;
3963
John McCallfb44de92011-05-01 22:35:37 +00003964 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003965 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003966
3967 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3968 OldParm->getDeclContext(),
3969 OldParm->getInnerLocStart(),
3970 OldParm->getLocation(),
3971 OldParm->getIdentifier(),
3972 NewDI->getType(),
3973 NewDI,
3974 OldParm->getStorageClass(),
3975 OldParm->getStorageClassAsWritten(),
3976 /* DefArg */ NULL);
3977 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3978 OldParm->getFunctionScopeIndex() + indexAdjustment);
3979 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003980}
3981
3982template<typename Derived>
3983bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003984 TransformFunctionTypeParams(SourceLocation Loc,
3985 ParmVarDecl **Params, unsigned NumParams,
3986 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003987 SmallVectorImpl<QualType> &OutParamTypes,
3988 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003989 int indexAdjustment = 0;
3990
Douglas Gregora009b592011-01-07 00:20:55 +00003991 for (unsigned i = 0; i != NumParams; ++i) {
3992 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003993 assert(OldParm->getFunctionScopeIndex() == i);
3994
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003995 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003996 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003997 if (OldParm->isParameterPack()) {
3998 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003999 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004000
Douglas Gregor603cfb42011-01-05 23:12:31 +00004001 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004002 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4003 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
4004 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4005 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004006 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4007
Douglas Gregor603cfb42011-01-05 23:12:31 +00004008 // Determine whether we should expand the parameter packs.
4009 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004010 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004011 llvm::Optional<unsigned> OrigNumExpansions
4012 = ExpansionTL.getTypePtr()->getNumExpansions();
4013 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004014 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4015 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004016 Unexpanded,
4017 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004018 RetainExpansion,
4019 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004020 return true;
4021 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004022
Douglas Gregor603cfb42011-01-05 23:12:31 +00004023 if (ShouldExpand) {
4024 // Expand the function parameter pack into multiple, separate
4025 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004026 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004027 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004028 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004029 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004030 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004031 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004032 OrigNumExpansions,
4033 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004034 if (!NewParm)
4035 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004036
Douglas Gregora009b592011-01-07 00:20:55 +00004037 OutParamTypes.push_back(NewParm->getType());
4038 if (PVars)
4039 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004040 }
Douglas Gregord3731192011-01-10 07:32:04 +00004041
4042 // If we're supposed to retain a pack expansion, do so by temporarily
4043 // forgetting the partially-substituted parameter pack.
4044 if (RetainExpansion) {
4045 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004046 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004047 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004048 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004049 OrigNumExpansions,
4050 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004051 if (!NewParm)
4052 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004053
Douglas Gregord3731192011-01-10 07:32:04 +00004054 OutParamTypes.push_back(NewParm->getType());
4055 if (PVars)
4056 PVars->push_back(NewParm);
4057 }
4058
John McCallfb44de92011-05-01 22:35:37 +00004059 // The next parameter should have the same adjustment as the
4060 // last thing we pushed, but we post-incremented indexAdjustment
4061 // on every push. Also, if we push nothing, the adjustment should
4062 // go down by one.
4063 indexAdjustment--;
4064
Douglas Gregor603cfb42011-01-05 23:12:31 +00004065 // We're done with the pack expansion.
4066 continue;
4067 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004068
4069 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004070 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004071 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4072 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004073 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004074 NumExpansions,
4075 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004076 } else {
4077 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004078 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004079 llvm::Optional<unsigned>(),
4080 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004081 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004082
John McCall21ef0fa2010-03-11 09:03:00 +00004083 if (!NewParm)
4084 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004085
Douglas Gregora009b592011-01-07 00:20:55 +00004086 OutParamTypes.push_back(NewParm->getType());
4087 if (PVars)
4088 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004089 continue;
4090 }
John McCall21ef0fa2010-03-11 09:03:00 +00004091
4092 // Deal with the possibility that we don't have a parameter
4093 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004094 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004095 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004096 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004097 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004098 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004099 = dyn_cast<PackExpansionType>(OldType)) {
4100 // We have a function parameter pack that may need to be expanded.
4101 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004102 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004103 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004104
Douglas Gregor603cfb42011-01-05 23:12:31 +00004105 // Determine whether we should expand the parameter packs.
4106 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004107 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004108 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004109 Unexpanded,
4110 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004111 RetainExpansion,
4112 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004113 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004114 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004115
Douglas Gregor603cfb42011-01-05 23:12:31 +00004116 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004117 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004118 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004119 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004120 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4121 QualType NewType = getDerived().TransformType(Pattern);
4122 if (NewType.isNull())
4123 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004124
Douglas Gregora009b592011-01-07 00:20:55 +00004125 OutParamTypes.push_back(NewType);
4126 if (PVars)
4127 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004128 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004129
Douglas Gregor603cfb42011-01-05 23:12:31 +00004130 // We're done with the pack expansion.
4131 continue;
4132 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004133
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004134 // If we're supposed to retain a pack expansion, do so by temporarily
4135 // forgetting the partially-substituted parameter pack.
4136 if (RetainExpansion) {
4137 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4138 QualType NewType = getDerived().TransformType(Pattern);
4139 if (NewType.isNull())
4140 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004141
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004142 OutParamTypes.push_back(NewType);
4143 if (PVars)
4144 PVars->push_back(0);
4145 }
Douglas Gregord3731192011-01-10 07:32:04 +00004146
Chad Rosier4a9d7952012-08-08 18:46:20 +00004147 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004148 // expansion.
4149 OldType = Expansion->getPattern();
4150 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004151 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4152 NewType = getDerived().TransformType(OldType);
4153 } else {
4154 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004155 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004156
Douglas Gregor603cfb42011-01-05 23:12:31 +00004157 if (NewType.isNull())
4158 return true;
4159
4160 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004161 NewType = getSema().Context.getPackExpansionType(NewType,
4162 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004163
Douglas Gregora009b592011-01-07 00:20:55 +00004164 OutParamTypes.push_back(NewType);
4165 if (PVars)
4166 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004167 }
4168
John McCallfb44de92011-05-01 22:35:37 +00004169#ifndef NDEBUG
4170 if (PVars) {
4171 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4172 if (ParmVarDecl *parm = (*PVars)[i])
4173 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004174 }
John McCallfb44de92011-05-01 22:35:37 +00004175#endif
4176
4177 return false;
4178}
John McCall21ef0fa2010-03-11 09:03:00 +00004179
4180template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004181QualType
John McCalla2becad2009-10-21 00:40:46 +00004182TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004183 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004184 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4185}
4186
4187template<typename Derived>
4188QualType
4189TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4190 FunctionProtoTypeLoc TL,
4191 CXXRecordDecl *ThisContext,
4192 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004193 // Transform the parameters and return type.
4194 //
Richard Smithe6975e92012-04-17 00:58:00 +00004195 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004196 // When the function has a trailing return type, we instantiate the
4197 // parameters before the return type, since the return type can then refer
4198 // to the parameters themselves (via decltype, sizeof, etc.).
4199 //
Chris Lattner686775d2011-07-20 06:58:45 +00004200 SmallVector<QualType, 4> ParamTypes;
4201 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004202 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004203
Douglas Gregordab60ad2010-10-01 18:44:50 +00004204 QualType ResultType;
4205
Richard Smith9fbf3272012-08-14 22:51:13 +00004206 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004207 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004208 TL.getParmArray(),
4209 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004210 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004211 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004212 return QualType();
4213
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004214 {
4215 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004216 // If a declaration declares a member function or member function
4217 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004218 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004219 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004220 // declarator.
4221 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004222
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004223 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4224 if (ResultType.isNull())
4225 return QualType();
4226 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004227 }
4228 else {
4229 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4230 if (ResultType.isNull())
4231 return QualType();
4232
Chad Rosier4a9d7952012-08-08 18:46:20 +00004233 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004234 TL.getParmArray(),
4235 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004236 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004237 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004238 return QualType();
4239 }
4240
Richard Smithe6975e92012-04-17 00:58:00 +00004241 // FIXME: Need to transform the exception-specification too.
4242
John McCalla2becad2009-10-21 00:40:46 +00004243 QualType Result = TL.getType();
4244 if (getDerived().AlwaysRebuild() ||
4245 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004246 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004247 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4248 Result = getDerived().RebuildFunctionProtoType(ResultType,
4249 ParamTypes.data(),
4250 ParamTypes.size(),
4251 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004252 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004253 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004254 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004255 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004256 if (Result.isNull())
4257 return QualType();
4258 }
Mike Stump1eb44332009-09-09 15:08:12 +00004259
John McCalla2becad2009-10-21 00:40:46 +00004260 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004261 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4262 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004263 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4264 NewTL.setArg(i, ParamDecls[i]);
4265
4266 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004267}
Mike Stump1eb44332009-09-09 15:08:12 +00004268
Douglas Gregor577f75a2009-08-04 16:50:30 +00004269template<typename Derived>
4270QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004271 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004272 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004273 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004274 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4275 if (ResultType.isNull())
4276 return QualType();
4277
4278 QualType Result = TL.getType();
4279 if (getDerived().AlwaysRebuild() ||
4280 ResultType != T->getResultType())
4281 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4282
4283 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004284 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4285 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004286
4287 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004288}
Mike Stump1eb44332009-09-09 15:08:12 +00004289
John McCalled976492009-12-04 22:46:56 +00004290template<typename Derived> QualType
4291TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004292 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004293 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004294 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004295 if (!D)
4296 return QualType();
4297
4298 QualType Result = TL.getType();
4299 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4300 Result = getDerived().RebuildUnresolvedUsingType(D);
4301 if (Result.isNull())
4302 return QualType();
4303 }
4304
4305 // We might get an arbitrary type spec type back. We should at
4306 // least always get a type spec type, though.
4307 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4308 NewTL.setNameLoc(TL.getNameLoc());
4309
4310 return Result;
4311}
4312
Douglas Gregor577f75a2009-08-04 16:50:30 +00004313template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004314QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004315 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004316 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004317 TypedefNameDecl *Typedef
4318 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4319 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004320 if (!Typedef)
4321 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004322
John McCalla2becad2009-10-21 00:40:46 +00004323 QualType Result = TL.getType();
4324 if (getDerived().AlwaysRebuild() ||
4325 Typedef != T->getDecl()) {
4326 Result = getDerived().RebuildTypedefType(Typedef);
4327 if (Result.isNull())
4328 return QualType();
4329 }
Mike Stump1eb44332009-09-09 15:08:12 +00004330
John McCalla2becad2009-10-21 00:40:46 +00004331 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4332 NewTL.setNameLoc(TL.getNameLoc());
4333
4334 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004335}
Mike Stump1eb44332009-09-09 15:08:12 +00004336
Douglas Gregor577f75a2009-08-04 16:50:30 +00004337template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004338QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004339 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004340 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004341 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004342
John McCall60d7b3a2010-08-24 06:29:42 +00004343 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004344 if (E.isInvalid())
4345 return QualType();
4346
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004347 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4348 if (E.isInvalid())
4349 return QualType();
4350
John McCalla2becad2009-10-21 00:40:46 +00004351 QualType Result = TL.getType();
4352 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004353 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004354 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004355 if (Result.isNull())
4356 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004357 }
John McCalla2becad2009-10-21 00:40:46 +00004358 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004359
John McCalla2becad2009-10-21 00:40:46 +00004360 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004361 NewTL.setTypeofLoc(TL.getTypeofLoc());
4362 NewTL.setLParenLoc(TL.getLParenLoc());
4363 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004364
4365 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004366}
Mike Stump1eb44332009-09-09 15:08:12 +00004367
4368template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004369QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004370 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004371 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4372 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4373 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004374 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004375
John McCalla2becad2009-10-21 00:40:46 +00004376 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004377 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4378 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004379 if (Result.isNull())
4380 return QualType();
4381 }
Mike Stump1eb44332009-09-09 15:08:12 +00004382
John McCalla2becad2009-10-21 00:40:46 +00004383 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004384 NewTL.setTypeofLoc(TL.getTypeofLoc());
4385 NewTL.setLParenLoc(TL.getLParenLoc());
4386 NewTL.setRParenLoc(TL.getRParenLoc());
4387 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004388
4389 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004390}
Mike Stump1eb44332009-09-09 15:08:12 +00004391
4392template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004393QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004394 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004395 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004396
Douglas Gregor670444e2009-08-04 22:27:00 +00004397 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004398 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4399 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004400
John McCall60d7b3a2010-08-24 06:29:42 +00004401 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004402 if (E.isInvalid())
4403 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004404
Richard Smith76f3f692012-02-22 02:04:18 +00004405 E = getSema().ActOnDecltypeExpression(E.take());
4406 if (E.isInvalid())
4407 return QualType();
4408
John McCalla2becad2009-10-21 00:40:46 +00004409 QualType Result = TL.getType();
4410 if (getDerived().AlwaysRebuild() ||
4411 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004412 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004413 if (Result.isNull())
4414 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004415 }
John McCalla2becad2009-10-21 00:40:46 +00004416 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004417
John McCalla2becad2009-10-21 00:40:46 +00004418 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4419 NewTL.setNameLoc(TL.getNameLoc());
4420
4421 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004422}
4423
4424template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004425QualType TreeTransform<Derived>::TransformUnaryTransformType(
4426 TypeLocBuilder &TLB,
4427 UnaryTransformTypeLoc TL) {
4428 QualType Result = TL.getType();
4429 if (Result->isDependentType()) {
4430 const UnaryTransformType *T = TL.getTypePtr();
4431 QualType NewBase =
4432 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4433 Result = getDerived().RebuildUnaryTransformType(NewBase,
4434 T->getUTTKind(),
4435 TL.getKWLoc());
4436 if (Result.isNull())
4437 return QualType();
4438 }
4439
4440 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4441 NewTL.setKWLoc(TL.getKWLoc());
4442 NewTL.setParensRange(TL.getParensRange());
4443 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4444 return Result;
4445}
4446
4447template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004448QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4449 AutoTypeLoc TL) {
4450 const AutoType *T = TL.getTypePtr();
4451 QualType OldDeduced = T->getDeducedType();
4452 QualType NewDeduced;
4453 if (!OldDeduced.isNull()) {
4454 NewDeduced = getDerived().TransformType(OldDeduced);
4455 if (NewDeduced.isNull())
4456 return QualType();
4457 }
4458
4459 QualType Result = TL.getType();
4460 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4461 Result = getDerived().RebuildAutoType(NewDeduced);
4462 if (Result.isNull())
4463 return QualType();
4464 }
4465
4466 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4467 NewTL.setNameLoc(TL.getNameLoc());
4468
4469 return Result;
4470}
4471
4472template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004473QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004474 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004475 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004476 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004477 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4478 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004479 if (!Record)
4480 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004481
John McCalla2becad2009-10-21 00:40:46 +00004482 QualType Result = TL.getType();
4483 if (getDerived().AlwaysRebuild() ||
4484 Record != T->getDecl()) {
4485 Result = getDerived().RebuildRecordType(Record);
4486 if (Result.isNull())
4487 return QualType();
4488 }
Mike Stump1eb44332009-09-09 15:08:12 +00004489
John McCalla2becad2009-10-21 00:40:46 +00004490 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4491 NewTL.setNameLoc(TL.getNameLoc());
4492
4493 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004494}
Mike Stump1eb44332009-09-09 15:08:12 +00004495
4496template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004497QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004498 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004499 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004500 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004501 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4502 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004503 if (!Enum)
4504 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004505
John McCalla2becad2009-10-21 00:40:46 +00004506 QualType Result = TL.getType();
4507 if (getDerived().AlwaysRebuild() ||
4508 Enum != T->getDecl()) {
4509 Result = getDerived().RebuildEnumType(Enum);
4510 if (Result.isNull())
4511 return QualType();
4512 }
Mike Stump1eb44332009-09-09 15:08:12 +00004513
John McCalla2becad2009-10-21 00:40:46 +00004514 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4515 NewTL.setNameLoc(TL.getNameLoc());
4516
4517 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004518}
John McCall7da24312009-09-05 00:15:47 +00004519
John McCall3cb0ebd2010-03-10 03:28:59 +00004520template<typename Derived>
4521QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4522 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004523 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004524 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4525 TL.getTypePtr()->getDecl());
4526 if (!D) return QualType();
4527
4528 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4529 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4530 return T;
4531}
4532
Douglas Gregor577f75a2009-08-04 16:50:30 +00004533template<typename Derived>
4534QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004535 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004536 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004537 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004538}
4539
Mike Stump1eb44332009-09-09 15:08:12 +00004540template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004541QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004542 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004543 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004544 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004545
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004546 // Substitute into the replacement type, which itself might involve something
4547 // that needs to be transformed. This only tends to occur with default
4548 // template arguments of template template parameters.
4549 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4550 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4551 if (Replacement.isNull())
4552 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004553
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004554 // Always canonicalize the replacement type.
4555 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4556 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004557 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004558 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004559
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004560 // Propagate type-source information.
4561 SubstTemplateTypeParmTypeLoc NewTL
4562 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4563 NewTL.setNameLoc(TL.getNameLoc());
4564 return Result;
4565
John McCall49a832b2009-10-18 09:09:24 +00004566}
4567
4568template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004569QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4570 TypeLocBuilder &TLB,
4571 SubstTemplateTypeParmPackTypeLoc TL) {
4572 return TransformTypeSpecType(TLB, TL);
4573}
4574
4575template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004576QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004577 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004578 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004579 const TemplateSpecializationType *T = TL.getTypePtr();
4580
Douglas Gregor1d752d72011-03-02 18:46:51 +00004581 // The nested-name-specifier never matters in a TemplateSpecializationType,
4582 // because we can't have a dependent nested-name-specifier anyway.
4583 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004584 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004585 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4586 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004587 if (Template.isNull())
4588 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004589
John McCall43fed0d2010-11-12 08:19:04 +00004590 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4591}
4592
Eli Friedmanb001de72011-10-06 23:00:33 +00004593template<typename Derived>
4594QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4595 AtomicTypeLoc TL) {
4596 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4597 if (ValueType.isNull())
4598 return QualType();
4599
4600 QualType Result = TL.getType();
4601 if (getDerived().AlwaysRebuild() ||
4602 ValueType != TL.getValueLoc().getType()) {
4603 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4604 if (Result.isNull())
4605 return QualType();
4606 }
4607
4608 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4609 NewTL.setKWLoc(TL.getKWLoc());
4610 NewTL.setLParenLoc(TL.getLParenLoc());
4611 NewTL.setRParenLoc(TL.getRParenLoc());
4612
4613 return Result;
4614}
4615
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004616namespace {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004617 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004618 /// container that provides a \c getArgLoc() member function.
4619 ///
4620 /// This iterator is intended to be used with the iterator form of
4621 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4622 template<typename ArgLocContainer>
4623 class TemplateArgumentLocContainerIterator {
4624 ArgLocContainer *Container;
4625 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004626
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004627 public:
4628 typedef TemplateArgumentLoc value_type;
4629 typedef TemplateArgumentLoc reference;
4630 typedef int difference_type;
4631 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004632
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004633 class pointer {
4634 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004635
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004636 public:
4637 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004638
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004639 const TemplateArgumentLoc *operator->() const {
4640 return &Arg;
4641 }
4642 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004643
4644
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004645 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004646
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004647 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4648 unsigned Index)
4649 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004650
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004651 TemplateArgumentLocContainerIterator &operator++() {
4652 ++Index;
4653 return *this;
4654 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004655
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004656 TemplateArgumentLocContainerIterator operator++(int) {
4657 TemplateArgumentLocContainerIterator Old(*this);
4658 ++(*this);
4659 return Old;
4660 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004661
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004662 TemplateArgumentLoc operator*() const {
4663 return Container->getArgLoc(Index);
4664 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004665
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004666 pointer operator->() const {
4667 return pointer(Container->getArgLoc(Index));
4668 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004669
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004670 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004671 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004672 return X.Container == Y.Container && X.Index == Y.Index;
4673 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004674
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004675 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004676 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004677 return !(X == Y);
4678 }
4679 };
4680}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004681
4682
John McCall43fed0d2010-11-12 08:19:04 +00004683template <typename Derived>
4684QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4685 TypeLocBuilder &TLB,
4686 TemplateSpecializationTypeLoc TL,
4687 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004688 TemplateArgumentListInfo NewTemplateArgs;
4689 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4690 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004691 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4692 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004693 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004694 ArgIterator(TL, TL.getNumArgs()),
4695 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004696 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004697
John McCall833ca992009-10-29 08:12:44 +00004698 // FIXME: maybe don't rebuild if all the template arguments are the same.
4699
4700 QualType Result =
4701 getDerived().RebuildTemplateSpecializationType(Template,
4702 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004703 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004704
4705 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004706 // Specializations of template template parameters are represented as
4707 // TemplateSpecializationTypes, and substitution of type alias templates
4708 // within a dependent context can transform them into
4709 // DependentTemplateSpecializationTypes.
4710 if (isa<DependentTemplateSpecializationType>(Result)) {
4711 DependentTemplateSpecializationTypeLoc NewTL
4712 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004713 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004714 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004715 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004716 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004717 NewTL.setLAngleLoc(TL.getLAngleLoc());
4718 NewTL.setRAngleLoc(TL.getRAngleLoc());
4719 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4720 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4721 return Result;
4722 }
4723
John McCall833ca992009-10-29 08:12:44 +00004724 TemplateSpecializationTypeLoc NewTL
4725 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004726 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004727 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4728 NewTL.setLAngleLoc(TL.getLAngleLoc());
4729 NewTL.setRAngleLoc(TL.getRAngleLoc());
4730 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4731 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004732 }
Mike Stump1eb44332009-09-09 15:08:12 +00004733
John McCall833ca992009-10-29 08:12:44 +00004734 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004735}
Mike Stump1eb44332009-09-09 15:08:12 +00004736
Douglas Gregora88f09f2011-02-28 17:23:35 +00004737template <typename Derived>
4738QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4739 TypeLocBuilder &TLB,
4740 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004741 TemplateName Template,
4742 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004743 TemplateArgumentListInfo NewTemplateArgs;
4744 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4745 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4746 typedef TemplateArgumentLocContainerIterator<
4747 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004748 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004749 ArgIterator(TL, TL.getNumArgs()),
4750 NewTemplateArgs))
4751 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004752
Douglas Gregora88f09f2011-02-28 17:23:35 +00004753 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004754
Douglas Gregora88f09f2011-02-28 17:23:35 +00004755 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4756 QualType Result
4757 = getSema().Context.getDependentTemplateSpecializationType(
4758 TL.getTypePtr()->getKeyword(),
4759 DTN->getQualifier(),
4760 DTN->getIdentifier(),
4761 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004762
Douglas Gregora88f09f2011-02-28 17:23:35 +00004763 DependentTemplateSpecializationTypeLoc NewTL
4764 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004765 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004766 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004767 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004768 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004769 NewTL.setLAngleLoc(TL.getLAngleLoc());
4770 NewTL.setRAngleLoc(TL.getRAngleLoc());
4771 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4772 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4773 return Result;
4774 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004775
4776 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004777 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004778 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004779 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004780
Douglas Gregora88f09f2011-02-28 17:23:35 +00004781 if (!Result.isNull()) {
4782 /// FIXME: Wrap this in an elaborated-type-specifier?
4783 TemplateSpecializationTypeLoc NewTL
4784 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004785 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004786 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004787 NewTL.setLAngleLoc(TL.getLAngleLoc());
4788 NewTL.setRAngleLoc(TL.getRAngleLoc());
4789 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4790 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4791 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004792
Douglas Gregora88f09f2011-02-28 17:23:35 +00004793 return Result;
4794}
4795
Mike Stump1eb44332009-09-09 15:08:12 +00004796template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004797QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004798TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004799 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004800 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004801
Douglas Gregor9e876872011-03-01 18:12:44 +00004802 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004803 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004804 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004805 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004806 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4807 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004808 return QualType();
4809 }
Mike Stump1eb44332009-09-09 15:08:12 +00004810
John McCall43fed0d2010-11-12 08:19:04 +00004811 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4812 if (NamedT.isNull())
4813 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004814
Richard Smith3e4c6c42011-05-05 21:57:07 +00004815 // C++0x [dcl.type.elab]p2:
4816 // If the identifier resolves to a typedef-name or the simple-template-id
4817 // resolves to an alias template specialization, the
4818 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004819 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4820 if (const TemplateSpecializationType *TST =
4821 NamedT->getAs<TemplateSpecializationType>()) {
4822 TemplateName Template = TST->getTemplateName();
4823 if (TypeAliasTemplateDecl *TAT =
4824 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4825 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4826 diag::err_tag_reference_non_tag) << 4;
4827 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4828 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004829 }
4830 }
4831
John McCalla2becad2009-10-21 00:40:46 +00004832 QualType Result = TL.getType();
4833 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004834 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004835 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004836 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004837 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004838 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004839 if (Result.isNull())
4840 return QualType();
4841 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004842
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004843 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004844 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004845 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004846 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004847}
Mike Stump1eb44332009-09-09 15:08:12 +00004848
4849template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004850QualType TreeTransform<Derived>::TransformAttributedType(
4851 TypeLocBuilder &TLB,
4852 AttributedTypeLoc TL) {
4853 const AttributedType *oldType = TL.getTypePtr();
4854 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4855 if (modifiedType.isNull())
4856 return QualType();
4857
4858 QualType result = TL.getType();
4859
4860 // FIXME: dependent operand expressions?
4861 if (getDerived().AlwaysRebuild() ||
4862 modifiedType != oldType->getModifiedType()) {
4863 // TODO: this is really lame; we should really be rebuilding the
4864 // equivalent type from first principles.
4865 QualType equivalentType
4866 = getDerived().TransformType(oldType->getEquivalentType());
4867 if (equivalentType.isNull())
4868 return QualType();
4869 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4870 modifiedType,
4871 equivalentType);
4872 }
4873
4874 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4875 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4876 if (TL.hasAttrOperand())
4877 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4878 if (TL.hasAttrExprOperand())
4879 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4880 else if (TL.hasAttrEnumOperand())
4881 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4882
4883 return result;
4884}
4885
4886template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004887QualType
4888TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4889 ParenTypeLoc TL) {
4890 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4891 if (Inner.isNull())
4892 return QualType();
4893
4894 QualType Result = TL.getType();
4895 if (getDerived().AlwaysRebuild() ||
4896 Inner != TL.getInnerLoc().getType()) {
4897 Result = getDerived().RebuildParenType(Inner);
4898 if (Result.isNull())
4899 return QualType();
4900 }
4901
4902 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4903 NewTL.setLParenLoc(TL.getLParenLoc());
4904 NewTL.setRParenLoc(TL.getRParenLoc());
4905 return Result;
4906}
4907
4908template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004909QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004910 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004911 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004912
Douglas Gregor2494dd02011-03-01 01:34:45 +00004913 NestedNameSpecifierLoc QualifierLoc
4914 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4915 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004916 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004917
John McCall33500952010-06-11 00:33:02 +00004918 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004919 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004920 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004921 QualifierLoc,
4922 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004923 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004924 if (Result.isNull())
4925 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004926
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004927 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4928 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004929 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4930
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004931 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004932 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004933 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004934 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004935 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004936 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004937 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004938 NewTL.setNameLoc(TL.getNameLoc());
4939 }
John McCalla2becad2009-10-21 00:40:46 +00004940 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004941}
Mike Stump1eb44332009-09-09 15:08:12 +00004942
Douglas Gregor577f75a2009-08-04 16:50:30 +00004943template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004944QualType TreeTransform<Derived>::
4945 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004946 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004947 NestedNameSpecifierLoc QualifierLoc;
4948 if (TL.getQualifierLoc()) {
4949 QualifierLoc
4950 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4951 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004952 return QualType();
4953 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004954
John McCall43fed0d2010-11-12 08:19:04 +00004955 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004956 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004957}
4958
4959template<typename Derived>
4960QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004961TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4962 DependentTemplateSpecializationTypeLoc TL,
4963 NestedNameSpecifierLoc QualifierLoc) {
4964 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004965
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004966 TemplateArgumentListInfo NewTemplateArgs;
4967 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4968 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004969
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004970 typedef TemplateArgumentLocContainerIterator<
4971 DependentTemplateSpecializationTypeLoc> ArgIterator;
4972 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4973 ArgIterator(TL, TL.getNumArgs()),
4974 NewTemplateArgs))
4975 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004976
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004977 QualType Result
4978 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4979 QualifierLoc,
4980 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004981 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004982 NewTemplateArgs);
4983 if (Result.isNull())
4984 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004985
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004986 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4987 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004988
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004989 // Copy information relevant to the template specialization.
4990 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004991 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004992 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004993 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004994 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4995 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004996 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004997 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004998
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004999 // Copy information relevant to the elaborated type.
5000 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005001 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005002 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005003 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5004 DependentTemplateSpecializationTypeLoc SpecTL
5005 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005006 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005007 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005008 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005009 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005010 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5011 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005012 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005013 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005014 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005015 TemplateSpecializationTypeLoc SpecTL
5016 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005017 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005018 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005019 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5020 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005021 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005022 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005023 }
5024 return Result;
5025}
5026
5027template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005028QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5029 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005030 QualType Pattern
5031 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005032 if (Pattern.isNull())
5033 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005034
5035 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005036 if (getDerived().AlwaysRebuild() ||
5037 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005038 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005039 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005040 TL.getEllipsisLoc(),
5041 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005042 if (Result.isNull())
5043 return QualType();
5044 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005045
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005046 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5047 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5048 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005049}
5050
5051template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005052QualType
5053TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005054 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005055 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005056 TLB.pushFullCopy(TL);
5057 return TL.getType();
5058}
5059
5060template<typename Derived>
5061QualType
5062TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005063 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005064 // ObjCObjectType is never dependent.
5065 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005066 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005067}
Mike Stump1eb44332009-09-09 15:08:12 +00005068
5069template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005070QualType
5071TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005072 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005073 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005074 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005075 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005076}
5077
Douglas Gregor577f75a2009-08-04 16:50:30 +00005078//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005079// Statement transformation
5080//===----------------------------------------------------------------------===//
5081template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005082StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005083TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005084 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005085}
5086
5087template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005088StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005089TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5090 return getDerived().TransformCompoundStmt(S, false);
5091}
5092
5093template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005094StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005095TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005096 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005097 Sema::CompoundScopeRAII CompoundScope(getSema());
5098
John McCall7114cba2010-08-27 19:56:05 +00005099 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005100 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005101 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00005102 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5103 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005104 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005105 if (Result.isInvalid()) {
5106 // Immediately fail if this was a DeclStmt, since it's very
5107 // likely that this will cause problems for future statements.
5108 if (isa<DeclStmt>(*B))
5109 return StmtError();
5110
5111 // Otherwise, just keep processing substatements and fail later.
5112 SubStmtInvalid = true;
5113 continue;
5114 }
Mike Stump1eb44332009-09-09 15:08:12 +00005115
Douglas Gregor43959a92009-08-20 07:17:43 +00005116 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5117 Statements.push_back(Result.takeAs<Stmt>());
5118 }
Mike Stump1eb44332009-09-09 15:08:12 +00005119
John McCall7114cba2010-08-27 19:56:05 +00005120 if (SubStmtInvalid)
5121 return StmtError();
5122
Douglas Gregor43959a92009-08-20 07:17:43 +00005123 if (!getDerived().AlwaysRebuild() &&
5124 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005125 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005126
5127 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5128 move_arg(Statements),
5129 S->getRBracLoc(),
5130 IsStmtExpr);
5131}
Mike Stump1eb44332009-09-09 15:08:12 +00005132
Douglas Gregor43959a92009-08-20 07:17:43 +00005133template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005134StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005135TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005136 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005137 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005138 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5139 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005140
Eli Friedman264c1f82009-11-19 03:14:00 +00005141 // Transform the left-hand case value.
5142 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005143 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005144 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005145 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005146
Eli Friedman264c1f82009-11-19 03:14:00 +00005147 // Transform the right-hand case value (for the GNU case-range extension).
5148 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005149 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005150 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005151 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005152 }
Mike Stump1eb44332009-09-09 15:08:12 +00005153
Douglas Gregor43959a92009-08-20 07:17:43 +00005154 // Build the case statement.
5155 // Case statements are always rebuilt so that they will attached to their
5156 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005157 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005158 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005159 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005160 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005161 S->getColonLoc());
5162 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005163 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005164
Douglas Gregor43959a92009-08-20 07:17:43 +00005165 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005166 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005167 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005168 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005169
Douglas Gregor43959a92009-08-20 07:17:43 +00005170 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005171 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005172}
5173
5174template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005175StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005176TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005177 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005178 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005179 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005180 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005181
Douglas Gregor43959a92009-08-20 07:17:43 +00005182 // Default statements are always rebuilt
5183 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005184 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005185}
Mike Stump1eb44332009-09-09 15:08:12 +00005186
Douglas Gregor43959a92009-08-20 07:17:43 +00005187template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005188StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005189TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005190 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005191 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005192 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005193
Chris Lattner57ad3782011-02-17 20:34:02 +00005194 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5195 S->getDecl());
5196 if (!LD)
5197 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005198
5199
Douglas Gregor43959a92009-08-20 07:17:43 +00005200 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005201 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005202 cast<LabelDecl>(LD), SourceLocation(),
5203 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005204}
Mike Stump1eb44332009-09-09 15:08:12 +00005205
Douglas Gregor43959a92009-08-20 07:17:43 +00005206template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005207StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005208TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5209 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5210 if (SubStmt.isInvalid())
5211 return StmtError();
5212
5213 // TODO: transform attributes
5214 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5215 return S;
5216
5217 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5218 S->getAttrs(),
5219 SubStmt.get());
5220}
5221
5222template<typename Derived>
5223StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005224TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005225 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005226 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005227 VarDecl *ConditionVar = 0;
5228 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005229 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005230 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005231 getDerived().TransformDefinition(
5232 S->getConditionVariable()->getLocation(),
5233 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005234 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005235 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005236 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005237 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005238
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005239 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005240 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005241
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005242 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005243 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005244 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005245 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005246 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005247 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005248
John McCall9ae2f072010-08-23 23:25:46 +00005249 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005250 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005251 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005252
John McCall9ae2f072010-08-23 23:25:46 +00005253 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5254 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005255 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005256
Douglas Gregor43959a92009-08-20 07:17:43 +00005257 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005258 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005259 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005260 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005261
Douglas Gregor43959a92009-08-20 07:17:43 +00005262 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005263 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005264 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005265 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005266
Douglas Gregor43959a92009-08-20 07:17:43 +00005267 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005268 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005269 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005270 Then.get() == S->getThen() &&
5271 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005272 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005273
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005274 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005275 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005276 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005277}
5278
5279template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005280StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005281TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005282 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005283 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005284 VarDecl *ConditionVar = 0;
5285 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005286 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005287 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005288 getDerived().TransformDefinition(
5289 S->getConditionVariable()->getLocation(),
5290 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005291 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005292 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005293 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005294 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005295
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005296 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005297 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005298 }
Mike Stump1eb44332009-09-09 15:08:12 +00005299
Douglas Gregor43959a92009-08-20 07:17:43 +00005300 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005301 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005302 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005303 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005304 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005305 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005306
Douglas Gregor43959a92009-08-20 07:17:43 +00005307 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005308 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005309 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005310 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005311
Douglas Gregor43959a92009-08-20 07:17:43 +00005312 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005313 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5314 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005315}
Mike Stump1eb44332009-09-09 15:08:12 +00005316
Douglas Gregor43959a92009-08-20 07:17:43 +00005317template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005318StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005319TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005320 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005321 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005322 VarDecl *ConditionVar = 0;
5323 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005324 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005325 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005326 getDerived().TransformDefinition(
5327 S->getConditionVariable()->getLocation(),
5328 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005329 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005330 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005331 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005332 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005333
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005334 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005335 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005336
5337 if (S->getCond()) {
5338 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005339 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005340 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005341 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005342 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005343 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005344 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005345 }
Mike Stump1eb44332009-09-09 15:08:12 +00005346
John McCall9ae2f072010-08-23 23:25:46 +00005347 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5348 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005349 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005350
Douglas Gregor43959a92009-08-20 07:17:43 +00005351 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005352 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005353 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005354 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005355
Douglas Gregor43959a92009-08-20 07:17:43 +00005356 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005357 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005358 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005359 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005360 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005361
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005362 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005363 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005364}
Mike Stump1eb44332009-09-09 15:08:12 +00005365
Douglas Gregor43959a92009-08-20 07:17:43 +00005366template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005367StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005368TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005369 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005370 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005371 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005372 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005373
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005374 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005375 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005376 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005377 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005378
Douglas Gregor43959a92009-08-20 07:17:43 +00005379 if (!getDerived().AlwaysRebuild() &&
5380 Cond.get() == S->getCond() &&
5381 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005382 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005383
John McCall9ae2f072010-08-23 23:25:46 +00005384 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5385 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005386 S->getRParenLoc());
5387}
Mike Stump1eb44332009-09-09 15:08:12 +00005388
Douglas Gregor43959a92009-08-20 07:17:43 +00005389template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005390StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005391TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005392 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005393 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005394 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005395 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005396
Douglas Gregor43959a92009-08-20 07:17:43 +00005397 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005398 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005399 VarDecl *ConditionVar = 0;
5400 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005401 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005402 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005403 getDerived().TransformDefinition(
5404 S->getConditionVariable()->getLocation(),
5405 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005406 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005407 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005408 } else {
5409 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005410
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005411 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005412 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005413
5414 if (S->getCond()) {
5415 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005416 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005417 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005418 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005419 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005420
John McCall9ae2f072010-08-23 23:25:46 +00005421 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005422 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005423 }
Mike Stump1eb44332009-09-09 15:08:12 +00005424
Chad Rosier4a9d7952012-08-08 18:46:20 +00005425 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005426 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005427 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005428
Douglas Gregor43959a92009-08-20 07:17:43 +00005429 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005430 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005431 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005432 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005433
John McCall9ae2f072010-08-23 23:25:46 +00005434 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5435 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005436 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005437
Douglas Gregor43959a92009-08-20 07:17:43 +00005438 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005439 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005440 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005441 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005442
Douglas Gregor43959a92009-08-20 07:17:43 +00005443 if (!getDerived().AlwaysRebuild() &&
5444 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005445 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005446 Inc.get() == S->getInc() &&
5447 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005448 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005449
Douglas Gregor43959a92009-08-20 07:17:43 +00005450 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005451 Init.get(), FullCond, ConditionVar,
5452 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005453}
5454
5455template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005456StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005457TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005458 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5459 S->getLabel());
5460 if (!LD)
5461 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005462
Douglas Gregor43959a92009-08-20 07:17:43 +00005463 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005464 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005465 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005466}
5467
5468template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005469StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005470TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005471 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005472 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005473 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005474 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005475
Douglas Gregor43959a92009-08-20 07:17:43 +00005476 if (!getDerived().AlwaysRebuild() &&
5477 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005478 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005479
5480 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005481 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005482}
5483
5484template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005485StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005486TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005487 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005488}
Mike Stump1eb44332009-09-09 15:08:12 +00005489
Douglas Gregor43959a92009-08-20 07:17:43 +00005490template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005491StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005492TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005493 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005494}
Mike Stump1eb44332009-09-09 15:08:12 +00005495
Douglas Gregor43959a92009-08-20 07:17:43 +00005496template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005497StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005498TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005499 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005500 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005501 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005502
Mike Stump1eb44332009-09-09 15:08:12 +00005503 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005504 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005505 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005506}
Mike Stump1eb44332009-09-09 15:08:12 +00005507
Douglas Gregor43959a92009-08-20 07:17:43 +00005508template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005509StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005510TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005511 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005512 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005513 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5514 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005515 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5516 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005517 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005518 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005519
Douglas Gregor43959a92009-08-20 07:17:43 +00005520 if (Transformed != *D)
5521 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005522
Douglas Gregor43959a92009-08-20 07:17:43 +00005523 Decls.push_back(Transformed);
5524 }
Mike Stump1eb44332009-09-09 15:08:12 +00005525
Douglas Gregor43959a92009-08-20 07:17:43 +00005526 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005527 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005528
5529 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005530 S->getStartLoc(), S->getEndLoc());
5531}
Mike Stump1eb44332009-09-09 15:08:12 +00005532
Douglas Gregor43959a92009-08-20 07:17:43 +00005533template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005534StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005535TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005536
John McCallca0408f2010-08-23 06:44:23 +00005537 ASTOwningVector<Expr*> Constraints(getSema());
5538 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005539 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005540
John McCall60d7b3a2010-08-24 06:29:42 +00005541 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005542 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005543
5544 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005545
Anders Carlsson703e3942010-01-24 05:50:09 +00005546 // Go through the outputs.
5547 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005548 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005549
Anders Carlsson703e3942010-01-24 05:50:09 +00005550 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005551 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005552
Anders Carlsson703e3942010-01-24 05:50:09 +00005553 // Transform the output expr.
5554 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005555 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005556 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005557 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005558
Anders Carlsson703e3942010-01-24 05:50:09 +00005559 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005560
John McCall9ae2f072010-08-23 23:25:46 +00005561 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005562 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005563
Anders Carlsson703e3942010-01-24 05:50:09 +00005564 // Go through the inputs.
5565 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005566 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005567
Anders Carlsson703e3942010-01-24 05:50:09 +00005568 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005569 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005570
Anders Carlsson703e3942010-01-24 05:50:09 +00005571 // Transform the input expr.
5572 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005573 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005574 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005575 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005576
Anders Carlsson703e3942010-01-24 05:50:09 +00005577 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005578
John McCall9ae2f072010-08-23 23:25:46 +00005579 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005580 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005581
Anders Carlsson703e3942010-01-24 05:50:09 +00005582 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005583 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005584
5585 // Go through the clobbers.
5586 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005587 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005588
5589 // No need to transform the asm string literal.
5590 AsmString = SemaRef.Owned(S->getAsmString());
5591
5592 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5593 S->isSimple(),
5594 S->isVolatile(),
5595 S->getNumOutputs(),
5596 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005597 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005598 move_arg(Constraints),
5599 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005600 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005601 move_arg(Clobbers),
Chad Rosierdf4ee102012-08-20 17:11:53 +00005602 S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005603}
5604
Chad Rosier8cd64b42012-06-11 20:47:18 +00005605template<typename Derived>
5606StmtResult
5607TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005608 ArrayRef<Token> AsmToks =
5609 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005610
Chad Rosier7bd092b2012-08-15 16:53:30 +00005611 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5612 AsmToks, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005613}
Douglas Gregor43959a92009-08-20 07:17:43 +00005614
5615template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005616StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005617TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005618 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005619 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005620 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005621 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005622
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005623 // Transform the @catch statements (if present).
5624 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005625 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005626 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005627 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005628 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005629 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005630 if (Catch.get() != S->getCatchStmt(I))
5631 AnyCatchChanged = true;
5632 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005633 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005634
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005635 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005636 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005637 if (S->getFinallyStmt()) {
5638 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5639 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005640 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005641 }
5642
5643 // If nothing changed, just retain this statement.
5644 if (!getDerived().AlwaysRebuild() &&
5645 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005646 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005647 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005648 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005649
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005650 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005651 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5652 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005653}
Mike Stump1eb44332009-09-09 15:08:12 +00005654
Douglas Gregor43959a92009-08-20 07:17:43 +00005655template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005656StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005657TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005658 // Transform the @catch parameter, if there is one.
5659 VarDecl *Var = 0;
5660 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5661 TypeSourceInfo *TSInfo = 0;
5662 if (FromVar->getTypeSourceInfo()) {
5663 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5664 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005665 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005666 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005667
Douglas Gregorbe270a02010-04-26 17:57:08 +00005668 QualType T;
5669 if (TSInfo)
5670 T = TSInfo->getType();
5671 else {
5672 T = getDerived().TransformType(FromVar->getType());
5673 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005674 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005675 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005676
Douglas Gregorbe270a02010-04-26 17:57:08 +00005677 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5678 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005679 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005680 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005681
John McCall60d7b3a2010-08-24 06:29:42 +00005682 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005683 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005684 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005685
5686 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005687 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005688 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005689}
Mike Stump1eb44332009-09-09 15:08:12 +00005690
Douglas Gregor43959a92009-08-20 07:17:43 +00005691template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005692StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005693TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005694 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005695 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005696 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005697 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005698
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005699 // If nothing changed, just retain this statement.
5700 if (!getDerived().AlwaysRebuild() &&
5701 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005702 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005703
5704 // Build a new statement.
5705 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005706 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005707}
Mike Stump1eb44332009-09-09 15:08:12 +00005708
Douglas Gregor43959a92009-08-20 07:17:43 +00005709template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005710StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005711TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005712 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005713 if (S->getThrowExpr()) {
5714 Operand = getDerived().TransformExpr(S->getThrowExpr());
5715 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005716 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005717 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005718
Douglas Gregord1377b22010-04-22 21:44:01 +00005719 if (!getDerived().AlwaysRebuild() &&
5720 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005721 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005722
John McCall9ae2f072010-08-23 23:25:46 +00005723 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005724}
Mike Stump1eb44332009-09-09 15:08:12 +00005725
Douglas Gregor43959a92009-08-20 07:17:43 +00005726template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005727StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005728TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005729 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005730 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005731 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005732 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005733 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005734 Object =
5735 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5736 Object.get());
5737 if (Object.isInvalid())
5738 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005739
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005740 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005741 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005742 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005743 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005744
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005745 // If nothing change, just retain the current statement.
5746 if (!getDerived().AlwaysRebuild() &&
5747 Object.get() == S->getSynchExpr() &&
5748 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005749 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005750
5751 // Build a new statement.
5752 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005753 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005754}
5755
5756template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005757StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005758TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5759 ObjCAutoreleasePoolStmt *S) {
5760 // Transform the body.
5761 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5762 if (Body.isInvalid())
5763 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005764
John McCallf85e1932011-06-15 23:02:42 +00005765 // If nothing changed, just retain this statement.
5766 if (!getDerived().AlwaysRebuild() &&
5767 Body.get() == S->getSubStmt())
5768 return SemaRef.Owned(S);
5769
5770 // Build a new statement.
5771 return getDerived().RebuildObjCAutoreleasePoolStmt(
5772 S->getAtLoc(), Body.get());
5773}
5774
5775template<typename Derived>
5776StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005777TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005778 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005779 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005780 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005781 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005782 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005783
Douglas Gregorc3203e72010-04-22 23:10:45 +00005784 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005785 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005786 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005787 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005788
Douglas Gregorc3203e72010-04-22 23:10:45 +00005789 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005790 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005791 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005792 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005793
Douglas Gregorc3203e72010-04-22 23:10:45 +00005794 // If nothing changed, just retain this statement.
5795 if (!getDerived().AlwaysRebuild() &&
5796 Element.get() == S->getElement() &&
5797 Collection.get() == S->getCollection() &&
5798 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005799 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005800
Douglas Gregorc3203e72010-04-22 23:10:45 +00005801 // Build a new statement.
5802 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005803 Element.get(),
5804 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005805 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005806 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005807}
5808
5809
5810template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005811StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005812TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5813 // Transform the exception declaration, if any.
5814 VarDecl *Var = 0;
5815 if (S->getExceptionDecl()) {
5816 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005817 TypeSourceInfo *T = getDerived().TransformType(
5818 ExceptionDecl->getTypeSourceInfo());
5819 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005820 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005821
Douglas Gregor83cb9422010-09-09 17:09:21 +00005822 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005823 ExceptionDecl->getInnerLocStart(),
5824 ExceptionDecl->getLocation(),
5825 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005826 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005827 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005828 }
Mike Stump1eb44332009-09-09 15:08:12 +00005829
Douglas Gregor43959a92009-08-20 07:17:43 +00005830 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005831 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005832 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005833 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005834
Douglas Gregor43959a92009-08-20 07:17:43 +00005835 if (!getDerived().AlwaysRebuild() &&
5836 !Var &&
5837 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005838 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005839
5840 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5841 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005842 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005843}
Mike Stump1eb44332009-09-09 15:08:12 +00005844
Douglas Gregor43959a92009-08-20 07:17:43 +00005845template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005846StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005847TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5848 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005849 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005850 = getDerived().TransformCompoundStmt(S->getTryBlock());
5851 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005852 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005853
Douglas Gregor43959a92009-08-20 07:17:43 +00005854 // Transform the handlers.
5855 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005856 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005857 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005858 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005859 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5860 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005861 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005862
Douglas Gregor43959a92009-08-20 07:17:43 +00005863 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5864 Handlers.push_back(Handler.takeAs<Stmt>());
5865 }
Mike Stump1eb44332009-09-09 15:08:12 +00005866
Douglas Gregor43959a92009-08-20 07:17:43 +00005867 if (!getDerived().AlwaysRebuild() &&
5868 TryBlock.get() == S->getTryBlock() &&
5869 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005870 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005871
John McCall9ae2f072010-08-23 23:25:46 +00005872 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005873 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005874}
Mike Stump1eb44332009-09-09 15:08:12 +00005875
Richard Smithad762fc2011-04-14 22:09:26 +00005876template<typename Derived>
5877StmtResult
5878TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5879 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5880 if (Range.isInvalid())
5881 return StmtError();
5882
5883 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5884 if (BeginEnd.isInvalid())
5885 return StmtError();
5886
5887 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5888 if (Cond.isInvalid())
5889 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005890 if (Cond.get())
5891 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5892 if (Cond.isInvalid())
5893 return StmtError();
5894 if (Cond.get())
5895 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005896
5897 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5898 if (Inc.isInvalid())
5899 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005900 if (Inc.get())
5901 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005902
5903 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5904 if (LoopVar.isInvalid())
5905 return StmtError();
5906
5907 StmtResult NewStmt = S;
5908 if (getDerived().AlwaysRebuild() ||
5909 Range.get() != S->getRangeStmt() ||
5910 BeginEnd.get() != S->getBeginEndStmt() ||
5911 Cond.get() != S->getCond() ||
5912 Inc.get() != S->getInc() ||
5913 LoopVar.get() != S->getLoopVarStmt())
5914 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5915 S->getColonLoc(), Range.get(),
5916 BeginEnd.get(), Cond.get(),
5917 Inc.get(), LoopVar.get(),
5918 S->getRParenLoc());
5919
5920 StmtResult Body = getDerived().TransformStmt(S->getBody());
5921 if (Body.isInvalid())
5922 return StmtError();
5923
5924 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5925 // it now so we have a new statement to attach the body to.
5926 if (Body.get() != S->getBody() && NewStmt.get() == S)
5927 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5928 S->getColonLoc(), Range.get(),
5929 BeginEnd.get(), Cond.get(),
5930 Inc.get(), LoopVar.get(),
5931 S->getRParenLoc());
5932
5933 if (NewStmt.get() == S)
5934 return SemaRef.Owned(S);
5935
5936 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5937}
5938
John Wiegley28bbe4b2011-04-28 01:08:34 +00005939template<typename Derived>
5940StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005941TreeTransform<Derived>::TransformMSDependentExistsStmt(
5942 MSDependentExistsStmt *S) {
5943 // Transform the nested-name-specifier, if any.
5944 NestedNameSpecifierLoc QualifierLoc;
5945 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005946 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005947 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5948 if (!QualifierLoc)
5949 return StmtError();
5950 }
5951
5952 // Transform the declaration name.
5953 DeclarationNameInfo NameInfo = S->getNameInfo();
5954 if (NameInfo.getName()) {
5955 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5956 if (!NameInfo.getName())
5957 return StmtError();
5958 }
5959
5960 // Check whether anything changed.
5961 if (!getDerived().AlwaysRebuild() &&
5962 QualifierLoc == S->getQualifierLoc() &&
5963 NameInfo.getName() == S->getNameInfo().getName())
5964 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005965
Douglas Gregorba0513d2011-10-25 01:33:02 +00005966 // Determine whether this name exists, if we can.
5967 CXXScopeSpec SS;
5968 SS.Adopt(QualifierLoc);
5969 bool Dependent = false;
5970 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5971 case Sema::IER_Exists:
5972 if (S->isIfExists())
5973 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005974
Douglas Gregorba0513d2011-10-25 01:33:02 +00005975 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5976
5977 case Sema::IER_DoesNotExist:
5978 if (S->isIfNotExists())
5979 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005980
Douglas Gregorba0513d2011-10-25 01:33:02 +00005981 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005982
Douglas Gregorba0513d2011-10-25 01:33:02 +00005983 case Sema::IER_Dependent:
5984 Dependent = true;
5985 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005986
Douglas Gregor65019ac2011-10-25 03:44:56 +00005987 case Sema::IER_Error:
5988 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005989 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005990
Douglas Gregorba0513d2011-10-25 01:33:02 +00005991 // We need to continue with the instantiation, so do so now.
5992 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5993 if (SubStmt.isInvalid())
5994 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005995
Douglas Gregorba0513d2011-10-25 01:33:02 +00005996 // If we have resolved the name, just transform to the substatement.
5997 if (!Dependent)
5998 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005999
Douglas Gregorba0513d2011-10-25 01:33:02 +00006000 // The name is still dependent, so build a dependent expression again.
6001 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6002 S->isIfExists(),
6003 QualifierLoc,
6004 NameInfo,
6005 SubStmt.get());
6006}
6007
6008template<typename Derived>
6009StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006010TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6011 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6012 if(TryBlock.isInvalid()) return StmtError();
6013
6014 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6015 if(!getDerived().AlwaysRebuild() &&
6016 TryBlock.get() == S->getTryBlock() &&
6017 Handler.get() == S->getHandler())
6018 return SemaRef.Owned(S);
6019
6020 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6021 S->getTryLoc(),
6022 TryBlock.take(),
6023 Handler.take());
6024}
6025
6026template<typename Derived>
6027StmtResult
6028TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6029 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6030 if(Block.isInvalid()) return StmtError();
6031
6032 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6033 Block.take());
6034}
6035
6036template<typename Derived>
6037StmtResult
6038TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6039 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6040 if(FilterExpr.isInvalid()) return StmtError();
6041
6042 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6043 if(Block.isInvalid()) return StmtError();
6044
6045 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6046 FilterExpr.take(),
6047 Block.take());
6048}
6049
6050template<typename Derived>
6051StmtResult
6052TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6053 if(isa<SEHFinallyStmt>(Handler))
6054 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6055 else
6056 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6057}
6058
Douglas Gregor43959a92009-08-20 07:17:43 +00006059//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006060// Expression transformation
6061//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006062template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006063ExprResult
John McCall454feb92009-12-08 09:21:05 +00006064TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006065 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006066}
Mike Stump1eb44332009-09-09 15:08:12 +00006067
6068template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006069ExprResult
John McCall454feb92009-12-08 09:21:05 +00006070TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006071 NestedNameSpecifierLoc QualifierLoc;
6072 if (E->getQualifierLoc()) {
6073 QualifierLoc
6074 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6075 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006076 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006077 }
John McCalldbd872f2009-12-08 09:08:17 +00006078
6079 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006080 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6081 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006082 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006083 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006084
John McCallec8045d2010-08-17 21:27:17 +00006085 DeclarationNameInfo NameInfo = E->getNameInfo();
6086 if (NameInfo.getName()) {
6087 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6088 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006089 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006090 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006091
6092 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006093 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006094 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006095 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006096 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006097
6098 // Mark it referenced in the new context regardless.
6099 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006100 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006101
John McCall3fa5cae2010-10-26 07:05:15 +00006102 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006103 }
John McCalldbd872f2009-12-08 09:08:17 +00006104
6105 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006106 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006107 TemplateArgs = &TransArgs;
6108 TransArgs.setLAngleLoc(E->getLAngleLoc());
6109 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006110 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6111 E->getNumTemplateArgs(),
6112 TransArgs))
6113 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006114 }
6115
Chad Rosier4a9d7952012-08-08 18:46:20 +00006116 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006117 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006118}
Mike Stump1eb44332009-09-09 15:08:12 +00006119
Douglas Gregorb98b1992009-08-11 05:31:07 +00006120template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006121ExprResult
John McCall454feb92009-12-08 09:21:05 +00006122TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006123 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006124}
Mike Stump1eb44332009-09-09 15:08:12 +00006125
Douglas Gregorb98b1992009-08-11 05:31:07 +00006126template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006127ExprResult
John McCall454feb92009-12-08 09:21:05 +00006128TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006129 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006130}
Mike Stump1eb44332009-09-09 15:08:12 +00006131
Douglas Gregorb98b1992009-08-11 05:31:07 +00006132template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006133ExprResult
John McCall454feb92009-12-08 09:21:05 +00006134TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006135 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006136}
Mike Stump1eb44332009-09-09 15:08:12 +00006137
Douglas Gregorb98b1992009-08-11 05:31:07 +00006138template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006139ExprResult
John McCall454feb92009-12-08 09:21:05 +00006140TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006141 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006142}
Mike Stump1eb44332009-09-09 15:08:12 +00006143
Douglas Gregorb98b1992009-08-11 05:31:07 +00006144template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006145ExprResult
John McCall454feb92009-12-08 09:21:05 +00006146TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006147 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006148}
6149
6150template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006151ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006152TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6153 return SemaRef.MaybeBindToTemporary(E);
6154}
6155
6156template<typename Derived>
6157ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006158TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6159 ExprResult ControllingExpr =
6160 getDerived().TransformExpr(E->getControllingExpr());
6161 if (ControllingExpr.isInvalid())
6162 return ExprError();
6163
Chris Lattner686775d2011-07-20 06:58:45 +00006164 SmallVector<Expr *, 4> AssocExprs;
6165 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006166 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6167 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6168 if (TS) {
6169 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6170 if (!AssocType)
6171 return ExprError();
6172 AssocTypes.push_back(AssocType);
6173 } else {
6174 AssocTypes.push_back(0);
6175 }
6176
6177 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6178 if (AssocExpr.isInvalid())
6179 return ExprError();
6180 AssocExprs.push_back(AssocExpr.release());
6181 }
6182
6183 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6184 E->getDefaultLoc(),
6185 E->getRParenLoc(),
6186 ControllingExpr.release(),
6187 AssocTypes.data(),
6188 AssocExprs.data(),
6189 E->getNumAssocs());
6190}
6191
6192template<typename Derived>
6193ExprResult
John McCall454feb92009-12-08 09:21:05 +00006194TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006195 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006196 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006197 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006198
Douglas Gregorb98b1992009-08-11 05:31:07 +00006199 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006200 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006201
John McCall9ae2f072010-08-23 23:25:46 +00006202 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006203 E->getRParen());
6204}
6205
Mike Stump1eb44332009-09-09 15:08:12 +00006206template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006207ExprResult
John McCall454feb92009-12-08 09:21:05 +00006208TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006209 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006210 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006211 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006212
Douglas Gregorb98b1992009-08-11 05:31:07 +00006213 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006214 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006215
Douglas Gregorb98b1992009-08-11 05:31:07 +00006216 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6217 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006218 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006219}
Mike Stump1eb44332009-09-09 15:08:12 +00006220
Douglas Gregorb98b1992009-08-11 05:31:07 +00006221template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006222ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006223TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6224 // Transform the type.
6225 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6226 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006227 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006228
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006229 // Transform all of the components into components similar to what the
6230 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006231 // FIXME: It would be slightly more efficient in the non-dependent case to
6232 // just map FieldDecls, rather than requiring the rebuilder to look for
6233 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006234 // template code that we don't care.
6235 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006236 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006237 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006238 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006239 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6240 const Node &ON = E->getComponent(I);
6241 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006242 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006243 Comp.LocStart = ON.getSourceRange().getBegin();
6244 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006245 switch (ON.getKind()) {
6246 case Node::Array: {
6247 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006248 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006249 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006250 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006251
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006252 ExprChanged = ExprChanged || Index.get() != FromIndex;
6253 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006254 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006255 break;
6256 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006257
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006258 case Node::Field:
6259 case Node::Identifier:
6260 Comp.isBrackets = false;
6261 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006262 if (!Comp.U.IdentInfo)
6263 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006264
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006265 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006266
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006267 case Node::Base:
6268 // Will be recomputed during the rebuild.
6269 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006270 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006271
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006272 Components.push_back(Comp);
6273 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006274
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006275 // If nothing changed, retain the existing expression.
6276 if (!getDerived().AlwaysRebuild() &&
6277 Type == E->getTypeSourceInfo() &&
6278 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006279 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006280
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006281 // Build a new offsetof expression.
6282 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6283 Components.data(), Components.size(),
6284 E->getRParenLoc());
6285}
6286
6287template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006288ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006289TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6290 assert(getDerived().AlreadyTransformed(E->getType()) &&
6291 "opaque value expression requires transformation");
6292 return SemaRef.Owned(E);
6293}
6294
6295template<typename Derived>
6296ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006297TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006298 // Rebuild the syntactic form. The original syntactic form has
6299 // opaque-value expressions in it, so strip those away and rebuild
6300 // the result. This is a really awful way of doing this, but the
6301 // better solution (rebuilding the semantic expressions and
6302 // rebinding OVEs as necessary) doesn't work; we'd need
6303 // TreeTransform to not strip away implicit conversions.
6304 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6305 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006306 if (result.isInvalid()) return ExprError();
6307
6308 // If that gives us a pseudo-object result back, the pseudo-object
6309 // expression must have been an lvalue-to-rvalue conversion which we
6310 // should reapply.
6311 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6312 result = SemaRef.checkPseudoObjectRValue(result.take());
6313
6314 return result;
6315}
6316
6317template<typename Derived>
6318ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006319TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6320 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006321 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006322 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006323
John McCalla93c9342009-12-07 02:54:59 +00006324 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006325 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006326 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006327
John McCall5ab75172009-11-04 07:28:41 +00006328 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006329 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006330
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006331 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6332 E->getKind(),
6333 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006334 }
Mike Stump1eb44332009-09-09 15:08:12 +00006335
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006336 // C++0x [expr.sizeof]p1:
6337 // The operand is either an expression, which is an unevaluated operand
6338 // [...]
6339 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006340
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006341 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6342 if (SubExpr.isInvalid())
6343 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006344
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006345 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6346 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006347
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006348 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6349 E->getOperatorLoc(),
6350 E->getKind(),
6351 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006352}
Mike Stump1eb44332009-09-09 15:08:12 +00006353
Douglas Gregorb98b1992009-08-11 05:31:07 +00006354template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006355ExprResult
John McCall454feb92009-12-08 09:21:05 +00006356TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006357 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006358 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006359 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006360
John McCall60d7b3a2010-08-24 06:29:42 +00006361 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006362 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006363 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006364
6365
Douglas Gregorb98b1992009-08-11 05:31:07 +00006366 if (!getDerived().AlwaysRebuild() &&
6367 LHS.get() == E->getLHS() &&
6368 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006369 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006370
John McCall9ae2f072010-08-23 23:25:46 +00006371 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006372 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006373 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006374 E->getRBracketLoc());
6375}
Mike Stump1eb44332009-09-09 15:08:12 +00006376
6377template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006378ExprResult
John McCall454feb92009-12-08 09:21:05 +00006379TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006380 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006381 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006382 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006383 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006384
6385 // Transform arguments.
6386 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006387 ASTOwningVector<Expr*> Args(SemaRef);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006388 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006389 &ArgChanged))
6390 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006391
Douglas Gregorb98b1992009-08-11 05:31:07 +00006392 if (!getDerived().AlwaysRebuild() &&
6393 Callee.get() == E->getCallee() &&
6394 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006395 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006396
Douglas Gregorb98b1992009-08-11 05:31:07 +00006397 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006398 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006399 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006400 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006401 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006402 E->getRParenLoc());
6403}
Mike Stump1eb44332009-09-09 15:08:12 +00006404
6405template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006406ExprResult
John McCall454feb92009-12-08 09:21:05 +00006407TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006408 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006409 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006410 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006411
Douglas Gregor40d96a62011-02-28 21:54:11 +00006412 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006413 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006414 QualifierLoc
6415 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006416
Douglas Gregor40d96a62011-02-28 21:54:11 +00006417 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006418 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006419 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006420 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006421
Eli Friedmanf595cc42009-12-04 06:40:45 +00006422 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006423 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6424 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006425 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006426 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006427
John McCall6bb80172010-03-30 21:47:33 +00006428 NamedDecl *FoundDecl = E->getFoundDecl();
6429 if (FoundDecl == E->getMemberDecl()) {
6430 FoundDecl = Member;
6431 } else {
6432 FoundDecl = cast_or_null<NamedDecl>(
6433 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6434 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006435 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006436 }
6437
Douglas Gregorb98b1992009-08-11 05:31:07 +00006438 if (!getDerived().AlwaysRebuild() &&
6439 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006440 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006441 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006442 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006443 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006444
Anders Carlsson1f240322009-12-22 05:24:09 +00006445 // Mark it referenced in the new context regardless.
6446 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006447 SemaRef.MarkMemberReferenced(E);
6448
John McCall3fa5cae2010-10-26 07:05:15 +00006449 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006450 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006451
John McCalld5532b62009-11-23 01:53:49 +00006452 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006453 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006454 TransArgs.setLAngleLoc(E->getLAngleLoc());
6455 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006456 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6457 E->getNumTemplateArgs(),
6458 TransArgs))
6459 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006460 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006461
Douglas Gregorb98b1992009-08-11 05:31:07 +00006462 // FIXME: Bogus source location for the operator
6463 SourceLocation FakeOperatorLoc
6464 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6465
John McCallc2233c52010-01-15 08:34:02 +00006466 // FIXME: to do this check properly, we will need to preserve the
6467 // first-qualifier-in-scope here, just in case we had a dependent
6468 // base (and therefore couldn't do the check) and a
6469 // nested-name-qualifier (and therefore could do the lookup).
6470 NamedDecl *FirstQualifierInScope = 0;
6471
John McCall9ae2f072010-08-23 23:25:46 +00006472 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006473 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006474 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006475 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006476 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006477 Member,
John McCall6bb80172010-03-30 21:47:33 +00006478 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006479 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006480 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006481 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006482}
Mike Stump1eb44332009-09-09 15:08:12 +00006483
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006485ExprResult
John McCall454feb92009-12-08 09:21:05 +00006486TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006487 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006488 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006489 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006490
John McCall60d7b3a2010-08-24 06:29:42 +00006491 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006492 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006493 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006494
Douglas Gregorb98b1992009-08-11 05:31:07 +00006495 if (!getDerived().AlwaysRebuild() &&
6496 LHS.get() == E->getLHS() &&
6497 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006498 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006499
Douglas Gregorb98b1992009-08-11 05:31:07 +00006500 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006501 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006502}
6503
Mike Stump1eb44332009-09-09 15:08:12 +00006504template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006505ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006506TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006507 CompoundAssignOperator *E) {
6508 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006509}
Mike Stump1eb44332009-09-09 15:08:12 +00006510
Douglas Gregorb98b1992009-08-11 05:31:07 +00006511template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006512ExprResult TreeTransform<Derived>::
6513TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6514 // Just rebuild the common and RHS expressions and see whether we
6515 // get any changes.
6516
6517 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6518 if (commonExpr.isInvalid())
6519 return ExprError();
6520
6521 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6522 if (rhs.isInvalid())
6523 return ExprError();
6524
6525 if (!getDerived().AlwaysRebuild() &&
6526 commonExpr.get() == e->getCommon() &&
6527 rhs.get() == e->getFalseExpr())
6528 return SemaRef.Owned(e);
6529
6530 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6531 e->getQuestionLoc(),
6532 0,
6533 e->getColonLoc(),
6534 rhs.get());
6535}
6536
6537template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006538ExprResult
John McCall454feb92009-12-08 09:21:05 +00006539TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006540 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006541 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006542 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006543
John McCall60d7b3a2010-08-24 06:29:42 +00006544 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006545 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006546 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006547
John McCall60d7b3a2010-08-24 06:29:42 +00006548 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006549 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006550 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006551
Douglas Gregorb98b1992009-08-11 05:31:07 +00006552 if (!getDerived().AlwaysRebuild() &&
6553 Cond.get() == E->getCond() &&
6554 LHS.get() == E->getLHS() &&
6555 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006556 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006557
John McCall9ae2f072010-08-23 23:25:46 +00006558 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006559 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006560 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006561 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006562 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006563}
Mike Stump1eb44332009-09-09 15:08:12 +00006564
6565template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006566ExprResult
John McCall454feb92009-12-08 09:21:05 +00006567TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006568 // Implicit casts are eliminated during transformation, since they
6569 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006570 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006571}
Mike Stump1eb44332009-09-09 15:08:12 +00006572
Douglas Gregorb98b1992009-08-11 05:31:07 +00006573template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006574ExprResult
John McCall454feb92009-12-08 09:21:05 +00006575TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006576 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6577 if (!Type)
6578 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006579
John McCall60d7b3a2010-08-24 06:29:42 +00006580 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006581 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006582 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006583 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006584
Douglas Gregorb98b1992009-08-11 05:31:07 +00006585 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006586 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006587 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006588 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006589
John McCall9d125032010-01-15 18:39:57 +00006590 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006591 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006592 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006593 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006594}
Mike Stump1eb44332009-09-09 15:08:12 +00006595
Douglas Gregorb98b1992009-08-11 05:31:07 +00006596template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006597ExprResult
John McCall454feb92009-12-08 09:21:05 +00006598TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006599 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6600 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6601 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006602 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006603
John McCall60d7b3a2010-08-24 06:29:42 +00006604 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006605 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006606 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006607
Douglas Gregorb98b1992009-08-11 05:31:07 +00006608 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006609 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006610 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006611 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006612
John McCall1d7d8d62010-01-19 22:33:45 +00006613 // Note: the expression type doesn't necessarily match the
6614 // type-as-written, but that's okay, because it should always be
6615 // derivable from the initializer.
6616
John McCall42f56b52010-01-18 19:35:47 +00006617 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006618 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006619 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006620}
Mike Stump1eb44332009-09-09 15:08:12 +00006621
Douglas Gregorb98b1992009-08-11 05:31:07 +00006622template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006623ExprResult
John McCall454feb92009-12-08 09:21:05 +00006624TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006625 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006626 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006627 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006628
Douglas Gregorb98b1992009-08-11 05:31:07 +00006629 if (!getDerived().AlwaysRebuild() &&
6630 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006631 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006632
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006634 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006636 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006637 E->getAccessorLoc(),
6638 E->getAccessor());
6639}
Mike Stump1eb44332009-09-09 15:08:12 +00006640
Douglas Gregorb98b1992009-08-11 05:31:07 +00006641template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006642ExprResult
John McCall454feb92009-12-08 09:21:05 +00006643TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006644 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006645
John McCallca0408f2010-08-23 06:44:23 +00006646 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006647 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006648 Inits, &InitChanged))
6649 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006650
Douglas Gregorb98b1992009-08-11 05:31:07 +00006651 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006652 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006653
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006655 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006656}
Mike Stump1eb44332009-09-09 15:08:12 +00006657
Douglas Gregorb98b1992009-08-11 05:31:07 +00006658template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006659ExprResult
John McCall454feb92009-12-08 09:21:05 +00006660TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006661 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006662
Douglas Gregor43959a92009-08-20 07:17:43 +00006663 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006664 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006665 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006666 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006667
Douglas Gregor43959a92009-08-20 07:17:43 +00006668 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006669 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006670 bool ExprChanged = false;
6671 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6672 DEnd = E->designators_end();
6673 D != DEnd; ++D) {
6674 if (D->isFieldDesignator()) {
6675 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6676 D->getDotLoc(),
6677 D->getFieldLoc()));
6678 continue;
6679 }
Mike Stump1eb44332009-09-09 15:08:12 +00006680
Douglas Gregorb98b1992009-08-11 05:31:07 +00006681 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006682 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006683 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006684 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006685
6686 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006687 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006688
Douglas Gregorb98b1992009-08-11 05:31:07 +00006689 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6690 ArrayExprs.push_back(Index.release());
6691 continue;
6692 }
Mike Stump1eb44332009-09-09 15:08:12 +00006693
Douglas Gregorb98b1992009-08-11 05:31:07 +00006694 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006695 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006696 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6697 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006698 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006699
John McCall60d7b3a2010-08-24 06:29:42 +00006700 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006701 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006702 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006703
6704 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006705 End.get(),
6706 D->getLBracketLoc(),
6707 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006708
Douglas Gregorb98b1992009-08-11 05:31:07 +00006709 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6710 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006711
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712 ArrayExprs.push_back(Start.release());
6713 ArrayExprs.push_back(End.release());
6714 }
Mike Stump1eb44332009-09-09 15:08:12 +00006715
Douglas Gregorb98b1992009-08-11 05:31:07 +00006716 if (!getDerived().AlwaysRebuild() &&
6717 Init.get() == E->getInit() &&
6718 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006719 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006720
Douglas Gregorb98b1992009-08-11 05:31:07 +00006721 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6722 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006723 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006724}
Mike Stump1eb44332009-09-09 15:08:12 +00006725
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006727ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006728TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006729 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006730 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006731
Douglas Gregor5557b252009-10-28 00:29:27 +00006732 // FIXME: Will we ever have proper type location here? Will we actually
6733 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006734 QualType T = getDerived().TransformType(E->getType());
6735 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006736 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006737
Douglas Gregorb98b1992009-08-11 05:31:07 +00006738 if (!getDerived().AlwaysRebuild() &&
6739 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006740 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006741
Douglas Gregorb98b1992009-08-11 05:31:07 +00006742 return getDerived().RebuildImplicitValueInitExpr(T);
6743}
Mike Stump1eb44332009-09-09 15:08:12 +00006744
Douglas Gregorb98b1992009-08-11 05:31:07 +00006745template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006746ExprResult
John McCall454feb92009-12-08 09:21:05 +00006747TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006748 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6749 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006750 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006751
John McCall60d7b3a2010-08-24 06:29:42 +00006752 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006753 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006754 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006755
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006757 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006758 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006759 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006760
John McCall9ae2f072010-08-23 23:25:46 +00006761 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006762 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006763}
6764
6765template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006766ExprResult
John McCall454feb92009-12-08 09:21:05 +00006767TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006768 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006769 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006770 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6771 &ArgumentChanged))
6772 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006773
Douglas Gregorb98b1992009-08-11 05:31:07 +00006774 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6775 move_arg(Inits),
6776 E->getRParenLoc());
6777}
Mike Stump1eb44332009-09-09 15:08:12 +00006778
Douglas Gregorb98b1992009-08-11 05:31:07 +00006779/// \brief Transform an address-of-label expression.
6780///
6781/// By default, the transformation of an address-of-label expression always
6782/// rebuilds the expression, so that the label identifier can be resolved to
6783/// the corresponding label statement by semantic analysis.
6784template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006785ExprResult
John McCall454feb92009-12-08 09:21:05 +00006786TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006787 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6788 E->getLabel());
6789 if (!LD)
6790 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006791
Douglas Gregorb98b1992009-08-11 05:31:07 +00006792 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006793 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006794}
Mike Stump1eb44332009-09-09 15:08:12 +00006795
6796template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006797ExprResult
John McCall454feb92009-12-08 09:21:05 +00006798TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006799 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006800 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006801 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006802 if (SubStmt.isInvalid()) {
6803 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006804 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006805 }
Mike Stump1eb44332009-09-09 15:08:12 +00006806
Douglas Gregorb98b1992009-08-11 05:31:07 +00006807 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006808 SubStmt.get() == E->getSubStmt()) {
6809 // Calling this an 'error' is unintuitive, but it does the right thing.
6810 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006811 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006812 }
Mike Stump1eb44332009-09-09 15:08:12 +00006813
6814 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006815 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006816 E->getRParenLoc());
6817}
Mike Stump1eb44332009-09-09 15:08:12 +00006818
Douglas Gregorb98b1992009-08-11 05:31:07 +00006819template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006820ExprResult
John McCall454feb92009-12-08 09:21:05 +00006821TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006822 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006823 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006824 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006825
John McCall60d7b3a2010-08-24 06:29:42 +00006826 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006827 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006828 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006829
John McCall60d7b3a2010-08-24 06:29:42 +00006830 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006831 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006832 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006833
Douglas Gregorb98b1992009-08-11 05:31:07 +00006834 if (!getDerived().AlwaysRebuild() &&
6835 Cond.get() == E->getCond() &&
6836 LHS.get() == E->getLHS() &&
6837 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006838 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006839
Douglas Gregorb98b1992009-08-11 05:31:07 +00006840 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006841 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006842 E->getRParenLoc());
6843}
Mike Stump1eb44332009-09-09 15:08:12 +00006844
Douglas Gregorb98b1992009-08-11 05:31:07 +00006845template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006846ExprResult
John McCall454feb92009-12-08 09:21:05 +00006847TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006848 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006849}
6850
6851template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006852ExprResult
John McCall454feb92009-12-08 09:21:05 +00006853TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006854 switch (E->getOperator()) {
6855 case OO_New:
6856 case OO_Delete:
6857 case OO_Array_New:
6858 case OO_Array_Delete:
6859 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006860
Douglas Gregor668d6d92009-12-13 20:44:55 +00006861 case OO_Call: {
6862 // This is a call to an object's operator().
6863 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6864
6865 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006866 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006867 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006868 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006869
6870 // FIXME: Poor location information
6871 SourceLocation FakeLParenLoc
6872 = SemaRef.PP.getLocForEndOfToken(
6873 static_cast<Expr *>(Object.get())->getLocEnd());
6874
6875 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006876 ASTOwningVector<Expr*> Args(SemaRef);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006877 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006878 Args))
6879 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006880
John McCall9ae2f072010-08-23 23:25:46 +00006881 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006882 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006883 E->getLocEnd());
6884 }
6885
6886#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6887 case OO_##Name:
6888#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6889#include "clang/Basic/OperatorKinds.def"
6890 case OO_Subscript:
6891 // Handled below.
6892 break;
6893
6894 case OO_Conditional:
6895 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006896
6897 case OO_None:
6898 case NUM_OVERLOADED_OPERATORS:
6899 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006900 }
6901
John McCall60d7b3a2010-08-24 06:29:42 +00006902 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006903 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006904 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006905
John McCall60d7b3a2010-08-24 06:29:42 +00006906 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006907 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006908 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006909
John McCall60d7b3a2010-08-24 06:29:42 +00006910 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006911 if (E->getNumArgs() == 2) {
6912 Second = getDerived().TransformExpr(E->getArg(1));
6913 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006914 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006915 }
Mike Stump1eb44332009-09-09 15:08:12 +00006916
Douglas Gregorb98b1992009-08-11 05:31:07 +00006917 if (!getDerived().AlwaysRebuild() &&
6918 Callee.get() == E->getCallee() &&
6919 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006920 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006921 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006922
Douglas Gregorb98b1992009-08-11 05:31:07 +00006923 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6924 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006925 Callee.get(),
6926 First.get(),
6927 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006928}
Mike Stump1eb44332009-09-09 15:08:12 +00006929
Douglas Gregorb98b1992009-08-11 05:31:07 +00006930template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006931ExprResult
John McCall454feb92009-12-08 09:21:05 +00006932TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6933 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006934}
Mike Stump1eb44332009-09-09 15:08:12 +00006935
Douglas Gregorb98b1992009-08-11 05:31:07 +00006936template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006937ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006938TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6939 // Transform the callee.
6940 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6941 if (Callee.isInvalid())
6942 return ExprError();
6943
6944 // Transform exec config.
6945 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6946 if (EC.isInvalid())
6947 return ExprError();
6948
6949 // Transform arguments.
6950 bool ArgChanged = false;
6951 ASTOwningVector<Expr*> Args(SemaRef);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006952 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006953 &ArgChanged))
6954 return ExprError();
6955
6956 if (!getDerived().AlwaysRebuild() &&
6957 Callee.get() == E->getCallee() &&
6958 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006959 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006960
6961 // FIXME: Wrong source location information for the '('.
6962 SourceLocation FakeLParenLoc
6963 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6964 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6965 move_arg(Args),
6966 E->getRParenLoc(), EC.get());
6967}
6968
6969template<typename Derived>
6970ExprResult
John McCall454feb92009-12-08 09:21:05 +00006971TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006972 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6973 if (!Type)
6974 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006975
John McCall60d7b3a2010-08-24 06:29:42 +00006976 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006977 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006978 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006979 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006980
Douglas Gregorb98b1992009-08-11 05:31:07 +00006981 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006982 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006983 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006984 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006985
Douglas Gregorb98b1992009-08-11 05:31:07 +00006986 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006987 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006988 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6989 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6990 SourceLocation FakeRParenLoc
6991 = SemaRef.PP.getLocForEndOfToken(
6992 E->getSubExpr()->getSourceRange().getEnd());
6993 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006994 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006995 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006996 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006997 FakeRAngleLoc,
6998 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006999 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007000 FakeRParenLoc);
7001}
Mike Stump1eb44332009-09-09 15:08:12 +00007002
Douglas Gregorb98b1992009-08-11 05:31:07 +00007003template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007004ExprResult
John McCall454feb92009-12-08 09:21:05 +00007005TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7006 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007007}
Mike Stump1eb44332009-09-09 15:08:12 +00007008
7009template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007010ExprResult
John McCall454feb92009-12-08 09:21:05 +00007011TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7012 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007013}
7014
Douglas Gregorb98b1992009-08-11 05:31:07 +00007015template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007016ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007017TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007018 CXXReinterpretCastExpr *E) {
7019 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007020}
Mike Stump1eb44332009-09-09 15:08:12 +00007021
Douglas Gregorb98b1992009-08-11 05:31:07 +00007022template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007023ExprResult
John McCall454feb92009-12-08 09:21:05 +00007024TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7025 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007026}
Mike Stump1eb44332009-09-09 15:08:12 +00007027
Douglas Gregorb98b1992009-08-11 05:31:07 +00007028template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007029ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007030TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007031 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007032 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7033 if (!Type)
7034 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007035
John McCall60d7b3a2010-08-24 06:29:42 +00007036 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007037 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007038 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007039 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007040
Douglas Gregorb98b1992009-08-11 05:31:07 +00007041 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007042 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007043 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007044 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007045
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007046 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007047 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007048 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007049 E->getRParenLoc());
7050}
Mike Stump1eb44332009-09-09 15:08:12 +00007051
Douglas Gregorb98b1992009-08-11 05:31:07 +00007052template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007053ExprResult
John McCall454feb92009-12-08 09:21:05 +00007054TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007055 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007056 TypeSourceInfo *TInfo
7057 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7058 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007059 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007060
Douglas Gregorb98b1992009-08-11 05:31:07 +00007061 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007062 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007063 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007064
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007065 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7066 E->getLocStart(),
7067 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007068 E->getLocEnd());
7069 }
Mike Stump1eb44332009-09-09 15:08:12 +00007070
Eli Friedmanef331b72012-01-20 01:26:23 +00007071 // We don't know whether the subexpression is potentially evaluated until
7072 // after we perform semantic analysis. We speculatively assume it is
7073 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007074 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00007075 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00007076
John McCall60d7b3a2010-08-24 06:29:42 +00007077 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007078 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007079 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007080
Douglas Gregorb98b1992009-08-11 05:31:07 +00007081 if (!getDerived().AlwaysRebuild() &&
7082 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007083 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007084
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007085 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7086 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007087 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007088 E->getLocEnd());
7089}
7090
7091template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007092ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007093TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7094 if (E->isTypeOperand()) {
7095 TypeSourceInfo *TInfo
7096 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7097 if (!TInfo)
7098 return ExprError();
7099
7100 if (!getDerived().AlwaysRebuild() &&
7101 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007102 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007103
Douglas Gregor3c52a212011-03-06 17:40:41 +00007104 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007105 E->getLocStart(),
7106 TInfo,
7107 E->getLocEnd());
7108 }
7109
Francois Pichet01b7c302010-09-08 12:20:18 +00007110 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7111
7112 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7113 if (SubExpr.isInvalid())
7114 return ExprError();
7115
7116 if (!getDerived().AlwaysRebuild() &&
7117 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007118 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007119
7120 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7121 E->getLocStart(),
7122 SubExpr.get(),
7123 E->getLocEnd());
7124}
7125
7126template<typename Derived>
7127ExprResult
John McCall454feb92009-12-08 09:21:05 +00007128TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007129 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007130}
Mike Stump1eb44332009-09-09 15:08:12 +00007131
Douglas Gregorb98b1992009-08-11 05:31:07 +00007132template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007133ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007134TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007135 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007136 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007137}
Mike Stump1eb44332009-09-09 15:08:12 +00007138
Douglas Gregorb98b1992009-08-11 05:31:07 +00007139template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007140ExprResult
John McCall454feb92009-12-08 09:21:05 +00007141TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007142 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007143 QualType T;
7144 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7145 T = MD->getThisType(getSema().Context);
7146 else
7147 T = getSema().Context.getPointerType(
7148 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007149
Douglas Gregorec79d872012-02-24 17:41:38 +00007150 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7151 // Make sure that we capture 'this'.
7152 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007153 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007154 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007155
Douglas Gregor828a1972010-01-07 23:12:05 +00007156 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007157}
Mike Stump1eb44332009-09-09 15:08:12 +00007158
Douglas Gregorb98b1992009-08-11 05:31:07 +00007159template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007160ExprResult
John McCall454feb92009-12-08 09:21:05 +00007161TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007162 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007163 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007164 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007165
Douglas Gregorb98b1992009-08-11 05:31:07 +00007166 if (!getDerived().AlwaysRebuild() &&
7167 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007168 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007169
Douglas Gregorbca01b42011-07-06 22:04:06 +00007170 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7171 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007172}
Mike Stump1eb44332009-09-09 15:08:12 +00007173
Douglas Gregorb98b1992009-08-11 05:31:07 +00007174template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007175ExprResult
John McCall454feb92009-12-08 09:21:05 +00007176TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007177 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007178 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7179 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007180 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007181 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007182
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007183 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007184 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007185 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007186
Douglas Gregor036aed12009-12-23 23:03:06 +00007187 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007188}
Mike Stump1eb44332009-09-09 15:08:12 +00007189
Douglas Gregorb98b1992009-08-11 05:31:07 +00007190template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007191ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007192TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7193 CXXScalarValueInitExpr *E) {
7194 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7195 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007196 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007197
Douglas Gregorb98b1992009-08-11 05:31:07 +00007198 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007199 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007200 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007201
Chad Rosier4a9d7952012-08-08 18:46:20 +00007202 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007203 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007204 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007205}
Mike Stump1eb44332009-09-09 15:08:12 +00007206
Douglas Gregorb98b1992009-08-11 05:31:07 +00007207template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007208ExprResult
John McCall454feb92009-12-08 09:21:05 +00007209TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007210 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007211 TypeSourceInfo *AllocTypeInfo
7212 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7213 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007214 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007215
Douglas Gregorb98b1992009-08-11 05:31:07 +00007216 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007217 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007218 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007219 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007220
Douglas Gregorb98b1992009-08-11 05:31:07 +00007221 // Transform the placement arguments (if any).
7222 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007223 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007224 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007225 E->getNumPlacementArgs(), true,
7226 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007227 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007228
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007229 // Transform the initializer (if any).
7230 Expr *OldInit = E->getInitializer();
7231 ExprResult NewInit;
7232 if (OldInit)
7233 NewInit = getDerived().TransformExpr(OldInit);
7234 if (NewInit.isInvalid())
7235 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007236
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007237 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007238 FunctionDecl *OperatorNew = 0;
7239 if (E->getOperatorNew()) {
7240 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007241 getDerived().TransformDecl(E->getLocStart(),
7242 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007243 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007244 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007245 }
7246
7247 FunctionDecl *OperatorDelete = 0;
7248 if (E->getOperatorDelete()) {
7249 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007250 getDerived().TransformDecl(E->getLocStart(),
7251 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007252 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007253 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007254 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007255
Douglas Gregorb98b1992009-08-11 05:31:07 +00007256 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007257 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007258 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007259 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007260 OperatorNew == E->getOperatorNew() &&
7261 OperatorDelete == E->getOperatorDelete() &&
7262 !ArgumentChanged) {
7263 // Mark any declarations we need as referenced.
7264 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007265 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007266 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007267 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007268 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007269
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007270 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007271 QualType ElementType
7272 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7273 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7274 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7275 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007276 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007277 }
7278 }
7279 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007280
John McCall3fa5cae2010-10-26 07:05:15 +00007281 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007282 }
Mike Stump1eb44332009-09-09 15:08:12 +00007283
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007284 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007285 if (!ArraySize.get()) {
7286 // If no array size was specified, but the new expression was
7287 // instantiated with an array type (e.g., "new T" where T is
7288 // instantiated with "int[4]"), extract the outer bound from the
7289 // array type as our array size. We do this with constant and
7290 // dependently-sized array types.
7291 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7292 if (!ArrayT) {
7293 // Do nothing
7294 } else if (const ConstantArrayType *ConsArrayT
7295 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007296 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007297 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007298 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007299 SemaRef.Context.getSizeType(),
7300 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007301 AllocType = ConsArrayT->getElementType();
7302 } else if (const DependentSizedArrayType *DepArrayT
7303 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7304 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007305 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007306 AllocType = DepArrayT->getElementType();
7307 }
7308 }
7309 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007310
Douglas Gregorb98b1992009-08-11 05:31:07 +00007311 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7312 E->isGlobalNew(),
7313 /*FIXME:*/E->getLocStart(),
7314 move_arg(PlacementArgs),
7315 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007316 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007317 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007318 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007319 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007320 E->getDirectInitRange(),
7321 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007322}
Mike Stump1eb44332009-09-09 15:08:12 +00007323
Douglas Gregorb98b1992009-08-11 05:31:07 +00007324template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007325ExprResult
John McCall454feb92009-12-08 09:21:05 +00007326TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007327 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007328 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007329 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007330
Douglas Gregor1af74512010-02-26 00:38:10 +00007331 // Transform the delete operator, if known.
7332 FunctionDecl *OperatorDelete = 0;
7333 if (E->getOperatorDelete()) {
7334 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007335 getDerived().TransformDecl(E->getLocStart(),
7336 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007337 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007338 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007339 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007340
Douglas Gregorb98b1992009-08-11 05:31:07 +00007341 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007342 Operand.get() == E->getArgument() &&
7343 OperatorDelete == E->getOperatorDelete()) {
7344 // Mark any declarations we need as referenced.
7345 // FIXME: instantiation-specific.
7346 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007347 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007348
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007349 if (!E->getArgument()->isTypeDependent()) {
7350 QualType Destroyed = SemaRef.Context.getBaseElementType(
7351 E->getDestroyedType());
7352 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7353 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007354 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007355 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007356 }
7357 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007358
John McCall3fa5cae2010-10-26 07:05:15 +00007359 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007360 }
Mike Stump1eb44332009-09-09 15:08:12 +00007361
Douglas Gregorb98b1992009-08-11 05:31:07 +00007362 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7363 E->isGlobalDelete(),
7364 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007365 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007366}
Mike Stump1eb44332009-09-09 15:08:12 +00007367
Douglas Gregorb98b1992009-08-11 05:31:07 +00007368template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007369ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007370TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007371 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007372 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007373 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007374 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007375
John McCallb3d87482010-08-24 05:47:05 +00007376 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007377 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007378 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007379 E->getOperatorLoc(),
7380 E->isArrow()? tok::arrow : tok::period,
7381 ObjectTypePtr,
7382 MayBePseudoDestructor);
7383 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007384 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007385
John McCallb3d87482010-08-24 05:47:05 +00007386 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007387 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7388 if (QualifierLoc) {
7389 QualifierLoc
7390 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7391 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007392 return ExprError();
7393 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007394 CXXScopeSpec SS;
7395 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007396
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007397 PseudoDestructorTypeStorage Destroyed;
7398 if (E->getDestroyedTypeInfo()) {
7399 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007400 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007401 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007402 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007403 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007404 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007405 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007406 // We aren't likely to be able to resolve the identifier down to a type
7407 // now anyway, so just retain the identifier.
7408 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7409 E->getDestroyedTypeLoc());
7410 } else {
7411 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007412 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007413 *E->getDestroyedTypeIdentifier(),
7414 E->getDestroyedTypeLoc(),
7415 /*Scope=*/0,
7416 SS, ObjectTypePtr,
7417 false);
7418 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007419 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007420
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007421 Destroyed
7422 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7423 E->getDestroyedTypeLoc());
7424 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007425
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007426 TypeSourceInfo *ScopeTypeInfo = 0;
7427 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007428 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007429 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007430 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007431 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007432
John McCall9ae2f072010-08-23 23:25:46 +00007433 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007434 E->getOperatorLoc(),
7435 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007436 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007437 ScopeTypeInfo,
7438 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007439 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007440 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007441}
Mike Stump1eb44332009-09-09 15:08:12 +00007442
Douglas Gregora71d8192009-09-04 17:36:40 +00007443template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007444ExprResult
John McCallba135432009-11-21 08:51:07 +00007445TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007446 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007447 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7448 Sema::LookupOrdinaryName);
7449
7450 // Transform all the decls.
7451 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7452 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007453 NamedDecl *InstD = static_cast<NamedDecl*>(
7454 getDerived().TransformDecl(Old->getNameLoc(),
7455 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007456 if (!InstD) {
7457 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7458 // This can happen because of dependent hiding.
7459 if (isa<UsingShadowDecl>(*I))
7460 continue;
7461 else
John McCallf312b1e2010-08-26 23:41:50 +00007462 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007463 }
John McCallf7a1a742009-11-24 19:00:30 +00007464
7465 // Expand using declarations.
7466 if (isa<UsingDecl>(InstD)) {
7467 UsingDecl *UD = cast<UsingDecl>(InstD);
7468 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7469 E = UD->shadow_end(); I != E; ++I)
7470 R.addDecl(*I);
7471 continue;
7472 }
7473
7474 R.addDecl(InstD);
7475 }
7476
7477 // Resolve a kind, but don't do any further analysis. If it's
7478 // ambiguous, the callee needs to deal with it.
7479 R.resolveKind();
7480
7481 // Rebuild the nested-name qualifier, if present.
7482 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007483 if (Old->getQualifierLoc()) {
7484 NestedNameSpecifierLoc QualifierLoc
7485 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7486 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007487 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007488
Douglas Gregor4c9be892011-02-28 20:01:57 +00007489 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007490 }
7491
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007492 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007493 CXXRecordDecl *NamingClass
7494 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7495 Old->getNameLoc(),
7496 Old->getNamingClass()));
7497 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007498 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007499
Douglas Gregor66c45152010-04-27 16:10:10 +00007500 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007501 }
7502
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007503 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7504
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007505 // If we have neither explicit template arguments, nor the template keyword,
7506 // it's a normal declaration name.
7507 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007508 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7509
7510 // If we have template arguments, rebuild them, then rebuild the
7511 // templateid expression.
7512 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007513 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7514 Old->getNumTemplateArgs(),
7515 TransArgs))
7516 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007517
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007518 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007519 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007520}
Mike Stump1eb44332009-09-09 15:08:12 +00007521
Douglas Gregorb98b1992009-08-11 05:31:07 +00007522template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007523ExprResult
John McCall454feb92009-12-08 09:21:05 +00007524TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007525 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7526 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007527 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007528
Douglas Gregorb98b1992009-08-11 05:31:07 +00007529 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007530 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007531 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007532
Mike Stump1eb44332009-09-09 15:08:12 +00007533 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007534 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007535 T,
7536 E->getLocEnd());
7537}
Mike Stump1eb44332009-09-09 15:08:12 +00007538
Douglas Gregorb98b1992009-08-11 05:31:07 +00007539template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007540ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007541TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7542 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7543 if (!LhsT)
7544 return ExprError();
7545
7546 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7547 if (!RhsT)
7548 return ExprError();
7549
7550 if (!getDerived().AlwaysRebuild() &&
7551 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7552 return SemaRef.Owned(E);
7553
7554 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7555 E->getLocStart(),
7556 LhsT, RhsT,
7557 E->getLocEnd());
7558}
7559
7560template<typename Derived>
7561ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007562TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7563 bool ArgChanged = false;
7564 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7565 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7566 TypeSourceInfo *From = E->getArg(I);
7567 TypeLoc FromTL = From->getTypeLoc();
7568 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7569 TypeLocBuilder TLB;
7570 TLB.reserve(FromTL.getFullDataSize());
7571 QualType To = getDerived().TransformType(TLB, FromTL);
7572 if (To.isNull())
7573 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007574
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007575 if (To == From->getType())
7576 Args.push_back(From);
7577 else {
7578 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7579 ArgChanged = true;
7580 }
7581 continue;
7582 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007583
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007584 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007585
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007586 // We have a pack expansion. Instantiate it.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007587 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007588 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7589 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7590 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007591
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007592 // Determine whether the set of unexpanded parameter packs can and should
7593 // be expanded.
7594 bool Expand = true;
7595 bool RetainExpansion = false;
7596 llvm::Optional<unsigned> OrigNumExpansions
7597 = ExpansionTL.getTypePtr()->getNumExpansions();
7598 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7599 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7600 PatternTL.getSourceRange(),
7601 Unexpanded,
7602 Expand, RetainExpansion,
7603 NumExpansions))
7604 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007605
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007606 if (!Expand) {
7607 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007608 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007609 // expansion.
7610 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007611
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007612 TypeLocBuilder TLB;
7613 TLB.reserve(From->getTypeLoc().getFullDataSize());
7614
7615 QualType To = getDerived().TransformType(TLB, PatternTL);
7616 if (To.isNull())
7617 return ExprError();
7618
Chad Rosier4a9d7952012-08-08 18:46:20 +00007619 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007620 PatternTL.getSourceRange(),
7621 ExpansionTL.getEllipsisLoc(),
7622 NumExpansions);
7623 if (To.isNull())
7624 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007625
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007626 PackExpansionTypeLoc ToExpansionTL
7627 = TLB.push<PackExpansionTypeLoc>(To);
7628 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7629 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7630 continue;
7631 }
7632
7633 // Expand the pack expansion by substituting for each argument in the
7634 // pack(s).
7635 for (unsigned I = 0; I != *NumExpansions; ++I) {
7636 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7637 TypeLocBuilder TLB;
7638 TLB.reserve(PatternTL.getFullDataSize());
7639 QualType To = getDerived().TransformType(TLB, PatternTL);
7640 if (To.isNull())
7641 return ExprError();
7642
7643 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7644 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007645
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007646 if (!RetainExpansion)
7647 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007648
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007649 // If we're supposed to retain a pack expansion, do so by temporarily
7650 // forgetting the partially-substituted parameter pack.
7651 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7652
7653 TypeLocBuilder TLB;
7654 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007655
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007656 QualType To = getDerived().TransformType(TLB, PatternTL);
7657 if (To.isNull())
7658 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007659
7660 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007661 PatternTL.getSourceRange(),
7662 ExpansionTL.getEllipsisLoc(),
7663 NumExpansions);
7664 if (To.isNull())
7665 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007666
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007667 PackExpansionTypeLoc ToExpansionTL
7668 = TLB.push<PackExpansionTypeLoc>(To);
7669 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7670 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7671 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007672
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007673 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7674 return SemaRef.Owned(E);
7675
7676 return getDerived().RebuildTypeTrait(E->getTrait(),
7677 E->getLocStart(),
7678 Args,
7679 E->getLocEnd());
7680}
7681
7682template<typename Derived>
7683ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007684TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7685 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7686 if (!T)
7687 return ExprError();
7688
7689 if (!getDerived().AlwaysRebuild() &&
7690 T == E->getQueriedTypeSourceInfo())
7691 return SemaRef.Owned(E);
7692
7693 ExprResult SubExpr;
7694 {
7695 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7696 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7697 if (SubExpr.isInvalid())
7698 return ExprError();
7699
7700 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7701 return SemaRef.Owned(E);
7702 }
7703
7704 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7705 E->getLocStart(),
7706 T,
7707 SubExpr.get(),
7708 E->getLocEnd());
7709}
7710
7711template<typename Derived>
7712ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007713TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7714 ExprResult SubExpr;
7715 {
7716 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7717 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7718 if (SubExpr.isInvalid())
7719 return ExprError();
7720
7721 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7722 return SemaRef.Owned(E);
7723 }
7724
7725 return getDerived().RebuildExpressionTrait(
7726 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7727}
7728
7729template<typename Derived>
7730ExprResult
John McCall865d4472009-11-19 22:55:06 +00007731TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007732 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007733 NestedNameSpecifierLoc QualifierLoc
7734 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7735 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007736 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007737 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007738
John McCall43fed0d2010-11-12 08:19:04 +00007739 // TODO: If this is a conversion-function-id, verify that the
7740 // destination type name (if present) resolves the same way after
7741 // instantiation as it did in the local scope.
7742
Abramo Bagnara25777432010-08-11 22:01:17 +00007743 DeclarationNameInfo NameInfo
7744 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7745 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007746 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007747
John McCallf7a1a742009-11-24 19:00:30 +00007748 if (!E->hasExplicitTemplateArgs()) {
7749 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007750 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007751 // Note: it is sufficient to compare the Name component of NameInfo:
7752 // if name has not changed, DNLoc has not changed either.
7753 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007754 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007755
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007756 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007757 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007758 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007759 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007760 }
John McCalld5532b62009-11-23 01:53:49 +00007761
7762 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007763 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7764 E->getNumTemplateArgs(),
7765 TransArgs))
7766 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007767
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007768 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007769 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007770 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007771 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007772}
7773
7774template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007775ExprResult
John McCall454feb92009-12-08 09:21:05 +00007776TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007777 // CXXConstructExprs are always implicit, so when we have a
7778 // 1-argument construction we just transform that argument.
7779 if (E->getNumArgs() == 1 ||
7780 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7781 return getDerived().TransformExpr(E->getArg(0));
7782
Douglas Gregorb98b1992009-08-11 05:31:07 +00007783 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7784
7785 QualType T = getDerived().TransformType(E->getType());
7786 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007787 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007788
7789 CXXConstructorDecl *Constructor
7790 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007791 getDerived().TransformDecl(E->getLocStart(),
7792 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007793 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007794 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007795
Douglas Gregorb98b1992009-08-11 05:31:07 +00007796 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007797 ASTOwningVector<Expr*> Args(SemaRef);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007798 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007799 &ArgumentChanged))
7800 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007801
Douglas Gregorb98b1992009-08-11 05:31:07 +00007802 if (!getDerived().AlwaysRebuild() &&
7803 T == E->getType() &&
7804 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007805 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007806 // Mark the constructor as referenced.
7807 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007808 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007809 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007810 }
Mike Stump1eb44332009-09-09 15:08:12 +00007811
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007812 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7813 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007814 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007815 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007816 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007817 E->getConstructionKind(),
7818 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007819}
Mike Stump1eb44332009-09-09 15:08:12 +00007820
Douglas Gregorb98b1992009-08-11 05:31:07 +00007821/// \brief Transform a C++ temporary-binding expression.
7822///
Douglas Gregor51326552009-12-24 18:51:59 +00007823/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7824/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007825template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007826ExprResult
John McCall454feb92009-12-08 09:21:05 +00007827TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007828 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007829}
Mike Stump1eb44332009-09-09 15:08:12 +00007830
John McCall4765fa02010-12-06 08:20:24 +00007831/// \brief Transform a C++ expression that contains cleanups that should
7832/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007833///
John McCall4765fa02010-12-06 08:20:24 +00007834/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007835/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007836template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007837ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007838TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007839 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007840}
Mike Stump1eb44332009-09-09 15:08:12 +00007841
Douglas Gregorb98b1992009-08-11 05:31:07 +00007842template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007843ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007844TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007845 CXXTemporaryObjectExpr *E) {
7846 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7847 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007848 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007849
Douglas Gregorb98b1992009-08-11 05:31:07 +00007850 CXXConstructorDecl *Constructor
7851 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007852 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007853 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007854 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007855 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007856
Douglas Gregorb98b1992009-08-11 05:31:07 +00007857 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007858 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007859 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007860 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007861 &ArgumentChanged))
7862 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007863
Douglas Gregorb98b1992009-08-11 05:31:07 +00007864 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007865 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007866 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007867 !ArgumentChanged) {
7868 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007869 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007870 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007871 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007872
Douglas Gregorab6677e2010-09-08 00:15:04 +00007873 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7874 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007875 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007876 E->getLocEnd());
7877}
Mike Stump1eb44332009-09-09 15:08:12 +00007878
Douglas Gregorb98b1992009-08-11 05:31:07 +00007879template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007880ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007881TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007882 // Create the local class that will describe the lambda.
7883 CXXRecordDecl *Class
Douglas Gregorf54486a2012-04-04 17:40:10 +00007884 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7885 /*KnownDependent=*/false);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007886 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007887
Douglas Gregordfca6f52012-02-13 22:00:16 +00007888 // Transform the type of the lambda parameters and start the definition of
7889 // the lambda itself.
7890 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00007891 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00007892 if (!MethodTy)
7893 return ExprError();
7894
Douglas Gregorc6889e72012-02-14 22:28:59 +00007895 // Transform lambda parameters.
Douglas Gregorc6889e72012-02-14 22:28:59 +00007896 llvm::SmallVector<QualType, 4> ParamTypes;
7897 llvm::SmallVector<ParmVarDecl *, 4> Params;
7898 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7899 E->getCallOperator()->param_begin(),
7900 E->getCallOperator()->param_size(),
7901 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00007902 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00007903
Douglas Gregordfca6f52012-02-13 22:00:16 +00007904 // Build the call operator.
7905 CXXMethodDecl *CallOperator
7906 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007907 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007908 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007909 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007910 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00007911
Richard Smith612409e2012-07-25 03:56:55 +00007912 return getDerived().TransformLambdaScope(E, CallOperator);
7913}
7914
7915template<typename Derived>
7916ExprResult
7917TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
7918 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00007919 // Introduce the context of the call operator.
7920 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7921
Douglas Gregordfca6f52012-02-13 22:00:16 +00007922 // Enter the scope of the lambda.
7923 sema::LambdaScopeInfo *LSI
7924 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7925 E->getCaptureDefault(),
7926 E->hasExplicitParameters(),
7927 E->hasExplicitResultType(),
7928 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007929
Douglas Gregordfca6f52012-02-13 22:00:16 +00007930 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00007931 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00007932 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007933 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007934 CEnd = E->capture_end();
7935 C != CEnd; ++C) {
7936 // When we hit the first implicit capture, tell Sema that we've finished
7937 // the list of explicit captures.
7938 if (!FinishedExplicitCaptures && C->isImplicit()) {
7939 getSema().finishLambdaExplicitCaptures(LSI);
7940 FinishedExplicitCaptures = true;
7941 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007942
Douglas Gregordfca6f52012-02-13 22:00:16 +00007943 // Capturing 'this' is trivial.
7944 if (C->capturesThis()) {
7945 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7946 continue;
7947 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007948
Douglas Gregora7365242012-02-14 19:27:52 +00007949 // Determine the capture kind for Sema.
7950 Sema::TryCaptureKind Kind
7951 = C->isImplicit()? Sema::TryCapture_Implicit
7952 : C->getCaptureKind() == LCK_ByCopy
7953 ? Sema::TryCapture_ExplicitByVal
7954 : Sema::TryCapture_ExplicitByRef;
7955 SourceLocation EllipsisLoc;
7956 if (C->isPackExpansion()) {
7957 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7958 bool ShouldExpand = false;
7959 bool RetainExpansion = false;
7960 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007961 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7962 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00007963 Unexpanded,
7964 ShouldExpand, RetainExpansion,
7965 NumExpansions))
7966 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007967
Douglas Gregora7365242012-02-14 19:27:52 +00007968 if (ShouldExpand) {
7969 // The transform has determined that we should perform an expansion;
7970 // transform and capture each of the arguments.
7971 // expansion of the pattern. Do so.
7972 VarDecl *Pack = C->getCapturedVar();
7973 for (unsigned I = 0; I != *NumExpansions; ++I) {
7974 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7975 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00007976 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00007977 Pack));
7978 if (!CapturedVar) {
7979 Invalid = true;
7980 continue;
7981 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007982
Douglas Gregora7365242012-02-14 19:27:52 +00007983 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007984 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
7985 }
Douglas Gregora7365242012-02-14 19:27:52 +00007986 continue;
7987 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007988
Douglas Gregora7365242012-02-14 19:27:52 +00007989 EllipsisLoc = C->getEllipsisLoc();
7990 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007991
Douglas Gregordfca6f52012-02-13 22:00:16 +00007992 // Transform the captured variable.
7993 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00007994 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007995 C->getCapturedVar()));
7996 if (!CapturedVar) {
7997 Invalid = true;
7998 continue;
7999 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008000
Douglas Gregordfca6f52012-02-13 22:00:16 +00008001 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008002 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008003 }
8004 if (!FinishedExplicitCaptures)
8005 getSema().finishLambdaExplicitCaptures(LSI);
8006
Douglas Gregordfca6f52012-02-13 22:00:16 +00008007
8008 // Enter a new evaluation context to insulate the lambda from any
8009 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008010 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008011
8012 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008013 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008014 /*IsInstantiation=*/true);
8015 return ExprError();
8016 }
8017
8018 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008019 StmtResult Body = getDerived().TransformStmt(E->getBody());
8020 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008021 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008022 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008023 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008024 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008025
Chad Rosier4a9d7952012-08-08 18:46:20 +00008026 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008027 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008028}
8029
8030template<typename Derived>
8031ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008032TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008033 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008034 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8035 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008036 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008037
Douglas Gregorb98b1992009-08-11 05:31:07 +00008038 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008039 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008040 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008041 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008042 &ArgumentChanged))
8043 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008044
Douglas Gregorb98b1992009-08-11 05:31:07 +00008045 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008046 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008047 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008048 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008049
Douglas Gregorb98b1992009-08-11 05:31:07 +00008050 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008051 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008052 E->getLParenLoc(),
8053 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00008054 E->getRParenLoc());
8055}
Mike Stump1eb44332009-09-09 15:08:12 +00008056
Douglas Gregorb98b1992009-08-11 05:31:07 +00008057template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008058ExprResult
John McCall865d4472009-11-19 22:55:06 +00008059TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008060 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008061 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008062 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008063 Expr *OldBase;
8064 QualType BaseType;
8065 QualType ObjectType;
8066 if (!E->isImplicitAccess()) {
8067 OldBase = E->getBase();
8068 Base = getDerived().TransformExpr(OldBase);
8069 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008070 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008071
John McCallaa81e162009-12-01 22:10:20 +00008072 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008073 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008074 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008075 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008076 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008077 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008078 ObjectTy,
8079 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008080 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008081 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008082
John McCallb3d87482010-08-24 05:47:05 +00008083 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008084 BaseType = ((Expr*) Base.get())->getType();
8085 } else {
8086 OldBase = 0;
8087 BaseType = getDerived().TransformType(E->getBaseType());
8088 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8089 }
Mike Stump1eb44332009-09-09 15:08:12 +00008090
Douglas Gregor6cd21982009-10-20 05:58:46 +00008091 // Transform the first part of the nested-name-specifier that qualifies
8092 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008093 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008094 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008095 E->getFirstQualifierFoundInScope(),
8096 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008097
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008098 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008099 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008100 QualifierLoc
8101 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8102 ObjectType,
8103 FirstQualifierInScope);
8104 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008105 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008106 }
Mike Stump1eb44332009-09-09 15:08:12 +00008107
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008108 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8109
John McCall43fed0d2010-11-12 08:19:04 +00008110 // TODO: If this is a conversion-function-id, verify that the
8111 // destination type name (if present) resolves the same way after
8112 // instantiation as it did in the local scope.
8113
Abramo Bagnara25777432010-08-11 22:01:17 +00008114 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008115 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008116 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008117 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008118
John McCallaa81e162009-12-01 22:10:20 +00008119 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008120 // This is a reference to a member without an explicitly-specified
8121 // template argument list. Optimize for this common case.
8122 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008123 Base.get() == OldBase &&
8124 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008125 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008126 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008127 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008128 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008129
John McCall9ae2f072010-08-23 23:25:46 +00008130 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008131 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008132 E->isArrow(),
8133 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008134 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008135 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008136 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008137 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008138 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008139 }
8140
John McCalld5532b62009-11-23 01:53:49 +00008141 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008142 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8143 E->getNumTemplateArgs(),
8144 TransArgs))
8145 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008146
John McCall9ae2f072010-08-23 23:25:46 +00008147 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008148 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008149 E->isArrow(),
8150 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008151 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008152 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008153 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008154 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008155 &TransArgs);
8156}
8157
8158template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008159ExprResult
John McCall454feb92009-12-08 09:21:05 +00008160TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008161 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008162 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008163 QualType BaseType;
8164 if (!Old->isImplicitAccess()) {
8165 Base = getDerived().TransformExpr(Old->getBase());
8166 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008167 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008168 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8169 Old->isArrow());
8170 if (Base.isInvalid())
8171 return ExprError();
8172 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008173 } else {
8174 BaseType = getDerived().TransformType(Old->getBaseType());
8175 }
John McCall129e2df2009-11-30 22:42:35 +00008176
Douglas Gregor4c9be892011-02-28 20:01:57 +00008177 NestedNameSpecifierLoc QualifierLoc;
8178 if (Old->getQualifierLoc()) {
8179 QualifierLoc
8180 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8181 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008182 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008183 }
8184
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008185 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8186
Abramo Bagnara25777432010-08-11 22:01:17 +00008187 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008188 Sema::LookupOrdinaryName);
8189
8190 // Transform all the decls.
8191 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8192 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008193 NamedDecl *InstD = static_cast<NamedDecl*>(
8194 getDerived().TransformDecl(Old->getMemberLoc(),
8195 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008196 if (!InstD) {
8197 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8198 // This can happen because of dependent hiding.
8199 if (isa<UsingShadowDecl>(*I))
8200 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008201 else {
8202 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008203 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008204 }
John McCall9f54ad42009-12-10 09:41:52 +00008205 }
John McCall129e2df2009-11-30 22:42:35 +00008206
8207 // Expand using declarations.
8208 if (isa<UsingDecl>(InstD)) {
8209 UsingDecl *UD = cast<UsingDecl>(InstD);
8210 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8211 E = UD->shadow_end(); I != E; ++I)
8212 R.addDecl(*I);
8213 continue;
8214 }
8215
8216 R.addDecl(InstD);
8217 }
8218
8219 R.resolveKind();
8220
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008221 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008222 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008223 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008224 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008225 Old->getMemberLoc(),
8226 Old->getNamingClass()));
8227 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008228 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008229
Douglas Gregor66c45152010-04-27 16:10:10 +00008230 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008231 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008232
John McCall129e2df2009-11-30 22:42:35 +00008233 TemplateArgumentListInfo TransArgs;
8234 if (Old->hasExplicitTemplateArgs()) {
8235 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8236 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008237 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8238 Old->getNumTemplateArgs(),
8239 TransArgs))
8240 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008241 }
John McCallc2233c52010-01-15 08:34:02 +00008242
8243 // FIXME: to do this check properly, we will need to preserve the
8244 // first-qualifier-in-scope here, just in case we had a dependent
8245 // base (and therefore couldn't do the check) and a
8246 // nested-name-qualifier (and therefore could do the lookup).
8247 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008248
John McCall9ae2f072010-08-23 23:25:46 +00008249 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008250 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008251 Old->getOperatorLoc(),
8252 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008253 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008254 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008255 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008256 R,
8257 (Old->hasExplicitTemplateArgs()
8258 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008259}
8260
8261template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008262ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008263TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008264 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008265 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8266 if (SubExpr.isInvalid())
8267 return ExprError();
8268
8269 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008270 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008271
8272 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8273}
8274
8275template<typename Derived>
8276ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008277TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008278 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8279 if (Pattern.isInvalid())
8280 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008281
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008282 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8283 return SemaRef.Owned(E);
8284
Douglas Gregor67fd1252011-01-14 21:20:45 +00008285 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8286 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008287}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008288
8289template<typename Derived>
8290ExprResult
8291TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8292 // If E is not value-dependent, then nothing will change when we transform it.
8293 // Note: This is an instantiation-centric view.
8294 if (!E->isValueDependent())
8295 return SemaRef.Owned(E);
8296
8297 // Note: None of the implementations of TryExpandParameterPacks can ever
8298 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008299 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008300 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8301 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008302 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008303 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008304 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008305 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008306 ShouldExpand, RetainExpansion,
8307 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008308 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008309
Douglas Gregor089e8932011-10-10 18:59:29 +00008310 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008311 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008312
Douglas Gregor089e8932011-10-10 18:59:29 +00008313 NamedDecl *Pack = E->getPack();
8314 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008315 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008316 Pack));
8317 if (!Pack)
8318 return ExprError();
8319 }
8320
Chad Rosier4a9d7952012-08-08 18:46:20 +00008321
Douglas Gregoree8aff02011-01-04 17:33:58 +00008322 // We now know the length of the parameter pack, so build a new expression
8323 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008324 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8325 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008326 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008327}
8328
Douglas Gregorbe230c32011-01-03 17:17:50 +00008329template<typename Derived>
8330ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008331TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8332 SubstNonTypeTemplateParmPackExpr *E) {
8333 // Default behavior is to do nothing with this transformation.
8334 return SemaRef.Owned(E);
8335}
8336
8337template<typename Derived>
8338ExprResult
John McCall91a57552011-07-15 05:09:51 +00008339TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8340 SubstNonTypeTemplateParmExpr *E) {
8341 // Default behavior is to do nothing with this transformation.
8342 return SemaRef.Owned(E);
8343}
8344
8345template<typename Derived>
8346ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008347TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8348 MaterializeTemporaryExpr *E) {
8349 return getDerived().TransformExpr(E->GetTemporaryExpr());
8350}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008351
Douglas Gregor03e80032011-06-21 17:03:29 +00008352template<typename Derived>
8353ExprResult
John McCall454feb92009-12-08 09:21:05 +00008354TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008355 return SemaRef.MaybeBindToTemporary(E);
8356}
8357
8358template<typename Derived>
8359ExprResult
8360TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008361 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008362}
8363
8364template<typename Derived>
8365ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008366TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8367 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8368 if (SubExpr.isInvalid())
8369 return ExprError();
8370
8371 if (!getDerived().AlwaysRebuild() &&
8372 SubExpr.get() == E->getSubExpr())
8373 return SemaRef.Owned(E);
8374
8375 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008376}
8377
8378template<typename Derived>
8379ExprResult
8380TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8381 // Transform each of the elements.
8382 llvm::SmallVector<Expr *, 8> Elements;
8383 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008384 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008385 /*IsCall=*/false, Elements, &ArgChanged))
8386 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008387
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008388 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8389 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008390
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008391 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8392 Elements.data(),
8393 Elements.size());
8394}
8395
8396template<typename Derived>
8397ExprResult
8398TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008399 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008400 // Transform each of the elements.
8401 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8402 bool ArgChanged = false;
8403 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8404 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008405
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008406 if (OrigElement.isPackExpansion()) {
8407 // This key/value element is a pack expansion.
8408 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8409 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8410 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8411 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8412
8413 // Determine whether the set of unexpanded parameter packs can
8414 // and should be expanded.
8415 bool Expand = true;
8416 bool RetainExpansion = false;
8417 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8418 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8419 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8420 OrigElement.Value->getLocEnd());
8421 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8422 PatternRange,
8423 Unexpanded,
8424 Expand, RetainExpansion,
8425 NumExpansions))
8426 return ExprError();
8427
8428 if (!Expand) {
8429 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008430 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008431 // expansion.
8432 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8433 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8434 if (Key.isInvalid())
8435 return ExprError();
8436
8437 if (Key.get() != OrigElement.Key)
8438 ArgChanged = true;
8439
8440 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8441 if (Value.isInvalid())
8442 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008443
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008444 if (Value.get() != OrigElement.Value)
8445 ArgChanged = true;
8446
Chad Rosier4a9d7952012-08-08 18:46:20 +00008447 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008448 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8449 };
8450 Elements.push_back(Expansion);
8451 continue;
8452 }
8453
8454 // Record right away that the argument was changed. This needs
8455 // to happen even if the array expands to nothing.
8456 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008457
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008458 // The transform has determined that we should perform an elementwise
8459 // expansion of the pattern. Do so.
8460 for (unsigned I = 0; I != *NumExpansions; ++I) {
8461 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8462 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8463 if (Key.isInvalid())
8464 return ExprError();
8465
8466 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8467 if (Value.isInvalid())
8468 return ExprError();
8469
Chad Rosier4a9d7952012-08-08 18:46:20 +00008470 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008471 Key.get(), Value.get(), SourceLocation(), NumExpansions
8472 };
8473
8474 // If any unexpanded parameter packs remain, we still have a
8475 // pack expansion.
8476 if (Key.get()->containsUnexpandedParameterPack() ||
8477 Value.get()->containsUnexpandedParameterPack())
8478 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008479
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008480 Elements.push_back(Element);
8481 }
8482
8483 // We've finished with this pack expansion.
8484 continue;
8485 }
8486
8487 // Transform and check key.
8488 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8489 if (Key.isInvalid())
8490 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008491
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008492 if (Key.get() != OrigElement.Key)
8493 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008494
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008495 // Transform and check value.
8496 ExprResult Value
8497 = getDerived().TransformExpr(OrigElement.Value);
8498 if (Value.isInvalid())
8499 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008500
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008501 if (Value.get() != OrigElement.Value)
8502 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008503
8504 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008505 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8506 };
8507 Elements.push_back(Element);
8508 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008509
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008510 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8511 return SemaRef.MaybeBindToTemporary(E);
8512
8513 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8514 Elements.data(),
8515 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008516}
8517
Mike Stump1eb44332009-09-09 15:08:12 +00008518template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008519ExprResult
John McCall454feb92009-12-08 09:21:05 +00008520TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008521 TypeSourceInfo *EncodedTypeInfo
8522 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8523 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008524 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008525
Douglas Gregorb98b1992009-08-11 05:31:07 +00008526 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008527 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008528 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008529
8530 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008531 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008532 E->getRParenLoc());
8533}
Mike Stump1eb44332009-09-09 15:08:12 +00008534
Douglas Gregorb98b1992009-08-11 05:31:07 +00008535template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008536ExprResult TreeTransform<Derived>::
8537TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8538 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8539 if (result.isInvalid()) return ExprError();
8540 Expr *subExpr = result.take();
8541
8542 if (!getDerived().AlwaysRebuild() &&
8543 subExpr == E->getSubExpr())
8544 return SemaRef.Owned(E);
8545
8546 return SemaRef.Owned(new(SemaRef.Context)
8547 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8548}
8549
8550template<typename Derived>
8551ExprResult TreeTransform<Derived>::
8552TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008553 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008554 = getDerived().TransformType(E->getTypeInfoAsWritten());
8555 if (!TSInfo)
8556 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008557
John McCallf85e1932011-06-15 23:02:42 +00008558 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008559 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008560 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008561
John McCallf85e1932011-06-15 23:02:42 +00008562 if (!getDerived().AlwaysRebuild() &&
8563 TSInfo == E->getTypeInfoAsWritten() &&
8564 Result.get() == E->getSubExpr())
8565 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008566
John McCallf85e1932011-06-15 23:02:42 +00008567 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008568 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008569 Result.get());
8570}
8571
8572template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008573ExprResult
John McCall454feb92009-12-08 09:21:05 +00008574TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008575 // Transform arguments.
8576 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008577 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008578 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008579 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008580 &ArgChanged))
8581 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008582
Douglas Gregor92e986e2010-04-22 16:44:27 +00008583 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8584 // Class message: transform the receiver type.
8585 TypeSourceInfo *ReceiverTypeInfo
8586 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8587 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008588 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008589
Douglas Gregor92e986e2010-04-22 16:44:27 +00008590 // If nothing changed, just retain the existing message send.
8591 if (!getDerived().AlwaysRebuild() &&
8592 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008593 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008594
8595 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008596 SmallVector<SourceLocation, 16> SelLocs;
8597 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008598 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8599 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008600 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008601 E->getMethodDecl(),
8602 E->getLeftLoc(),
8603 move_arg(Args),
8604 E->getRightLoc());
8605 }
8606
8607 // Instance message: transform the receiver
8608 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8609 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008610 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008611 = getDerived().TransformExpr(E->getInstanceReceiver());
8612 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008613 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008614
8615 // If nothing changed, just retain the existing message send.
8616 if (!getDerived().AlwaysRebuild() &&
8617 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008618 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008619
Douglas Gregor92e986e2010-04-22 16:44:27 +00008620 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008621 SmallVector<SourceLocation, 16> SelLocs;
8622 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008623 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008624 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008625 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008626 E->getMethodDecl(),
8627 E->getLeftLoc(),
8628 move_arg(Args),
8629 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008630}
8631
Mike Stump1eb44332009-09-09 15:08:12 +00008632template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008633ExprResult
John McCall454feb92009-12-08 09:21:05 +00008634TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008635 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008636}
8637
Mike Stump1eb44332009-09-09 15:08:12 +00008638template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008639ExprResult
John McCall454feb92009-12-08 09:21:05 +00008640TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008641 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008642}
8643
Mike Stump1eb44332009-09-09 15:08:12 +00008644template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008645ExprResult
John McCall454feb92009-12-08 09:21:05 +00008646TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008647 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008648 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008649 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008650 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008651
8652 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008653
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008654 // If nothing changed, just retain the existing expression.
8655 if (!getDerived().AlwaysRebuild() &&
8656 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008657 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008658
John McCall9ae2f072010-08-23 23:25:46 +00008659 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008660 E->getLocation(),
8661 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008662}
8663
Mike Stump1eb44332009-09-09 15:08:12 +00008664template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008665ExprResult
John McCall454feb92009-12-08 09:21:05 +00008666TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008667 // 'super' and types never change. Property never changes. Just
8668 // retain the existing expression.
8669 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008670 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008671
Douglas Gregore3303542010-04-26 20:47:02 +00008672 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008673 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008674 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008675 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008676
Douglas Gregore3303542010-04-26 20:47:02 +00008677 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008678
Douglas Gregore3303542010-04-26 20:47:02 +00008679 // If nothing changed, just retain the existing expression.
8680 if (!getDerived().AlwaysRebuild() &&
8681 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008682 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008683
John McCall12f78a62010-12-02 01:19:52 +00008684 if (E->isExplicitProperty())
8685 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8686 E->getExplicitProperty(),
8687 E->getLocation());
8688
8689 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008690 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008691 E->getImplicitPropertyGetter(),
8692 E->getImplicitPropertySetter(),
8693 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008694}
8695
Mike Stump1eb44332009-09-09 15:08:12 +00008696template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008697ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008698TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8699 // Transform the base expression.
8700 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8701 if (Base.isInvalid())
8702 return ExprError();
8703
8704 // Transform the key expression.
8705 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8706 if (Key.isInvalid())
8707 return ExprError();
8708
8709 // If nothing changed, just retain the existing expression.
8710 if (!getDerived().AlwaysRebuild() &&
8711 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8712 return SemaRef.Owned(E);
8713
Chad Rosier4a9d7952012-08-08 18:46:20 +00008714 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008715 Base.get(), Key.get(),
8716 E->getAtIndexMethodDecl(),
8717 E->setAtIndexMethodDecl());
8718}
8719
8720template<typename Derived>
8721ExprResult
John McCall454feb92009-12-08 09:21:05 +00008722TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008723 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008724 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008725 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008726 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008727
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008728 // If nothing changed, just retain the existing expression.
8729 if (!getDerived().AlwaysRebuild() &&
8730 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008731 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008732
John McCall9ae2f072010-08-23 23:25:46 +00008733 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008734 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008735}
8736
Mike Stump1eb44332009-09-09 15:08:12 +00008737template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008738ExprResult
John McCall454feb92009-12-08 09:21:05 +00008739TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008740 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008741 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008742 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008743 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008744 SubExprs, &ArgumentChanged))
8745 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008746
Douglas Gregorb98b1992009-08-11 05:31:07 +00008747 if (!getDerived().AlwaysRebuild() &&
8748 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008749 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008750
Douglas Gregorb98b1992009-08-11 05:31:07 +00008751 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8752 move_arg(SubExprs),
8753 E->getRParenLoc());
8754}
8755
Mike Stump1eb44332009-09-09 15:08:12 +00008756template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008757ExprResult
John McCall454feb92009-12-08 09:21:05 +00008758TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008759 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008760
John McCallc6ac9c32011-02-04 18:33:18 +00008761 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8762 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8763
8764 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008765 blockScope->TheDecl->setBlockMissingReturnType(
8766 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008767
Chris Lattner686775d2011-07-20 06:58:45 +00008768 SmallVector<ParmVarDecl*, 4> params;
8769 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008770
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008771 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008772 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8773 oldBlock->param_begin(),
8774 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008775 0, paramTypes, &params)) {
8776 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008777 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008778 }
John McCallc6ac9c32011-02-04 18:33:18 +00008779
8780 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008781 QualType exprResultType =
8782 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008783
8784 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008785 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008786 getSema().Diag(E->getCaretLocation(),
8787 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008788 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008789 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008790 return ExprError();
8791 }
John McCall711c52b2011-01-05 12:14:39 +00008792
John McCallc6ac9c32011-02-04 18:33:18 +00008793 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008794 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008795 paramTypes.data(),
8796 paramTypes.size(),
8797 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008798 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008799 exprFunctionType->getExtInfo());
8800 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008801
8802 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008803 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008804 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008805
8806 if (!oldBlock->blockMissingReturnType()) {
8807 blockScope->HasImplicitReturnType = false;
8808 blockScope->ReturnType = exprResultType;
8809 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008810
John McCall711c52b2011-01-05 12:14:39 +00008811 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008812 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008813 if (body.isInvalid()) {
8814 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008815 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008816 }
John McCall711c52b2011-01-05 12:14:39 +00008817
John McCallc6ac9c32011-02-04 18:33:18 +00008818#ifndef NDEBUG
8819 // In builds with assertions, make sure that we captured everything we
8820 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008821 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8822 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8823 e = oldBlock->capture_end(); i != e; ++i) {
8824 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008825
Douglas Gregorfc921372011-05-20 15:32:55 +00008826 // Ignore parameter packs.
8827 if (isa<ParmVarDecl>(oldCapture) &&
8828 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8829 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008830
Douglas Gregorfc921372011-05-20 15:32:55 +00008831 VarDecl *newCapture =
8832 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8833 oldCapture));
8834 assert(blockScope->CaptureMap.count(newCapture));
8835 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008836 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008837 }
8838#endif
8839
8840 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8841 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008842}
8843
Mike Stump1eb44332009-09-09 15:08:12 +00008844template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008845ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008846TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008847 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008848}
Eli Friedman276b0612011-10-11 02:20:01 +00008849
8850template<typename Derived>
8851ExprResult
8852TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008853 QualType RetTy = getDerived().TransformType(E->getType());
8854 bool ArgumentChanged = false;
8855 ASTOwningVector<Expr*> SubExprs(SemaRef);
8856 SubExprs.reserve(E->getNumSubExprs());
8857 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8858 SubExprs, &ArgumentChanged))
8859 return ExprError();
8860
8861 if (!getDerived().AlwaysRebuild() &&
8862 !ArgumentChanged)
8863 return SemaRef.Owned(E);
8864
8865 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8866 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008867}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008868
Douglas Gregorb98b1992009-08-11 05:31:07 +00008869//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008870// Type reconstruction
8871//===----------------------------------------------------------------------===//
8872
Mike Stump1eb44332009-09-09 15:08:12 +00008873template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008874QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8875 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008876 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008877 getDerived().getBaseEntity());
8878}
8879
Mike Stump1eb44332009-09-09 15:08:12 +00008880template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008881QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8882 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008883 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008884 getDerived().getBaseEntity());
8885}
8886
Mike Stump1eb44332009-09-09 15:08:12 +00008887template<typename Derived>
8888QualType
John McCall85737a72009-10-30 00:06:24 +00008889TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8890 bool WrittenAsLValue,
8891 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008892 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008893 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008894}
8895
8896template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008897QualType
John McCall85737a72009-10-30 00:06:24 +00008898TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8899 QualType ClassType,
8900 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008901 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008902 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008903}
8904
8905template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008906QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008907TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8908 ArrayType::ArraySizeModifier SizeMod,
8909 const llvm::APInt *Size,
8910 Expr *SizeExpr,
8911 unsigned IndexTypeQuals,
8912 SourceRange BracketsRange) {
8913 if (SizeExpr || !Size)
8914 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8915 IndexTypeQuals, BracketsRange,
8916 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008917
8918 QualType Types[] = {
8919 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8920 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8921 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008922 };
8923 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8924 QualType SizeType;
8925 for (unsigned I = 0; I != NumTypes; ++I)
8926 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8927 SizeType = Types[I];
8928 break;
8929 }
Mike Stump1eb44332009-09-09 15:08:12 +00008930
Eli Friedman01f276d2012-01-25 23:20:27 +00008931 // Note that we can return a VariableArrayType here in the case where
8932 // the element type was a dependent VariableArrayType.
8933 IntegerLiteral *ArraySize
8934 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8935 /*FIXME*/BracketsRange.getBegin());
8936 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008937 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008938 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008939}
Mike Stump1eb44332009-09-09 15:08:12 +00008940
Douglas Gregor577f75a2009-08-04 16:50:30 +00008941template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008942QualType
8943TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008944 ArrayType::ArraySizeModifier SizeMod,
8945 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008946 unsigned IndexTypeQuals,
8947 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008948 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008949 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008950}
8951
8952template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008953QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008954TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008955 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008956 unsigned IndexTypeQuals,
8957 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008958 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008959 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008960}
Mike Stump1eb44332009-09-09 15:08:12 +00008961
Douglas Gregor577f75a2009-08-04 16:50:30 +00008962template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008963QualType
8964TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008965 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008966 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008967 unsigned IndexTypeQuals,
8968 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008969 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008970 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008971 IndexTypeQuals, BracketsRange);
8972}
8973
8974template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008975QualType
8976TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008977 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008978 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008979 unsigned IndexTypeQuals,
8980 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008981 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008982 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008983 IndexTypeQuals, BracketsRange);
8984}
8985
8986template<typename Derived>
8987QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008988 unsigned NumElements,
8989 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008990 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008991 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008992}
Mike Stump1eb44332009-09-09 15:08:12 +00008993
Douglas Gregor577f75a2009-08-04 16:50:30 +00008994template<typename Derived>
8995QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8996 unsigned NumElements,
8997 SourceLocation AttributeLoc) {
8998 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8999 NumElements, true);
9000 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009001 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9002 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009003 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009004}
Mike Stump1eb44332009-09-09 15:08:12 +00009005
Douglas Gregor577f75a2009-08-04 16:50:30 +00009006template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009007QualType
9008TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009009 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009010 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009011 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009012}
Mike Stump1eb44332009-09-09 15:08:12 +00009013
Douglas Gregor577f75a2009-08-04 16:50:30 +00009014template<typename Derived>
9015QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00009016 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009017 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00009018 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009019 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00009020 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00009021 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00009022 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00009023 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009024 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009025 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009026 getDerived().getBaseEntity(),
9027 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009028}
Mike Stump1eb44332009-09-09 15:08:12 +00009029
Douglas Gregor577f75a2009-08-04 16:50:30 +00009030template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009031QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9032 return SemaRef.Context.getFunctionNoProtoType(T);
9033}
9034
9035template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009036QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9037 assert(D && "no decl found");
9038 if (D->isInvalidDecl()) return QualType();
9039
Douglas Gregor92e986e2010-04-22 16:44:27 +00009040 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009041 TypeDecl *Ty;
9042 if (isa<UsingDecl>(D)) {
9043 UsingDecl *Using = cast<UsingDecl>(D);
9044 assert(Using->isTypeName() &&
9045 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9046
9047 // A valid resolved using typename decl points to exactly one type decl.
9048 assert(++Using->shadow_begin() == Using->shadow_end());
9049 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009050
John McCalled976492009-12-04 22:46:56 +00009051 } else {
9052 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9053 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9054 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9055 }
9056
9057 return SemaRef.Context.getTypeDeclType(Ty);
9058}
9059
9060template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009061QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9062 SourceLocation Loc) {
9063 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009064}
9065
9066template<typename Derived>
9067QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9068 return SemaRef.Context.getTypeOfType(Underlying);
9069}
9070
9071template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009072QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9073 SourceLocation Loc) {
9074 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009075}
9076
9077template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009078QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9079 UnaryTransformType::UTTKind UKind,
9080 SourceLocation Loc) {
9081 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9082}
9083
9084template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009085QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009086 TemplateName Template,
9087 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009088 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009089 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009090}
Mike Stump1eb44332009-09-09 15:08:12 +00009091
Douglas Gregordcee1a12009-08-06 05:28:30 +00009092template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009093QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9094 SourceLocation KWLoc) {
9095 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9096}
9097
9098template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009099TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009100TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009101 bool TemplateKW,
9102 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009103 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009104 Template);
9105}
9106
9107template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009108TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009109TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9110 const IdentifierInfo &Name,
9111 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009112 QualType ObjectType,
9113 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009114 UnqualifiedId TemplateName;
9115 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009116 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009117 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009118 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009119 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009120 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009121 /*EnteringContext=*/false,
9122 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009123 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009124}
Mike Stump1eb44332009-09-09 15:08:12 +00009125
Douglas Gregorb98b1992009-08-11 05:31:07 +00009126template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009127TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009128TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009129 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009130 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009131 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009132 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009133 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009134 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009135 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009136 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009137 Sema::TemplateTy Template;
9138 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009139 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009140 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009141 /*EnteringContext=*/false,
9142 Template);
9143 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009144}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009145
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009146template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009147ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009148TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9149 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009150 Expr *OrigCallee,
9151 Expr *First,
9152 Expr *Second) {
9153 Expr *Callee = OrigCallee->IgnoreParenCasts();
9154 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009155
Douglas Gregorb98b1992009-08-11 05:31:07 +00009156 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009157 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009158 if (!First->getType()->isOverloadableType() &&
9159 !Second->getType()->isOverloadableType())
9160 return getSema().CreateBuiltinArraySubscriptExpr(First,
9161 Callee->getLocStart(),
9162 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009163 } else if (Op == OO_Arrow) {
9164 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009165 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9166 } else if (Second == 0 || isPostIncDec) {
9167 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009168 // The argument is not of overloadable type, so try to create a
9169 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009170 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009171 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009172
John McCall9ae2f072010-08-23 23:25:46 +00009173 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009174 }
9175 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009176 if (!First->getType()->isOverloadableType() &&
9177 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009178 // Neither of the arguments is an overloadable type, so try to
9179 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009180 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009181 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009182 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009183 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009184 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009185
Douglas Gregorb98b1992009-08-11 05:31:07 +00009186 return move(Result);
9187 }
9188 }
Mike Stump1eb44332009-09-09 15:08:12 +00009189
9190 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009191 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009192 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009193
John McCall9ae2f072010-08-23 23:25:46 +00009194 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009195 assert(ULE->requiresADL());
9196
9197 // FIXME: Do we have to check
9198 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009199 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009200 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009201 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00009202 }
Mike Stump1eb44332009-09-09 15:08:12 +00009203
Douglas Gregorb98b1992009-08-11 05:31:07 +00009204 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009205 Expr *Args[2] = { First, Second };
9206 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009207
Douglas Gregorb98b1992009-08-11 05:31:07 +00009208 // Create the overloaded operator invocation for unary operators.
9209 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009210 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009211 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009212 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009213 }
Mike Stump1eb44332009-09-09 15:08:12 +00009214
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009215 if (Op == OO_Subscript) {
9216 SourceLocation LBrace;
9217 SourceLocation RBrace;
9218
9219 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9220 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9221 LBrace = SourceLocation::getFromRawEncoding(
9222 NameLoc.CXXOperatorName.BeginOpNameLoc);
9223 RBrace = SourceLocation::getFromRawEncoding(
9224 NameLoc.CXXOperatorName.EndOpNameLoc);
9225 } else {
9226 LBrace = Callee->getLocStart();
9227 RBrace = OpLoc;
9228 }
9229
9230 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9231 First, Second);
9232 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009233
Douglas Gregorb98b1992009-08-11 05:31:07 +00009234 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009235 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009236 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009237 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9238 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009239 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009240
Mike Stump1eb44332009-09-09 15:08:12 +00009241 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009242}
Mike Stump1eb44332009-09-09 15:08:12 +00009243
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009244template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009245ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009246TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009247 SourceLocation OperatorLoc,
9248 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009249 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009250 TypeSourceInfo *ScopeType,
9251 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009252 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009253 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009254 QualType BaseType = Base->getType();
9255 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009256 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009257 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009258 !BaseType->getAs<PointerType>()->getPointeeType()
9259 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009260 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009261 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009262 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009263 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009264 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009265 /*FIXME?*/true);
9266 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009267
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009268 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009269 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9270 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9271 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9272 NameInfo.setNamedTypeInfo(DestroyedType);
9273
Richard Smith6314db92012-05-15 06:15:11 +00009274 // The scope type is now known to be a valid nested name specifier
9275 // component. Tack it on to the end of the nested name specifier.
9276 if (ScopeType)
9277 SS.Extend(SemaRef.Context, SourceLocation(),
9278 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009279
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009280 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009281 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009282 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009283 SS, TemplateKWLoc,
9284 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009285 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009286 /*TemplateArgs*/ 0);
9287}
9288
Douglas Gregor577f75a2009-08-04 16:50:30 +00009289} // end namespace clang
9290
9291#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H