blob: 7bf1a29183168f28a3ff239ef51ef1f2154578f1 [file] [log] [blame]
Chris Lattner57ad3782011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner57ad3782011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattner57ad3782011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregor577f75a2009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall2d887082010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor8491ffe2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Richard Smith3e4c6c42011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall19510852010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000034#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000035#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000036#include "TypeLocBuilder.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCall781472f2010-08-25 08:40:02 +000040using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000041
Douglas Gregor577f75a2009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump1eb44332009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump1eb44332009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000101
Douglas Gregord3731192011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000106
Douglas Gregord3731192011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier4a9d7952012-08-08 18:46:20 +0000111
Douglas Gregor577f75a2009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000114
Douglas Gregordfca6f52012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000119
Mike Stump1eb44332009-09-09 15:08:12 +0000120public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000123
Douglas Gregor577f75a2009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000130 }
131
John McCall60d7b3a2010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000134
Douglas Gregor577f75a2009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000138
Douglas Gregor577f75a2009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
144 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000145
Douglas Gregor577f75a2009-08-04 16:50:30 +0000146 /// \brief Returns the location of the entity being transformed, if that
147 /// information was not available elsewhere in the AST.
148 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000149 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000150 /// provide an alternative implementation that provides better location
151 /// information.
152 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000153
Douglas Gregor577f75a2009-08-04 16:50:30 +0000154 /// \brief Returns the name of the entity being transformed, if that
155 /// information was not available elsewhere in the AST.
156 ///
157 /// By default, returns an empty name. Subclasses can provide an alternative
158 /// implementation with a more precise name.
159 DeclarationName getBaseEntity() { return DeclarationName(); }
160
Douglas Gregorb98b1992009-08-11 05:31:07 +0000161 /// \brief Sets the "base" location and entity when that
162 /// information is known based on another transformation.
163 ///
164 /// By default, the source location and entity are ignored. Subclasses can
165 /// override this function to provide a customized implementation.
166 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000167
Douglas Gregorb98b1992009-08-11 05:31:07 +0000168 /// \brief RAII object that temporarily sets the base location and entity
169 /// used for reporting diagnostics in types.
170 class TemporaryBase {
171 TreeTransform &Self;
172 SourceLocation OldLocation;
173 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000174
Douglas Gregorb98b1992009-08-11 05:31:07 +0000175 public:
176 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000177 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000178 OldLocation = Self.getDerived().getBaseLocation();
179 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000180
Douglas Gregorae201f72011-01-25 17:51:48 +0000181 if (Location.isValid())
182 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000183 }
Mike Stump1eb44332009-09-09 15:08:12 +0000184
Douglas Gregorb98b1992009-08-11 05:31:07 +0000185 ~TemporaryBase() {
186 Self.getDerived().setBase(OldLocation, OldEntity);
187 }
188 };
Mike Stump1eb44332009-09-09 15:08:12 +0000189
190 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000191 /// transformed.
192 ///
193 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000194 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000195 /// not change. For example, template instantiation need not traverse
196 /// non-dependent types.
197 bool AlreadyTransformed(QualType T) {
198 return T.isNull();
199 }
200
Douglas Gregor6eef5192009-12-14 19:27:10 +0000201 /// \brief Determine whether the given call argument should be dropped, e.g.,
202 /// because it is a default argument.
203 ///
204 /// Subclasses can provide an alternative implementation of this routine to
205 /// determine which kinds of call arguments get dropped. By default,
206 /// CXXDefaultArgument nodes are dropped (prior to transformation).
207 bool DropCallArgument(Expr *E) {
208 return E->isDefaultArgument();
209 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000210
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000211 /// \brief Determine whether we should expand a pack expansion with the
212 /// given set of parameter packs into separate arguments by repeatedly
213 /// transforming the pattern.
214 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000215 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000216 /// Subclasses can override this routine to provide different behavior.
217 ///
218 /// \param EllipsisLoc The location of the ellipsis that identifies the
219 /// pack expansion.
220 ///
221 /// \param PatternRange The source range that covers the entire pattern of
222 /// the pack expansion.
223 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000224 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000225 /// pattern.
226 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000227 /// \param ShouldExpand Will be set to \c true if the transformer should
228 /// expand the corresponding pack expansions into separate arguments. When
229 /// set, \c NumExpansions must also be set.
230 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000231 /// \param RetainExpansion Whether the caller should add an unexpanded
232 /// pack expansion after all of the expanded arguments. This is used
233 /// when extending explicitly-specified template argument packs per
234 /// C++0x [temp.arg.explicit]p9.
235 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000236 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000237 /// the expanded form of the corresponding pack expansion. This is both an
238 /// input and an output parameter, which can be set by the caller if the
239 /// number of expansions is known a priori (e.g., due to a prior substitution)
240 /// and will be set by the callee when the number of expansions is known.
241 /// The callee must set this value when \c ShouldExpand is \c true; it may
242 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000243 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000244 /// \returns true if an error occurred (e.g., because the parameter packs
245 /// are to be instantiated with arguments of different lengths), false
246 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000247 /// must be set.
248 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
249 SourceRange PatternRange,
David Blaikiea71f9d02011-09-22 02:34:54 +0000250 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000251 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000252 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000253 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000254 ShouldExpand = false;
255 return false;
256 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000257
Douglas Gregord3731192011-01-10 07:32:04 +0000258 /// \brief "Forget" about the partially-substituted pack template argument,
259 /// when performing an instantiation that must preserve the parameter pack
260 /// use.
261 ///
262 /// This routine is meant to be overridden by the template instantiator.
263 TemplateArgument ForgetPartiallySubstitutedPack() {
264 return TemplateArgument();
265 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000266
Douglas Gregord3731192011-01-10 07:32:04 +0000267 /// \brief "Remember" the partially-substituted pack template argument
268 /// after performing an instantiation that must preserve the parameter pack
269 /// use.
270 ///
271 /// This routine is meant to be overridden by the template instantiator.
272 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000273
Douglas Gregor12c9c002011-01-07 16:43:16 +0000274 /// \brief Note to the derived class when a function parameter pack is
275 /// being expanded.
276 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000277
Douglas Gregor577f75a2009-08-04 16:50:30 +0000278 /// \brief Transforms the given type into another type.
279 ///
John McCalla2becad2009-10-21 00:40:46 +0000280 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000281 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000282 /// function. This is expensive, but we don't mind, because
283 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000284 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000285 ///
286 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000287 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000288
John McCalla2becad2009-10-21 00:40:46 +0000289 /// \brief Transforms the given type-with-location into a new
290 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000291 ///
John McCalla2becad2009-10-21 00:40:46 +0000292 /// By default, this routine transforms a type by delegating to the
293 /// appropriate TransformXXXType to build a new type. Subclasses
294 /// may override this function (to take over all type
295 /// transformations) or some set of the TransformXXXType functions
296 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000297 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000298
299 /// \brief Transform the given type-with-location into a new
300 /// type, collecting location information in the given builder
301 /// as necessary.
302 ///
John McCall43fed0d2010-11-12 08:19:04 +0000303 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000304
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000305 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000306 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000307 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000308 /// appropriate TransformXXXStmt function to transform a specific kind of
309 /// statement or the TransformExpr() function to transform an expression.
310 /// Subclasses may override this function to transform statements using some
311 /// other mechanism.
312 ///
313 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000314 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000315
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000316 /// \brief Transform the given expression.
317 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000318 /// By default, this routine transforms an expression by delegating to the
319 /// appropriate TransformXXXExpr function to build a new expression.
320 /// Subclasses may override this function to transform expressions using some
321 /// other mechanism.
322 ///
323 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000324 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000325
Douglas Gregoraa165f82011-01-03 19:04:46 +0000326 /// \brief Transform the given list of expressions.
327 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000328 /// This routine transforms a list of expressions by invoking
329 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregoraa165f82011-01-03 19:04:46 +0000330 /// support for variadic templates by expanding any pack expansions (if the
331 /// derived class permits such expansion) along the way. When pack expansions
332 /// are present, the number of outputs may not equal the number of inputs.
333 ///
334 /// \param Inputs The set of expressions to be transformed.
335 ///
336 /// \param NumInputs The number of expressions in \c Inputs.
337 ///
338 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier4a9d7952012-08-08 18:46:20 +0000339 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregoraa165f82011-01-03 19:04:46 +0000340 /// be.
341 ///
342 /// \param Outputs The transformed input expressions will be added to this
343 /// vector.
344 ///
345 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
346 /// due to transformation.
347 ///
348 /// \returns true if an error occurred, false otherwise.
349 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000350 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000351 bool *ArgChanged = 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000352
Douglas Gregor577f75a2009-08-04 16:50:30 +0000353 /// \brief Transform the given declaration, which is referenced from a type
354 /// or expression.
355 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000356 /// By default, acts as the identity function on declarations, unless the
357 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000358 /// may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000359 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregordfca6f52012-02-13 22:00:16 +0000360 llvm::DenseMap<Decl *, Decl *>::iterator Known
361 = TransformedLocalDecls.find(D);
362 if (Known != TransformedLocalDecls.end())
363 return Known->second;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000364
365 return D;
Douglas Gregordfca6f52012-02-13 22:00:16 +0000366 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000367
Chad Rosier4a9d7952012-08-08 18:46:20 +0000368 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregordfca6f52012-02-13 22:00:16 +0000369 /// place them on the new declaration.
370 ///
371 /// By default, this operation does nothing. Subclasses may override this
372 /// behavior to transform attributes.
373 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000374
Douglas Gregordfca6f52012-02-13 22:00:16 +0000375 /// \brief Note that a local declaration has been transformed by this
376 /// transformer.
377 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000378 /// Local declarations are typically transformed via a call to
Douglas Gregordfca6f52012-02-13 22:00:16 +0000379 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
380 /// the transformer itself has to transform the declarations. This routine
381 /// can be overridden by a subclass that keeps track of such mappings.
382 void transformedLocalDecl(Decl *Old, Decl *New) {
383 TransformedLocalDecls[Old] = New;
384 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000385
Douglas Gregor43959a92009-08-20 07:17:43 +0000386 /// \brief Transform the definition of the given declaration.
387 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000388 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000389 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000390 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
391 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000392 }
Mike Stump1eb44332009-09-09 15:08:12 +0000393
Douglas Gregor6cd21982009-10-20 05:58:46 +0000394 /// \brief Transform the given declaration, which was the first part of a
395 /// nested-name-specifier in a member access expression.
396 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000397 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000398 /// identifier in a nested-name-specifier of a member access expression, e.g.,
399 /// the \c T in \c x->T::member
400 ///
401 /// By default, invokes TransformDecl() to transform the declaration.
402 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000403 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
404 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000405 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000406
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000407 /// \brief Transform the given nested-name-specifier with source-location
408 /// information.
409 ///
410 /// By default, transforms all of the types and declarations within the
411 /// nested-name-specifier. Subclasses may override this function to provide
412 /// alternate behavior.
413 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
414 NestedNameSpecifierLoc NNS,
415 QualType ObjectType = QualType(),
416 NamedDecl *FirstQualifierInScope = 0);
417
Douglas Gregor81499bb2009-09-03 22:13:48 +0000418 /// \brief Transform the given declaration name.
419 ///
420 /// By default, transforms the types of conversion function, constructor,
421 /// and destructor names and then (if needed) rebuilds the declaration name.
422 /// Identifiers and selectors are returned unmodified. Sublcasses may
423 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000424 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000425 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000426
Douglas Gregor577f75a2009-08-04 16:50:30 +0000427 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000428 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000429 /// \param SS The nested-name-specifier that qualifies the template
430 /// name. This nested-name-specifier must already have been transformed.
431 ///
432 /// \param Name The template name to transform.
433 ///
434 /// \param NameLoc The source location of the template name.
435 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000436 /// \param ObjectType If we're translating a template name within a member
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000437 /// access expression, this is the type of the object whose member template
438 /// is being referenced.
439 ///
440 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
441 /// also refers to a name within the current (lexical) scope, this is the
442 /// declaration it refers to.
443 ///
444 /// By default, transforms the template name by transforming the declarations
445 /// and nested-name-specifiers that occur within the template name.
446 /// Subclasses may override this function to provide alternate behavior.
447 TemplateName TransformTemplateName(CXXScopeSpec &SS,
448 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000449 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000450 QualType ObjectType = QualType(),
451 NamedDecl *FirstQualifierInScope = 0);
452
Douglas Gregor577f75a2009-08-04 16:50:30 +0000453 /// \brief Transform the given template argument.
454 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000455 /// By default, this operation transforms the type, expression, or
456 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000457 /// new template argument from the transformed result. Subclasses may
458 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000459 ///
460 /// Returns true if there was an error.
461 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
462 TemplateArgumentLoc &Output);
463
Douglas Gregorfcc12532010-12-20 17:31:10 +0000464 /// \brief Transform the given set of template arguments.
465 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000466 /// By default, this operation transforms all of the template arguments
Douglas Gregorfcc12532010-12-20 17:31:10 +0000467 /// in the input set using \c TransformTemplateArgument(), and appends
468 /// the transformed arguments to the output list.
469 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000470 /// Note that this overload of \c TransformTemplateArguments() is merely
471 /// a convenience function. Subclasses that wish to override this behavior
472 /// should override the iterator-based member template version.
473 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000474 /// \param Inputs The set of template arguments to be transformed.
475 ///
476 /// \param NumInputs The number of template arguments in \p Inputs.
477 ///
478 /// \param Outputs The set of transformed template arguments output by this
479 /// routine.
480 ///
481 /// Returns true if an error occurred.
482 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
483 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000484 TemplateArgumentListInfo &Outputs) {
485 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
486 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000487
488 /// \brief Transform the given set of template arguments.
489 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000490 /// By default, this operation transforms all of the template arguments
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000491 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier4a9d7952012-08-08 18:46:20 +0000492 /// the transformed arguments to the output list.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000493 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000494 /// \param First An iterator to the first template argument.
495 ///
496 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000497 ///
498 /// \param Outputs The set of transformed template arguments output by this
499 /// routine.
500 ///
501 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000502 template<typename InputIterator>
503 bool TransformTemplateArguments(InputIterator First,
504 InputIterator Last,
505 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000506
John McCall833ca992009-10-29 08:12:44 +0000507 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
508 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
509 TemplateArgumentLoc &ArgLoc);
510
John McCalla93c9342009-12-07 02:54:59 +0000511 /// \brief Fakes up a TypeSourceInfo for a type.
512 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
513 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000514 getDerived().getBaseLocation());
515 }
Mike Stump1eb44332009-09-09 15:08:12 +0000516
John McCalla2becad2009-10-21 00:40:46 +0000517#define ABSTRACT_TYPELOC(CLASS, PARENT)
518#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000519 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000520#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000521
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000522 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
523 FunctionProtoTypeLoc TL,
524 CXXRecordDecl *ThisContext,
525 unsigned ThisTypeQuals);
526
John Wiegley28bbe4b2011-04-28 01:08:34 +0000527 StmtResult
528 TransformSEHHandler(Stmt *Handler);
529
Chad Rosier4a9d7952012-08-08 18:46:20 +0000530 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000531 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
532 TemplateSpecializationTypeLoc TL,
533 TemplateName Template);
534
Chad Rosier4a9d7952012-08-08 18:46:20 +0000535 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000536 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
537 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000538 TemplateName Template,
539 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000540
Chad Rosier4a9d7952012-08-08 18:46:20 +0000541 QualType
Douglas Gregora88f09f2011-02-28 17:23:35 +0000542 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000543 DependentTemplateSpecializationTypeLoc TL,
544 NestedNameSpecifierLoc QualifierLoc);
545
John McCall21ef0fa2010-03-11 09:03:00 +0000546 /// \brief Transforms the parameters of a function type into the
547 /// given vectors.
548 ///
549 /// The result vectors should be kept in sync; null entries in the
550 /// variables vector are acceptable.
551 ///
552 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000553 bool TransformFunctionTypeParams(SourceLocation Loc,
554 ParmVarDecl **Params, unsigned NumParams,
555 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000556 SmallVectorImpl<QualType> &PTypes,
557 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000558
559 /// \brief Transforms a single function-type parameter. Return null
560 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000561 ///
562 /// \param indexAdjustment - A number to add to the parameter's
563 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000564 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000565 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000566 llvm::Optional<unsigned> NumExpansions,
567 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000568
John McCall43fed0d2010-11-12 08:19:04 +0000569 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000570
John McCall60d7b3a2010-08-24 06:29:42 +0000571 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
572 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000573
Richard Smith612409e2012-07-25 03:56:55 +0000574 /// \brief Transform the captures and body of a lambda expression.
575 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
576
Douglas Gregor43959a92009-08-20 07:17:43 +0000577#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000578 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000579#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000580 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000581#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000582#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000583
Douglas Gregor577f75a2009-08-04 16:50:30 +0000584 /// \brief Build a new pointer type given its pointee type.
585 ///
586 /// By default, performs semantic analysis when building the pointer type.
587 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000588 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000589
590 /// \brief Build a new block pointer type given its pointee type.
591 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000592 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000593 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000594 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000595
John McCall85737a72009-10-30 00:06:24 +0000596 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000597 ///
John McCall85737a72009-10-30 00:06:24 +0000598 /// By default, performs semantic analysis when building the
599 /// reference type. Subclasses may override this routine to provide
600 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000601 ///
John McCall85737a72009-10-30 00:06:24 +0000602 /// \param LValue whether the type was written with an lvalue sigil
603 /// or an rvalue sigil.
604 QualType RebuildReferenceType(QualType ReferentType,
605 bool LValue,
606 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000607
Douglas Gregor577f75a2009-08-04 16:50:30 +0000608 /// \brief Build a new member pointer type given the pointee type and the
609 /// class type it refers into.
610 ///
611 /// By default, performs semantic analysis when building the member pointer
612 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000613 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
614 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000615
Douglas Gregor577f75a2009-08-04 16:50:30 +0000616 /// \brief Build a new array type given the element type, size
617 /// modifier, size of the array (if known), size expression, and index type
618 /// qualifiers.
619 ///
620 /// By default, performs semantic analysis when building the array type.
621 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000622 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000623 QualType RebuildArrayType(QualType ElementType,
624 ArrayType::ArraySizeModifier SizeMod,
625 const llvm::APInt *Size,
626 Expr *SizeExpr,
627 unsigned IndexTypeQuals,
628 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000629
Douglas Gregor577f75a2009-08-04 16:50:30 +0000630 /// \brief Build a new constant array type given the element type, size
631 /// modifier, (known) size of the array, and index type qualifiers.
632 ///
633 /// By default, performs semantic analysis when building the array type.
634 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000635 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636 ArrayType::ArraySizeModifier SizeMod,
637 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000638 unsigned IndexTypeQuals,
639 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000640
Douglas Gregor577f75a2009-08-04 16:50:30 +0000641 /// \brief Build a new incomplete array type given the element type, size
642 /// modifier, and index type qualifiers.
643 ///
644 /// By default, performs semantic analysis when building the array type.
645 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000646 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000647 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000648 unsigned IndexTypeQuals,
649 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000650
Mike Stump1eb44332009-09-09 15:08:12 +0000651 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000652 /// size modifier, size expression, and index type qualifiers.
653 ///
654 /// By default, performs semantic analysis when building the array type.
655 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000656 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000657 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000658 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000659 unsigned IndexTypeQuals,
660 SourceRange BracketsRange);
661
Mike Stump1eb44332009-09-09 15:08:12 +0000662 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663 /// size modifier, size expression, and index type qualifiers.
664 ///
665 /// By default, performs semantic analysis when building the array type.
666 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000667 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000668 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000669 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000670 unsigned IndexTypeQuals,
671 SourceRange BracketsRange);
672
673 /// \brief Build a new vector type given the element type and
674 /// number of elements.
675 ///
676 /// By default, performs semantic analysis when building the vector type.
677 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000678 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000679 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000680
Douglas Gregor577f75a2009-08-04 16:50:30 +0000681 /// \brief Build a new extended vector type given the element type and
682 /// number of elements.
683 ///
684 /// By default, performs semantic analysis when building the vector type.
685 /// Subclasses may override this routine to provide different behavior.
686 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
687 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000688
689 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000690 /// given the element type and number of elements.
691 ///
692 /// By default, performs semantic analysis when building the vector type.
693 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000694 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000695 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000696 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000697
Douglas Gregor577f75a2009-08-04 16:50:30 +0000698 /// \brief Build a new function type.
699 ///
700 /// By default, performs semantic analysis when building the function type.
701 /// Subclasses may override this routine to provide different behavior.
702 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000703 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000704 unsigned NumParamTypes,
Richard Smitheefb3d52012-02-10 09:58:53 +0000705 bool Variadic, bool HasTrailingReturn,
706 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000707 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000708 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000709
John McCalla2becad2009-10-21 00:40:46 +0000710 /// \brief Build a new unprototyped function type.
711 QualType RebuildFunctionNoProtoType(QualType ResultType);
712
John McCalled976492009-12-04 22:46:56 +0000713 /// \brief Rebuild an unresolved typename type, given the decl that
714 /// the UnresolvedUsingTypenameDecl was transformed to.
715 QualType RebuildUnresolvedUsingType(Decl *D);
716
Douglas Gregor577f75a2009-08-04 16:50:30 +0000717 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000718 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000719 return SemaRef.Context.getTypeDeclType(Typedef);
720 }
721
722 /// \brief Build a new class/struct/union type.
723 QualType RebuildRecordType(RecordDecl *Record) {
724 return SemaRef.Context.getTypeDeclType(Record);
725 }
726
727 /// \brief Build a new Enum type.
728 QualType RebuildEnumType(EnumDecl *Enum) {
729 return SemaRef.Context.getTypeDeclType(Enum);
730 }
John McCall7da24312009-09-05 00:15:47 +0000731
Mike Stump1eb44332009-09-09 15:08:12 +0000732 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000733 ///
734 /// By default, performs semantic analysis when building the typeof type.
735 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000736 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000737
Mike Stump1eb44332009-09-09 15:08:12 +0000738 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000739 ///
740 /// By default, builds a new TypeOfType with the given underlying type.
741 QualType RebuildTypeOfType(QualType Underlying);
742
Sean Huntca63c202011-05-24 22:41:36 +0000743 /// \brief Build a new unary transform type.
744 QualType RebuildUnaryTransformType(QualType BaseType,
745 UnaryTransformType::UTTKind UKind,
746 SourceLocation Loc);
747
Mike Stump1eb44332009-09-09 15:08:12 +0000748 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000749 ///
750 /// By default, performs semantic analysis when building the decltype type.
751 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000752 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000753
Richard Smith34b41d92011-02-20 03:19:35 +0000754 /// \brief Build a new C++0x auto type.
755 ///
756 /// By default, builds a new AutoType with the given deduced type.
757 QualType RebuildAutoType(QualType Deduced) {
758 return SemaRef.Context.getAutoType(Deduced);
759 }
760
Douglas Gregor577f75a2009-08-04 16:50:30 +0000761 /// \brief Build a new template specialization type.
762 ///
763 /// By default, performs semantic analysis when building the template
764 /// specialization type. Subclasses may override this routine to provide
765 /// different behavior.
766 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000767 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000768 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000769
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000770 /// \brief Build a new parenthesized type.
771 ///
772 /// By default, builds a new ParenType type from the inner type.
773 /// Subclasses may override this routine to provide different behavior.
774 QualType RebuildParenType(QualType InnerType) {
775 return SemaRef.Context.getParenType(InnerType);
776 }
777
Douglas Gregor577f75a2009-08-04 16:50:30 +0000778 /// \brief Build a new qualified name type.
779 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000780 /// By default, builds a new ElaboratedType type from the keyword,
781 /// the nested-name-specifier and the named type.
782 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000783 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
784 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000785 NestedNameSpecifierLoc QualifierLoc,
786 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000787 return SemaRef.Context.getElaboratedType(Keyword,
788 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000789 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000790 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000791
792 /// \brief Build a new typename type that refers to a template-id.
793 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000794 /// By default, builds a new DependentNameType type from the
795 /// nested-name-specifier and the given type. Subclasses may override
796 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000797 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000798 ElaboratedTypeKeyword Keyword,
799 NestedNameSpecifierLoc QualifierLoc,
800 const IdentifierInfo *Name,
801 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000802 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000803 // Rebuild the template name.
804 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000805 CXXScopeSpec SS;
806 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000807 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000808 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000809
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000810 if (InstName.isNull())
811 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000812
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000813 // If it's still dependent, make a dependent specialization.
814 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000815 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
816 QualifierLoc.getNestedNameSpecifier(),
817 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000818 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000819
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000820 // Otherwise, make an elaborated type wrapping a non-dependent
821 // specialization.
822 QualType T =
823 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
824 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000825
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000826 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
827 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000828
829 return SemaRef.Context.getElaboratedType(Keyword,
830 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000831 T);
832 }
833
Douglas Gregor577f75a2009-08-04 16:50:30 +0000834 /// \brief Build a new typename type that refers to an identifier.
835 ///
836 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000837 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000838 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000839 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000840 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000841 NestedNameSpecifierLoc QualifierLoc,
842 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000843 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000844 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000845 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000846
Douglas Gregor2494dd02011-03-01 01:34:45 +0000847 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000848 // If the name is still dependent, just build a new dependent name type.
849 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000850 return SemaRef.Context.getDependentNameType(Keyword,
851 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000852 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000853 }
854
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000855 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000856 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000857 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000858
859 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
860
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000861 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000862 // into a non-dependent elaborated-type-specifier. Find the tag we're
863 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000864 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000865 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
866 if (!DC)
867 return QualType();
868
John McCall56138762010-05-27 06:40:31 +0000869 if (SemaRef.RequireCompleteDeclContext(SS, DC))
870 return QualType();
871
Douglas Gregor40336422010-03-31 22:19:08 +0000872 TagDecl *Tag = 0;
873 SemaRef.LookupQualifiedName(Result, DC);
874 switch (Result.getResultKind()) {
875 case LookupResult::NotFound:
876 case LookupResult::NotFoundInCurrentInstantiation:
877 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000878
Douglas Gregor40336422010-03-31 22:19:08 +0000879 case LookupResult::Found:
880 Tag = Result.getAsSingle<TagDecl>();
881 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000882
Douglas Gregor40336422010-03-31 22:19:08 +0000883 case LookupResult::FoundOverloaded:
884 case LookupResult::FoundUnresolvedValue:
885 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000886
Douglas Gregor40336422010-03-31 22:19:08 +0000887 case LookupResult::Ambiguous:
888 // Let the LookupResult structure handle ambiguities.
889 return QualType();
890 }
891
892 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000893 // Check where the name exists but isn't a tag type and use that to emit
894 // better diagnostics.
895 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
896 SemaRef.LookupQualifiedName(Result, DC);
897 switch (Result.getResultKind()) {
898 case LookupResult::Found:
899 case LookupResult::FoundOverloaded:
900 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000901 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000902 unsigned Kind = 0;
903 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000904 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
905 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000906 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
907 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
908 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000909 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000910 default:
911 // FIXME: Would be nice to highlight just the source range.
912 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
913 << Kind << Id << DC;
914 break;
915 }
Douglas Gregor40336422010-03-31 22:19:08 +0000916 return QualType();
917 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000918
Richard Trieubbf34c02011-06-10 03:11:26 +0000919 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
920 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000921 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000922 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
923 return QualType();
924 }
925
926 // Build the elaborated-type-specifier type.
927 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000928 return SemaRef.Context.getElaboratedType(Keyword,
929 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000930 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000931 }
Mike Stump1eb44332009-09-09 15:08:12 +0000932
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000933 /// \brief Build a new pack expansion type.
934 ///
935 /// By default, builds a new PackExpansionType type from the given pattern.
936 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000937 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000938 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000939 SourceLocation EllipsisLoc,
940 llvm::Optional<unsigned> NumExpansions) {
941 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
942 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000943 }
944
Eli Friedmanb001de72011-10-06 23:00:33 +0000945 /// \brief Build a new atomic type given its value type.
946 ///
947 /// By default, performs semantic analysis when building the atomic type.
948 /// Subclasses may override this routine to provide different behavior.
949 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
950
Douglas Gregord1067e52009-08-06 06:41:21 +0000951 /// \brief Build a new template name given a nested name specifier, a flag
952 /// indicating whether the "template" keyword was provided, and the template
953 /// that the template name refers to.
954 ///
955 /// By default, builds the new template name directly. Subclasses may override
956 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000957 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000958 bool TemplateKW,
959 TemplateDecl *Template);
960
Douglas Gregord1067e52009-08-06 06:41:21 +0000961 /// \brief Build a new template name given a nested name specifier and the
962 /// name that is referred to as a template.
963 ///
964 /// By default, performs semantic analysis to determine whether the name can
965 /// be resolved to a specific template, then builds the appropriate kind of
966 /// template name. Subclasses may override this routine to provide different
967 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000968 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
969 const IdentifierInfo &Name,
970 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000971 QualType ObjectType,
972 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000973
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000974 /// \brief Build a new template name given a nested name specifier and the
975 /// overloaded operator name that is referred to as a template.
976 ///
977 /// By default, performs semantic analysis to determine whether the name can
978 /// be resolved to a specific template, then builds the appropriate kind of
979 /// template name. Subclasses may override this routine to provide different
980 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000981 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000982 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000983 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000984 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000985
986 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +0000987 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000988 ///
989 /// By default, performs semantic analysis to determine whether the name can
990 /// be resolved to a specific template, then builds the appropriate kind of
991 /// template name. Subclasses may override this routine to provide different
992 /// behavior.
993 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
994 const TemplateArgument &ArgPack) {
995 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
996 }
997
Douglas Gregor43959a92009-08-20 07:17:43 +0000998 /// \brief Build a new compound statement.
999 ///
1000 /// By default, performs semantic analysis to build the new statement.
1001 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001002 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001003 MultiStmtArg Statements,
1004 SourceLocation RBraceLoc,
1005 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001006 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001007 IsStmtExpr);
1008 }
1009
1010 /// \brief Build a new case statement.
1011 ///
1012 /// By default, performs semantic analysis to build the new statement.
1013 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001014 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001015 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001016 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001017 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001018 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001019 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001020 ColonLoc);
1021 }
Mike Stump1eb44332009-09-09 15:08:12 +00001022
Douglas Gregor43959a92009-08-20 07:17:43 +00001023 /// \brief Attach the body to a new case statement.
1024 ///
1025 /// By default, performs semantic analysis to build the new statement.
1026 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001027 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001028 getSema().ActOnCaseStmtBody(S, Body);
1029 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001030 }
Mike Stump1eb44332009-09-09 15:08:12 +00001031
Douglas Gregor43959a92009-08-20 07:17:43 +00001032 /// \brief Build a new default statement.
1033 ///
1034 /// By default, performs semantic analysis to build the new statement.
1035 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001036 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001037 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001038 Stmt *SubStmt) {
1039 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001040 /*CurScope=*/0);
1041 }
Mike Stump1eb44332009-09-09 15:08:12 +00001042
Douglas Gregor43959a92009-08-20 07:17:43 +00001043 /// \brief Build a new label statement.
1044 ///
1045 /// By default, performs semantic analysis to build the new statement.
1046 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001047 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1048 SourceLocation ColonLoc, Stmt *SubStmt) {
1049 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001050 }
Mike Stump1eb44332009-09-09 15:08:12 +00001051
Richard Smith534986f2012-04-14 00:33:13 +00001052 /// \brief Build a new label statement.
1053 ///
1054 /// By default, performs semantic analysis to build the new statement.
1055 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001056 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1057 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001058 Stmt *SubStmt) {
1059 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1060 }
1061
Douglas Gregor43959a92009-08-20 07:17:43 +00001062 /// \brief Build a new "if" statement.
1063 ///
1064 /// By default, performs semantic analysis to build the new statement.
1065 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001066 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001067 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001068 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001069 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001070 }
Mike Stump1eb44332009-09-09 15:08:12 +00001071
Douglas Gregor43959a92009-08-20 07:17:43 +00001072 /// \brief Start building a new switch statement.
1073 ///
1074 /// By default, performs semantic analysis to build the new statement.
1075 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001076 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001077 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001078 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001079 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001080 }
Mike Stump1eb44332009-09-09 15:08:12 +00001081
Douglas Gregor43959a92009-08-20 07:17:43 +00001082 /// \brief Attach the body to the switch statement.
1083 ///
1084 /// By default, performs semantic analysis to build the new statement.
1085 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001086 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001087 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001088 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001089 }
1090
1091 /// \brief Build a new while statement.
1092 ///
1093 /// By default, performs semantic analysis to build the new statement.
1094 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001095 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1096 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001097 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001098 }
Mike Stump1eb44332009-09-09 15:08:12 +00001099
Douglas Gregor43959a92009-08-20 07:17:43 +00001100 /// \brief Build a new do-while statement.
1101 ///
1102 /// By default, performs semantic analysis to build the new statement.
1103 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001104 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001105 SourceLocation WhileLoc, SourceLocation LParenLoc,
1106 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001107 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1108 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001109 }
1110
1111 /// \brief Build a new for statement.
1112 ///
1113 /// By default, performs semantic analysis to build the new statement.
1114 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001115 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001116 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001117 VarDecl *CondVar, Sema::FullExprArg Inc,
1118 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001119 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001120 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001121 }
Mike Stump1eb44332009-09-09 15:08:12 +00001122
Douglas Gregor43959a92009-08-20 07:17:43 +00001123 /// \brief Build a new goto statement.
1124 ///
1125 /// By default, performs semantic analysis to build the new statement.
1126 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001127 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1128 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001129 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001130 }
1131
1132 /// \brief Build a new indirect goto statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001136 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001137 SourceLocation StarLoc,
1138 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001139 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001140 }
Mike Stump1eb44332009-09-09 15:08:12 +00001141
Douglas Gregor43959a92009-08-20 07:17:43 +00001142 /// \brief Build a new return statement.
1143 ///
1144 /// By default, performs semantic analysis to build the new statement.
1145 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001146 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001147 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001148 }
Mike Stump1eb44332009-09-09 15:08:12 +00001149
Douglas Gregor43959a92009-08-20 07:17:43 +00001150 /// \brief Build a new declaration statement.
1151 ///
1152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001154 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001155 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001156 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001157 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1158 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001159 }
Mike Stump1eb44332009-09-09 15:08:12 +00001160
Anders Carlsson703e3942010-01-24 05:50:09 +00001161 /// \brief Build a new inline asm statement.
1162 ///
1163 /// By default, performs semantic analysis to build the new statement.
1164 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001165 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1166 bool IsVolatile, unsigned NumOutputs,
1167 unsigned NumInputs, IdentifierInfo **Names,
1168 MultiExprArg Constraints, MultiExprArg Exprs,
1169 Expr *AsmString, MultiExprArg Clobbers,
1170 SourceLocation RParenLoc) {
1171 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1172 NumInputs, Names, Constraints, Exprs,
1173 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001174 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001175
Chad Rosier8cd64b42012-06-11 20:47:18 +00001176 /// \brief Build a new MS style inline asm statement.
1177 ///
1178 /// By default, performs semantic analysis to build the new statement.
1179 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001180 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
1181 ArrayRef<Token> AsmToks, SourceLocation EndLoc) {
Chad Rosier7bd092b2012-08-15 16:53:30 +00001182 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001183 }
1184
James Dennett699c9042012-06-15 07:13:21 +00001185 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001186 ///
1187 /// By default, performs semantic analysis to build the new statement.
1188 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001189 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001190 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001191 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001192 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001193 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001194 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001195 }
1196
Douglas Gregorbe270a02010-04-26 17:57:08 +00001197 /// \brief Rebuild an Objective-C exception declaration.
1198 ///
1199 /// By default, performs semantic analysis to build the new declaration.
1200 /// Subclasses may override this routine to provide different behavior.
1201 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1202 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001203 return getSema().BuildObjCExceptionDecl(TInfo, T,
1204 ExceptionDecl->getInnerLocStart(),
1205 ExceptionDecl->getLocation(),
1206 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001207 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001208
James Dennett699c9042012-06-15 07:13:21 +00001209 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001210 ///
1211 /// By default, performs semantic analysis to build the new statement.
1212 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001213 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001214 SourceLocation RParenLoc,
1215 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001216 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001217 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001218 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001219 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001220
James Dennett699c9042012-06-15 07:13:21 +00001221 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001225 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001226 Stmt *Body) {
1227 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001228 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001229
James Dennett699c9042012-06-15 07:13:21 +00001230 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001231 ///
1232 /// By default, performs semantic analysis to build the new statement.
1233 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001234 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001235 Expr *Operand) {
1236 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001237 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001238
James Dennett699c9042012-06-15 07:13:21 +00001239 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001240 ///
1241 /// By default, performs semantic analysis to build the new statement.
1242 /// Subclasses may override this routine to provide different behavior.
1243 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1244 Expr *object) {
1245 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1246 }
1247
James Dennett699c9042012-06-15 07:13:21 +00001248 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001249 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001250 /// By default, performs semantic analysis to build the new statement.
1251 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001252 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001253 Expr *Object, Stmt *Body) {
1254 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001255 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001256
James Dennett699c9042012-06-15 07:13:21 +00001257 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001258 ///
1259 /// By default, performs semantic analysis to build the new statement.
1260 /// Subclasses may override this routine to provide different behavior.
1261 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1262 Stmt *Body) {
1263 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1264 }
John McCall990567c2011-07-27 01:07:15 +00001265
Douglas Gregorc3203e72010-04-22 23:10:45 +00001266 /// \brief Build a new Objective-C fast enumeration statement.
1267 ///
1268 /// By default, performs semantic analysis to build the new statement.
1269 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001270 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001271 Stmt *Element,
1272 Expr *Collection,
1273 SourceLocation RParenLoc,
1274 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001275 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001276 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001277 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001278 RParenLoc);
1279 if (ForEachStmt.isInvalid())
1280 return StmtError();
1281
1282 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001283 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001284
Douglas Gregor43959a92009-08-20 07:17:43 +00001285 /// \brief Build a new C++ exception declaration.
1286 ///
1287 /// By default, performs semantic analysis to build the new decaration.
1288 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001289 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001290 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001291 SourceLocation StartLoc,
1292 SourceLocation IdLoc,
1293 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001294 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1295 StartLoc, IdLoc, Id);
1296 if (Var)
1297 getSema().CurContext->addDecl(Var);
1298 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001299 }
1300
1301 /// \brief Build a new C++ catch statement.
1302 ///
1303 /// By default, performs semantic analysis to build the new statement.
1304 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001305 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001306 VarDecl *ExceptionDecl,
1307 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001308 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1309 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001310 }
Mike Stump1eb44332009-09-09 15:08:12 +00001311
Douglas Gregor43959a92009-08-20 07:17:43 +00001312 /// \brief Build a new C++ try statement.
1313 ///
1314 /// By default, performs semantic analysis to build the new statement.
1315 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001316 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001317 Stmt *TryBlock,
1318 MultiStmtArg Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001319 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001320 }
Mike Stump1eb44332009-09-09 15:08:12 +00001321
Richard Smithad762fc2011-04-14 22:09:26 +00001322 /// \brief Build a new C++0x range-based for statement.
1323 ///
1324 /// By default, performs semantic analysis to build the new statement.
1325 /// Subclasses may override this routine to provide different behavior.
1326 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1327 SourceLocation ColonLoc,
1328 Stmt *Range, Stmt *BeginEnd,
1329 Expr *Cond, Expr *Inc,
1330 Stmt *LoopVar,
1331 SourceLocation RParenLoc) {
1332 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001333 Cond, Inc, LoopVar, RParenLoc,
1334 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001335 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001336
1337 /// \brief Build a new C++0x range-based for statement.
1338 ///
1339 /// By default, performs semantic analysis to build the new statement.
1340 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001341 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001342 bool IsIfExists,
1343 NestedNameSpecifierLoc QualifierLoc,
1344 DeclarationNameInfo NameInfo,
1345 Stmt *Nested) {
1346 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1347 QualifierLoc, NameInfo, Nested);
1348 }
1349
Richard Smithad762fc2011-04-14 22:09:26 +00001350 /// \brief Attach body to a C++0x range-based for statement.
1351 ///
1352 /// By default, performs semantic analysis to finish the new statement.
1353 /// Subclasses may override this routine to provide different behavior.
1354 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1355 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1356 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001357
John Wiegley28bbe4b2011-04-28 01:08:34 +00001358 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1359 SourceLocation TryLoc,
1360 Stmt *TryBlock,
1361 Stmt *Handler) {
1362 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1363 }
1364
1365 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1366 Expr *FilterExpr,
1367 Stmt *Block) {
1368 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1369 }
1370
1371 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1372 Stmt *Block) {
1373 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1374 }
1375
Douglas Gregorb98b1992009-08-11 05:31:07 +00001376 /// \brief Build a new expression that references a declaration.
1377 ///
1378 /// By default, performs semantic analysis to build the new expression.
1379 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001380 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001381 LookupResult &R,
1382 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001383 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1384 }
1385
1386
1387 /// \brief Build a new expression that references a declaration.
1388 ///
1389 /// By default, performs semantic analysis to build the new expression.
1390 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001391 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001392 ValueDecl *VD,
1393 const DeclarationNameInfo &NameInfo,
1394 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001395 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001396 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001397
1398 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001399
1400 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001401 }
Mike Stump1eb44332009-09-09 15:08:12 +00001402
Douglas Gregorb98b1992009-08-11 05:31:07 +00001403 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001404 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001405 /// By default, performs semantic analysis to build the new expression.
1406 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001407 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001408 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001409 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001410 }
1411
Douglas Gregora71d8192009-09-04 17:36:40 +00001412 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001413 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001414 /// By default, performs semantic analysis to build the new expression.
1415 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001416 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001417 SourceLocation OperatorLoc,
1418 bool isArrow,
1419 CXXScopeSpec &SS,
1420 TypeSourceInfo *ScopeType,
1421 SourceLocation CCLoc,
1422 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001423 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001424
Douglas Gregorb98b1992009-08-11 05:31:07 +00001425 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001426 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001427 /// By default, performs semantic analysis to build the new expression.
1428 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001429 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001430 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001431 Expr *SubExpr) {
1432 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001433 }
Mike Stump1eb44332009-09-09 15:08:12 +00001434
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001435 /// \brief Build a new builtin offsetof expression.
1436 ///
1437 /// By default, performs semantic analysis to build the new expression.
1438 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001439 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001440 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001441 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001442 unsigned NumComponents,
1443 SourceLocation RParenLoc) {
1444 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1445 NumComponents, RParenLoc);
1446 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001447
1448 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001449 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001450 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001451 /// By default, performs semantic analysis to build the new expression.
1452 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001453 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1454 SourceLocation OpLoc,
1455 UnaryExprOrTypeTrait ExprKind,
1456 SourceRange R) {
1457 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001458 }
1459
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001460 /// \brief Build a new sizeof, alignof or vec step expression with an
1461 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001462 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001463 /// By default, performs semantic analysis to build the new expression.
1464 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001465 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1466 UnaryExprOrTypeTrait ExprKind,
1467 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001468 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001469 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001470 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001471 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001472
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001473 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001474 }
Mike Stump1eb44332009-09-09 15:08:12 +00001475
Douglas Gregorb98b1992009-08-11 05:31:07 +00001476 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001477 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001478 /// By default, performs semantic analysis to build the new expression.
1479 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001480 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001481 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001482 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001483 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001484 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1485 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001486 RBracketLoc);
1487 }
1488
1489 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001490 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001491 /// By default, performs semantic analysis to build the new expression.
1492 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001493 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001494 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001495 SourceLocation RParenLoc,
1496 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001497 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001498 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001499 }
1500
1501 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001502 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001503 /// By default, performs semantic analysis to build the new expression.
1504 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001505 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001506 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001507 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001508 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001509 const DeclarationNameInfo &MemberNameInfo,
1510 ValueDecl *Member,
1511 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001512 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001513 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001514 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1515 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001516 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001517 // We have a reference to an unnamed field. This is always the
1518 // base of an anonymous struct/union member access, i.e. the
1519 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001520 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001521 assert(Member->getType()->isRecordType() &&
1522 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001523
Richard Smith9138b4e2011-10-26 19:06:56 +00001524 BaseResult =
1525 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001526 QualifierLoc.getNestedNameSpecifier(),
1527 FoundDecl, Member);
1528 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001529 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001530 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001531 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001532 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001533 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001534 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001535 cast<FieldDecl>(Member)->getType(),
1536 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001537 return getSema().Owned(ME);
1538 }
Mike Stump1eb44332009-09-09 15:08:12 +00001539
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001540 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001541 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001542
John Wiegley429bb272011-04-08 18:41:53 +00001543 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001544 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001545
John McCall6bb80172010-03-30 21:47:33 +00001546 // FIXME: this involves duplicating earlier analysis in a lot of
1547 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001548 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001549 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001550 R.resolveKind();
1551
John McCall9ae2f072010-08-23 23:25:46 +00001552 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001553 SS, TemplateKWLoc,
1554 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001555 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001556 }
Mike Stump1eb44332009-09-09 15:08:12 +00001557
Douglas Gregorb98b1992009-08-11 05:31:07 +00001558 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001559 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001560 /// By default, performs semantic analysis to build the new expression.
1561 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001562 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001563 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001564 Expr *LHS, Expr *RHS) {
1565 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001566 }
1567
1568 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001569 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001570 /// By default, performs semantic analysis to build the new expression.
1571 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001572 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001573 SourceLocation QuestionLoc,
1574 Expr *LHS,
1575 SourceLocation ColonLoc,
1576 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001577 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1578 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001579 }
1580
Douglas Gregorb98b1992009-08-11 05:31:07 +00001581 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001582 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001583 /// By default, performs semantic analysis to build the new expression.
1584 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001585 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001586 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001587 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001588 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001589 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001590 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001591 }
Mike Stump1eb44332009-09-09 15:08:12 +00001592
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001594 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 /// By default, performs semantic analysis to build the new expression.
1596 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001597 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001598 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001600 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001601 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001602 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 }
Mike Stump1eb44332009-09-09 15:08:12 +00001604
Douglas Gregorb98b1992009-08-11 05:31:07 +00001605 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001606 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001607 /// By default, performs semantic analysis to build the new expression.
1608 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001609 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001610 SourceLocation OpLoc,
1611 SourceLocation AccessorLoc,
1612 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001613
John McCall129e2df2009-11-30 22:42:35 +00001614 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001615 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001616 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001617 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001618 SS, SourceLocation(),
1619 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001620 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001621 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001622 }
Mike Stump1eb44332009-09-09 15:08:12 +00001623
Douglas Gregorb98b1992009-08-11 05:31:07 +00001624 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001625 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001626 /// By default, performs semantic analysis to build the new expression.
1627 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001628 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001629 MultiExprArg Inits,
1630 SourceLocation RBraceLoc,
1631 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001632 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001633 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001634 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001635 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001636
Douglas Gregore48319a2009-11-09 17:16:50 +00001637 // Patch in the result type we were given, which may have been computed
1638 // when the initial InitListExpr was built.
1639 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1640 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001641 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001642 }
Mike Stump1eb44332009-09-09 15:08:12 +00001643
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001645 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 /// By default, performs semantic analysis to build the new expression.
1647 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001648 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001649 MultiExprArg ArrayExprs,
1650 SourceLocation EqualOrColonLoc,
1651 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001652 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001653 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001654 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001655 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001656 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001657 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001658
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001659 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001660 }
Mike Stump1eb44332009-09-09 15:08:12 +00001661
Douglas Gregorb98b1992009-08-11 05:31:07 +00001662 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001663 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 /// By default, builds the implicit value initialization without performing
1665 /// any semantic analysis. Subclasses may override this routine to provide
1666 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001667 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1669 }
Mike Stump1eb44332009-09-09 15:08:12 +00001670
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001672 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 /// By default, performs semantic analysis to build the new expression.
1674 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001675 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001676 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001677 SourceLocation RParenLoc) {
1678 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001679 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001680 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001681 }
1682
1683 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001684 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001685 /// By default, performs semantic analysis to build the new expression.
1686 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001687 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001688 MultiExprArg SubExprs,
1689 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001690 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 }
Mike Stump1eb44332009-09-09 15:08:12 +00001692
Douglas Gregorb98b1992009-08-11 05:31:07 +00001693 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001694 ///
1695 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 /// rather than attempting to map the label statement itself.
1697 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001698 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001699 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001700 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001701 }
Mike Stump1eb44332009-09-09 15:08:12 +00001702
Douglas Gregorb98b1992009-08-11 05:31:07 +00001703 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001704 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001705 /// By default, performs semantic analysis to build the new expression.
1706 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001707 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001708 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001709 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001710 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001711 }
Mike Stump1eb44332009-09-09 15:08:12 +00001712
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 /// \brief Build a new __builtin_choose_expr expression.
1714 ///
1715 /// By default, performs semantic analysis to build the new expression.
1716 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001717 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001718 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001719 SourceLocation RParenLoc) {
1720 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001721 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 RParenLoc);
1723 }
Mike Stump1eb44332009-09-09 15:08:12 +00001724
Peter Collingbournef111d932011-04-15 00:35:48 +00001725 /// \brief Build a new generic selection expression.
1726 ///
1727 /// By default, performs semantic analysis to build the new expression.
1728 /// Subclasses may override this routine to provide different behavior.
1729 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1730 SourceLocation DefaultLoc,
1731 SourceLocation RParenLoc,
1732 Expr *ControllingExpr,
1733 TypeSourceInfo **Types,
1734 Expr **Exprs,
1735 unsigned NumAssocs) {
1736 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1737 ControllingExpr, Types, Exprs,
1738 NumAssocs);
1739 }
1740
Douglas Gregorb98b1992009-08-11 05:31:07 +00001741 /// \brief Build a new overloaded operator call expression.
1742 ///
1743 /// By default, performs semantic analysis to build the new expression.
1744 /// The semantic analysis provides the behavior of template instantiation,
1745 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001746 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001747 /// argument-dependent lookup, etc. Subclasses may override this routine to
1748 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001749 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001750 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001751 Expr *Callee,
1752 Expr *First,
1753 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001754
1755 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 /// reinterpret_cast.
1757 ///
1758 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001759 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001760 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001761 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001762 Stmt::StmtClass Class,
1763 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001764 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765 SourceLocation RAngleLoc,
1766 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001767 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001768 SourceLocation RParenLoc) {
1769 switch (Class) {
1770 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001771 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001772 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001773 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001774
1775 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001776 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001777 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001778 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001779
Douglas Gregorb98b1992009-08-11 05:31:07 +00001780 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001781 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001782 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001783 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001784 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001785
Douglas Gregorb98b1992009-08-11 05:31:07 +00001786 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001787 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001788 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001789 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001790
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001792 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001794 }
Mike Stump1eb44332009-09-09 15:08:12 +00001795
Douglas Gregorb98b1992009-08-11 05:31:07 +00001796 /// \brief Build a new C++ static_cast expression.
1797 ///
1798 /// By default, performs semantic analysis to build the new expression.
1799 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001800 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001802 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 SourceLocation RAngleLoc,
1804 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001805 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001807 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001808 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001809 SourceRange(LAngleLoc, RAngleLoc),
1810 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 }
1812
1813 /// \brief Build a new C++ dynamic_cast expression.
1814 ///
1815 /// By default, performs semantic analysis to build the new expression.
1816 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001817 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001818 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001819 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001820 SourceLocation RAngleLoc,
1821 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001822 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001823 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001824 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001825 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001826 SourceRange(LAngleLoc, RAngleLoc),
1827 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001828 }
1829
1830 /// \brief Build a new C++ reinterpret_cast expression.
1831 ///
1832 /// By default, performs semantic analysis to build the new expression.
1833 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001834 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001835 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001836 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001837 SourceLocation RAngleLoc,
1838 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001839 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001840 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001841 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001842 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001843 SourceRange(LAngleLoc, RAngleLoc),
1844 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001845 }
1846
1847 /// \brief Build a new C++ const_cast expression.
1848 ///
1849 /// By default, performs semantic analysis to build the new expression.
1850 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001851 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001852 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001853 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001854 SourceLocation RAngleLoc,
1855 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001856 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001857 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001858 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001859 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001860 SourceRange(LAngleLoc, RAngleLoc),
1861 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001862 }
Mike Stump1eb44332009-09-09 15:08:12 +00001863
Douglas Gregorb98b1992009-08-11 05:31:07 +00001864 /// \brief Build a new C++ functional-style cast expression.
1865 ///
1866 /// By default, performs semantic analysis to build the new expression.
1867 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001868 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1869 SourceLocation LParenLoc,
1870 Expr *Sub,
1871 SourceLocation RParenLoc) {
1872 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001873 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001874 RParenLoc);
1875 }
Mike Stump1eb44332009-09-09 15:08:12 +00001876
Douglas Gregorb98b1992009-08-11 05:31:07 +00001877 /// \brief Build a new C++ typeid(type) expression.
1878 ///
1879 /// By default, performs semantic analysis to build the new expression.
1880 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001881 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001882 SourceLocation TypeidLoc,
1883 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001884 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001885 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001886 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001887 }
Mike Stump1eb44332009-09-09 15:08:12 +00001888
Francois Pichet01b7c302010-09-08 12:20:18 +00001889
Douglas Gregorb98b1992009-08-11 05:31:07 +00001890 /// \brief Build a new C++ typeid(expr) expression.
1891 ///
1892 /// By default, performs semantic analysis to build the new expression.
1893 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001894 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001895 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001896 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001897 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001898 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001899 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001900 }
1901
Francois Pichet01b7c302010-09-08 12:20:18 +00001902 /// \brief Build a new C++ __uuidof(type) expression.
1903 ///
1904 /// By default, performs semantic analysis to build the new expression.
1905 /// Subclasses may override this routine to provide different behavior.
1906 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1907 SourceLocation TypeidLoc,
1908 TypeSourceInfo *Operand,
1909 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001910 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001911 RParenLoc);
1912 }
1913
1914 /// \brief Build a new C++ __uuidof(expr) expression.
1915 ///
1916 /// By default, performs semantic analysis to build the new expression.
1917 /// Subclasses may override this routine to provide different behavior.
1918 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1919 SourceLocation TypeidLoc,
1920 Expr *Operand,
1921 SourceLocation RParenLoc) {
1922 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1923 RParenLoc);
1924 }
1925
Douglas Gregorb98b1992009-08-11 05:31:07 +00001926 /// \brief Build a new C++ "this" expression.
1927 ///
1928 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001929 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001930 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001931 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001932 QualType ThisType,
1933 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001934 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001936 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1937 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001938 }
1939
1940 /// \brief Build a new C++ throw expression.
1941 ///
1942 /// By default, performs semantic analysis to build the new expression.
1943 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001944 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1945 bool IsThrownVariableInScope) {
1946 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001947 }
1948
1949 /// \brief Build a new C++ default-argument expression.
1950 ///
1951 /// By default, builds a new default-argument expression, which does not
1952 /// require any semantic analysis. Subclasses may override this routine to
1953 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001954 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001955 ParmVarDecl *Param) {
1956 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1957 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001958 }
1959
1960 /// \brief Build a new C++ zero-initialization expression.
1961 ///
1962 /// By default, performs semantic analysis to build the new expression.
1963 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001964 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1965 SourceLocation LParenLoc,
1966 SourceLocation RParenLoc) {
1967 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Benjamin Kramer5354e772012-08-23 23:38:35 +00001968 MultiExprArg(), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001969 }
Mike Stump1eb44332009-09-09 15:08:12 +00001970
Douglas Gregorb98b1992009-08-11 05:31:07 +00001971 /// \brief Build a new C++ "new" expression.
1972 ///
1973 /// By default, performs semantic analysis to build the new expression.
1974 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001975 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001976 bool UseGlobal,
1977 SourceLocation PlacementLParen,
1978 MultiExprArg PlacementArgs,
1979 SourceLocation PlacementRParen,
1980 SourceRange TypeIdParens,
1981 QualType AllocatedType,
1982 TypeSourceInfo *AllocatedTypeInfo,
1983 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001984 SourceRange DirectInitRange,
1985 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001986 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001987 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001988 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001989 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001990 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001991 AllocatedType,
1992 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001993 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001994 DirectInitRange,
1995 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001996 }
Mike Stump1eb44332009-09-09 15:08:12 +00001997
Douglas Gregorb98b1992009-08-11 05:31:07 +00001998 /// \brief Build a new C++ "delete" expression.
1999 ///
2000 /// By default, performs semantic analysis to build the new expression.
2001 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002002 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002003 bool IsGlobalDelete,
2004 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002005 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002006 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002007 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002008 }
Mike Stump1eb44332009-09-09 15:08:12 +00002009
Douglas Gregorb98b1992009-08-11 05:31:07 +00002010 /// \brief Build a new unary type trait expression.
2011 ///
2012 /// By default, performs semantic analysis to build the new expression.
2013 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002014 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002015 SourceLocation StartLoc,
2016 TypeSourceInfo *T,
2017 SourceLocation RParenLoc) {
2018 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002019 }
2020
Francois Pichet6ad6f282010-12-07 00:08:36 +00002021 /// \brief Build a new binary type trait expression.
2022 ///
2023 /// By default, performs semantic analysis to build the new expression.
2024 /// Subclasses may override this routine to provide different behavior.
2025 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2026 SourceLocation StartLoc,
2027 TypeSourceInfo *LhsT,
2028 TypeSourceInfo *RhsT,
2029 SourceLocation RParenLoc) {
2030 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2031 }
2032
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002033 /// \brief Build a new type trait expression.
2034 ///
2035 /// By default, performs semantic analysis to build the new expression.
2036 /// Subclasses may override this routine to provide different behavior.
2037 ExprResult RebuildTypeTrait(TypeTrait Trait,
2038 SourceLocation StartLoc,
2039 ArrayRef<TypeSourceInfo *> Args,
2040 SourceLocation RParenLoc) {
2041 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2042 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002043
John Wiegley21ff2e52011-04-28 00:16:57 +00002044 /// \brief Build a new array type trait expression.
2045 ///
2046 /// By default, performs semantic analysis to build the new expression.
2047 /// Subclasses may override this routine to provide different behavior.
2048 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2049 SourceLocation StartLoc,
2050 TypeSourceInfo *TSInfo,
2051 Expr *DimExpr,
2052 SourceLocation RParenLoc) {
2053 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2054 }
2055
John Wiegley55262202011-04-25 06:54:41 +00002056 /// \brief Build a new expression trait expression.
2057 ///
2058 /// By default, performs semantic analysis to build the new expression.
2059 /// Subclasses may override this routine to provide different behavior.
2060 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2061 SourceLocation StartLoc,
2062 Expr *Queried,
2063 SourceLocation RParenLoc) {
2064 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2065 }
2066
Mike Stump1eb44332009-09-09 15:08:12 +00002067 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002068 /// expression.
2069 ///
2070 /// By default, performs semantic analysis to build the new expression.
2071 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002072 ExprResult RebuildDependentScopeDeclRefExpr(
2073 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002074 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002075 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002076 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002077 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002078 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002079
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002080 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002081 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002082 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002083
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002084 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002085 }
2086
2087 /// \brief Build a new template-id expression.
2088 ///
2089 /// By default, performs semantic analysis to build the new expression.
2090 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002091 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002092 SourceLocation TemplateKWLoc,
2093 LookupResult &R,
2094 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002095 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002096 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2097 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002098 }
2099
2100 /// \brief Build a new object-construction expression.
2101 ///
2102 /// By default, performs semantic analysis to build the new expression.
2103 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002104 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002105 SourceLocation Loc,
2106 CXXConstructorDecl *Constructor,
2107 bool IsElidable,
2108 MultiExprArg Args,
2109 bool HadMultipleCandidates,
2110 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002111 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002112 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002113 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002114 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002115 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002116 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002117
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002118 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002119 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002120 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002121 RequiresZeroInit, ConstructKind,
2122 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002123 }
2124
2125 /// \brief Build a new object-construction expression.
2126 ///
2127 /// By default, performs semantic analysis to build the new expression.
2128 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002129 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2130 SourceLocation LParenLoc,
2131 MultiExprArg Args,
2132 SourceLocation RParenLoc) {
2133 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002134 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002135 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002136 RParenLoc);
2137 }
2138
2139 /// \brief Build a new object-construction expression.
2140 ///
2141 /// By default, performs semantic analysis to build the new expression.
2142 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002143 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2144 SourceLocation LParenLoc,
2145 MultiExprArg Args,
2146 SourceLocation RParenLoc) {
2147 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002148 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002149 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002150 RParenLoc);
2151 }
Mike Stump1eb44332009-09-09 15:08:12 +00002152
Douglas Gregorb98b1992009-08-11 05:31:07 +00002153 /// \brief Build a new member reference expression.
2154 ///
2155 /// By default, performs semantic analysis to build the new expression.
2156 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002157 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002158 QualType BaseType,
2159 bool IsArrow,
2160 SourceLocation OperatorLoc,
2161 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002162 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002163 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002164 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002165 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002166 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002167 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002168
John McCall9ae2f072010-08-23 23:25:46 +00002169 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002170 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002171 SS, TemplateKWLoc,
2172 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002173 MemberNameInfo,
2174 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002175 }
2176
John McCall129e2df2009-11-30 22:42:35 +00002177 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002178 ///
2179 /// By default, performs semantic analysis to build the new expression.
2180 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002181 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2182 SourceLocation OperatorLoc,
2183 bool IsArrow,
2184 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002185 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002186 NamedDecl *FirstQualifierInScope,
2187 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002188 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002189 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002190 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002191
John McCall9ae2f072010-08-23 23:25:46 +00002192 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002193 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002194 SS, TemplateKWLoc,
2195 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002196 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002197 }
Mike Stump1eb44332009-09-09 15:08:12 +00002198
Sebastian Redl2e156222010-09-10 20:55:43 +00002199 /// \brief Build a new noexcept expression.
2200 ///
2201 /// By default, performs semantic analysis to build the new expression.
2202 /// Subclasses may override this routine to provide different behavior.
2203 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2204 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2205 }
2206
Douglas Gregoree8aff02011-01-04 17:33:58 +00002207 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002208 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2209 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002210 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002211 llvm::Optional<unsigned> Length) {
2212 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002213 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2214 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002215 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002216
2217 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2218 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002219 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002220 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002221
Patrick Beardeb382ec2012-04-19 00:25:12 +00002222 /// \brief Build a new Objective-C boxed expression.
2223 ///
2224 /// By default, performs semantic analysis to build the new expression.
2225 /// Subclasses may override this routine to provide different behavior.
2226 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2227 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2228 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002229
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002230 /// \brief Build a new Objective-C array literal.
2231 ///
2232 /// By default, performs semantic analysis to build the new expression.
2233 /// Subclasses may override this routine to provide different behavior.
2234 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2235 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002236 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002237 MultiExprArg(Elements, NumElements));
2238 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002239
2240 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002241 Expr *Base, Expr *Key,
2242 ObjCMethodDecl *getterMethod,
2243 ObjCMethodDecl *setterMethod) {
2244 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2245 getterMethod, setterMethod);
2246 }
2247
2248 /// \brief Build a new Objective-C dictionary literal.
2249 ///
2250 /// By default, performs semantic analysis to build the new expression.
2251 /// Subclasses may override this routine to provide different behavior.
2252 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2253 ObjCDictionaryElement *Elements,
2254 unsigned NumElements) {
2255 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2256 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002257
James Dennett699c9042012-06-15 07:13:21 +00002258 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002259 ///
2260 /// By default, performs semantic analysis to build the new expression.
2261 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002262 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002263 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002264 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002265 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002266 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002267 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002268
Douglas Gregor92e986e2010-04-22 16:44:27 +00002269 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002270 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002271 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002272 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002273 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002274 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002275 MultiExprArg Args,
2276 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002277 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2278 ReceiverTypeInfo->getType(),
2279 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002280 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002281 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002282 }
2283
2284 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002285 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002286 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002287 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002288 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002289 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002290 MultiExprArg Args,
2291 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002292 return SemaRef.BuildInstanceMessage(Receiver,
2293 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002294 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002295 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002296 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002297 }
2298
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002299 /// \brief Build a new Objective-C ivar reference expression.
2300 ///
2301 /// By default, performs semantic analysis to build the new expression.
2302 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002303 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002304 SourceLocation IvarLoc,
2305 bool IsArrow, bool IsFreeIvar) {
2306 // FIXME: We lose track of the IsFreeIvar bit.
2307 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002308 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002309 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2310 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002311 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002312 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002313 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002314 false);
John Wiegley429bb272011-04-08 18:41:53 +00002315 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002316 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002317
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002318 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002319 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002320
John Wiegley429bb272011-04-08 18:41:53 +00002321 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002322 /*FIXME:*/IvarLoc, IsArrow,
2323 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002324 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002325 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002326 /*TemplateArgs=*/0);
2327 }
Douglas Gregore3303542010-04-26 20:47:02 +00002328
2329 /// \brief Build a new Objective-C property reference expression.
2330 ///
2331 /// By default, performs semantic analysis to build the new expression.
2332 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002333 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002334 ObjCPropertyDecl *Property,
2335 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002336 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002337 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002338 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2339 Sema::LookupMemberName);
2340 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002341 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002342 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002343 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002344 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002345 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002346
Douglas Gregore3303542010-04-26 20:47:02 +00002347 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002348 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002349
John Wiegley429bb272011-04-08 18:41:53 +00002350 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002351 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002352 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002353 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002354 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002355 /*TemplateArgs=*/0);
2356 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002357
John McCall12f78a62010-12-02 01:19:52 +00002358 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002359 ///
2360 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002361 /// Subclasses may override this routine to provide different behavior.
2362 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2363 ObjCMethodDecl *Getter,
2364 ObjCMethodDecl *Setter,
2365 SourceLocation PropertyLoc) {
2366 // Since these expressions can only be value-dependent, we do not
2367 // need to perform semantic analysis again.
2368 return Owned(
2369 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2370 VK_LValue, OK_ObjCProperty,
2371 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002372 }
2373
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002374 /// \brief Build a new Objective-C "isa" expression.
2375 ///
2376 /// By default, performs semantic analysis to build the new expression.
2377 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002378 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002379 bool IsArrow) {
2380 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002381 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002382 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2383 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002384 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002385 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002386 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002387 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002388 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002389
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002390 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002391 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002392
John Wiegley429bb272011-04-08 18:41:53 +00002393 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002394 /*FIXME:*/IsaLoc, IsArrow,
2395 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002396 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002397 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002398 /*TemplateArgs=*/0);
2399 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002400
Douglas Gregorb98b1992009-08-11 05:31:07 +00002401 /// \brief Build a new shuffle vector expression.
2402 ///
2403 /// By default, performs semantic analysis to build the new expression.
2404 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002405 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002406 MultiExprArg SubExprs,
2407 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002408 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002409 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002410 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2411 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2412 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2413 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002414
Douglas Gregorb98b1992009-08-11 05:31:07 +00002415 // Build a reference to the __builtin_shufflevector builtin
2416 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002417 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2418 SemaRef.Context.BuiltinFnTy,
2419 VK_RValue, BuiltinLoc);
2420 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2421 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2422 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002423
2424 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002425 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002426 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002427 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002428 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002429 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002430
Douglas Gregorb98b1992009-08-11 05:31:07 +00002431 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002432 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002433 }
John McCall43fed0d2010-11-12 08:19:04 +00002434
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002435 /// \brief Build a new template argument pack expansion.
2436 ///
2437 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002438 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002439 /// different behavior.
2440 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002441 SourceLocation EllipsisLoc,
2442 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002443 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002444 case TemplateArgument::Expression: {
2445 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002446 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2447 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002448 if (Result.isInvalid())
2449 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002450
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002451 return TemplateArgumentLoc(Result.get(), Result.get());
2452 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002453
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002454 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002455 return TemplateArgumentLoc(TemplateArgument(
2456 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002457 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002458 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002459 Pattern.getTemplateNameLoc(),
2460 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002461
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002462 case TemplateArgument::Null:
2463 case TemplateArgument::Integral:
2464 case TemplateArgument::Declaration:
2465 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002466 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002467 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002468 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002469
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002470 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002471 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002472 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002473 EllipsisLoc,
2474 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002475 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2476 Expansion);
2477 break;
2478 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002479
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002480 return TemplateArgumentLoc();
2481 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002482
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002483 /// \brief Build a new expression pack expansion.
2484 ///
2485 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002486 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002487 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002488 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2489 llvm::Optional<unsigned> NumExpansions) {
2490 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002491 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002492
2493 /// \brief Build a new atomic operation expression.
2494 ///
2495 /// By default, performs semantic analysis to build the new expression.
2496 /// Subclasses may override this routine to provide different behavior.
2497 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2498 MultiExprArg SubExprs,
2499 QualType RetTy,
2500 AtomicExpr::AtomicOp Op,
2501 SourceLocation RParenLoc) {
2502 // Just create the expression; there is not any interesting semantic
2503 // analysis here because we can't actually build an AtomicExpr until
2504 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002505 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002506 RParenLoc);
2507 }
2508
John McCall43fed0d2010-11-12 08:19:04 +00002509private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002510 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2511 QualType ObjectType,
2512 NamedDecl *FirstQualifierInScope,
2513 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002514
2515 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2516 QualType ObjectType,
2517 NamedDecl *FirstQualifierInScope,
2518 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002519};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002520
Douglas Gregor43959a92009-08-20 07:17:43 +00002521template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002522StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002523 if (!S)
2524 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002525
Douglas Gregor43959a92009-08-20 07:17:43 +00002526 switch (S->getStmtClass()) {
2527 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002528
Douglas Gregor43959a92009-08-20 07:17:43 +00002529 // Transform individual statement nodes
2530#define STMT(Node, Parent) \
2531 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002532#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002533#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002534#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002535
Douglas Gregor43959a92009-08-20 07:17:43 +00002536 // Transform expressions by calling TransformExpr.
2537#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002538#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002539#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002540#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002541 {
John McCall60d7b3a2010-08-24 06:29:42 +00002542 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002543 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002544 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002545
John McCall9ae2f072010-08-23 23:25:46 +00002546 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002547 }
Mike Stump1eb44332009-09-09 15:08:12 +00002548 }
2549
John McCall3fa5cae2010-10-26 07:05:15 +00002550 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002551}
Mike Stump1eb44332009-09-09 15:08:12 +00002552
2553
Douglas Gregor670444e2009-08-04 22:27:00 +00002554template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002555ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002556 if (!E)
2557 return SemaRef.Owned(E);
2558
2559 switch (E->getStmtClass()) {
2560 case Stmt::NoStmtClass: break;
2561#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002562#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002563#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002564 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002565#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002566 }
2567
John McCall3fa5cae2010-10-26 07:05:15 +00002568 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002569}
2570
2571template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002572bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2573 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002574 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002575 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002576 bool *ArgChanged) {
2577 for (unsigned I = 0; I != NumInputs; ++I) {
2578 // If requested, drop call arguments that need to be dropped.
2579 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2580 if (ArgChanged)
2581 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002582
Douglas Gregoraa165f82011-01-03 19:04:46 +00002583 break;
2584 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002585
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002586 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2587 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002588
Chris Lattner686775d2011-07-20 06:58:45 +00002589 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002590 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2591 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002592
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002593 // Determine whether the set of unexpanded parameter packs can and should
2594 // be expanded.
2595 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002596 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002597 llvm::Optional<unsigned> OrigNumExpansions
2598 = Expansion->getNumExpansions();
2599 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002600 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2601 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002602 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002603 Expand, RetainExpansion,
2604 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002605 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002606
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002607 if (!Expand) {
2608 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002609 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002610 // expansion.
2611 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2612 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2613 if (OutPattern.isInvalid())
2614 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002615
2616 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002617 Expansion->getEllipsisLoc(),
2618 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002619 if (Out.isInvalid())
2620 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002621
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002622 if (ArgChanged)
2623 *ArgChanged = true;
2624 Outputs.push_back(Out.get());
2625 continue;
2626 }
John McCallc8fc90a2011-07-06 07:30:07 +00002627
2628 // Record right away that the argument was changed. This needs
2629 // to happen even if the array expands to nothing.
2630 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002631
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002632 // The transform has determined that we should perform an elementwise
2633 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002634 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002635 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2636 ExprResult Out = getDerived().TransformExpr(Pattern);
2637 if (Out.isInvalid())
2638 return true;
2639
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002640 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002641 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2642 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002643 if (Out.isInvalid())
2644 return true;
2645 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002646
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002647 Outputs.push_back(Out.get());
2648 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002649
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002650 continue;
2651 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002652
Douglas Gregoraa165f82011-01-03 19:04:46 +00002653 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2654 if (Result.isInvalid())
2655 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002656
Douglas Gregoraa165f82011-01-03 19:04:46 +00002657 if (Result.get() != Inputs[I] && ArgChanged)
2658 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002659
2660 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002661 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002662
Douglas Gregoraa165f82011-01-03 19:04:46 +00002663 return false;
2664}
2665
2666template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002667NestedNameSpecifierLoc
2668TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2669 NestedNameSpecifierLoc NNS,
2670 QualType ObjectType,
2671 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002672 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002673 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002674 Qualifier = Qualifier.getPrefix())
2675 Qualifiers.push_back(Qualifier);
2676
2677 CXXScopeSpec SS;
2678 while (!Qualifiers.empty()) {
2679 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2680 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002681
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002682 switch (QNNS->getKind()) {
2683 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002684 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002685 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002686 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002687 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002688 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002689 FirstQualifierInScope, false))
2690 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002691
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002692 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002693
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002694 case NestedNameSpecifier::Namespace: {
2695 NamespaceDecl *NS
2696 = cast_or_null<NamespaceDecl>(
2697 getDerived().TransformDecl(
2698 Q.getLocalBeginLoc(),
2699 QNNS->getAsNamespace()));
2700 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2701 break;
2702 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002703
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002704 case NestedNameSpecifier::NamespaceAlias: {
2705 NamespaceAliasDecl *Alias
2706 = cast_or_null<NamespaceAliasDecl>(
2707 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2708 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002709 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002710 Q.getLocalEndLoc());
2711 break;
2712 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002713
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002714 case NestedNameSpecifier::Global:
2715 // There is no meaningful transformation that one could perform on the
2716 // global scope.
2717 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2718 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002719
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002720 case NestedNameSpecifier::TypeSpecWithTemplate:
2721 case NestedNameSpecifier::TypeSpec: {
2722 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2723 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002724
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002725 if (!TL)
2726 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002727
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002728 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00002729 (SemaRef.getLangOpts().CPlusPlus0x &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002730 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002731 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002732 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002733 if (TL.getType()->isEnumeralType())
2734 SemaRef.Diag(TL.getBeginLoc(),
2735 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002736 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2737 Q.getLocalEndLoc());
2738 break;
2739 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002740 // If the nested-name-specifier is an invalid type def, don't emit an
2741 // error because a previous error should have already been emitted.
2742 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2743 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002744 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002745 << TL.getType() << SS.getRange();
2746 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002747 return NestedNameSpecifierLoc();
2748 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002749 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002750
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002751 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002752 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002753 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002754 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002755
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002756 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002757 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002758 !getDerived().AlwaysRebuild())
2759 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002760
2761 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002762 // nested-name-specifier, do so.
2763 if (SS.location_size() == NNS.getDataLength() &&
2764 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2765 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2766
2767 // Allocate new nested-name-specifier location information.
2768 return SS.getWithLocInContext(SemaRef.Context);
2769}
2770
2771template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002772DeclarationNameInfo
2773TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002774::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002775 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002776 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002777 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002778
2779 switch (Name.getNameKind()) {
2780 case DeclarationName::Identifier:
2781 case DeclarationName::ObjCZeroArgSelector:
2782 case DeclarationName::ObjCOneArgSelector:
2783 case DeclarationName::ObjCMultiArgSelector:
2784 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002785 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002786 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002787 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002788
Douglas Gregor81499bb2009-09-03 22:13:48 +00002789 case DeclarationName::CXXConstructorName:
2790 case DeclarationName::CXXDestructorName:
2791 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002792 TypeSourceInfo *NewTInfo;
2793 CanQualType NewCanTy;
2794 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002795 NewTInfo = getDerived().TransformType(OldTInfo);
2796 if (!NewTInfo)
2797 return DeclarationNameInfo();
2798 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002799 }
2800 else {
2801 NewTInfo = 0;
2802 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002803 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002804 if (NewT.isNull())
2805 return DeclarationNameInfo();
2806 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2807 }
Mike Stump1eb44332009-09-09 15:08:12 +00002808
Abramo Bagnara25777432010-08-11 22:01:17 +00002809 DeclarationName NewName
2810 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2811 NewCanTy);
2812 DeclarationNameInfo NewNameInfo(NameInfo);
2813 NewNameInfo.setName(NewName);
2814 NewNameInfo.setNamedTypeInfo(NewTInfo);
2815 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002816 }
Mike Stump1eb44332009-09-09 15:08:12 +00002817 }
2818
David Blaikieb219cfc2011-09-23 05:06:16 +00002819 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002820}
2821
2822template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002823TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002824TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2825 TemplateName Name,
2826 SourceLocation NameLoc,
2827 QualType ObjectType,
2828 NamedDecl *FirstQualifierInScope) {
2829 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2830 TemplateDecl *Template = QTN->getTemplateDecl();
2831 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002832
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002833 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002834 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002835 Template));
2836 if (!TransTemplate)
2837 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002838
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002839 if (!getDerived().AlwaysRebuild() &&
2840 SS.getScopeRep() == QTN->getQualifier() &&
2841 TransTemplate == Template)
2842 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002843
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002844 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2845 TransTemplate);
2846 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002847
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002848 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2849 if (SS.getScopeRep()) {
2850 // These apply to the scope specifier, not the template.
2851 ObjectType = QualType();
2852 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002853 }
2854
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002855 if (!getDerived().AlwaysRebuild() &&
2856 SS.getScopeRep() == DTN->getQualifier() &&
2857 ObjectType.isNull())
2858 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002859
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002860 if (DTN->isIdentifier()) {
2861 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002862 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002863 NameLoc,
2864 ObjectType,
2865 FirstQualifierInScope);
2866 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002867
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002868 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2869 ObjectType);
2870 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002871
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002872 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2873 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002874 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002875 Template));
2876 if (!TransTemplate)
2877 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002878
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002879 if (!getDerived().AlwaysRebuild() &&
2880 TransTemplate == Template)
2881 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002882
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002883 return TemplateName(TransTemplate);
2884 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002885
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002886 if (SubstTemplateTemplateParmPackStorage *SubstPack
2887 = Name.getAsSubstTemplateTemplateParmPack()) {
2888 TemplateTemplateParmDecl *TransParam
2889 = cast_or_null<TemplateTemplateParmDecl>(
2890 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2891 if (!TransParam)
2892 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002893
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002894 if (!getDerived().AlwaysRebuild() &&
2895 TransParam == SubstPack->getParameterPack())
2896 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002897
2898 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002899 SubstPack->getArgumentPack());
2900 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002901
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002902 // These should be getting filtered out before they reach the AST.
2903 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002904}
2905
2906template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002907void TreeTransform<Derived>::InventTemplateArgumentLoc(
2908 const TemplateArgument &Arg,
2909 TemplateArgumentLoc &Output) {
2910 SourceLocation Loc = getDerived().getBaseLocation();
2911 switch (Arg.getKind()) {
2912 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002913 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002914 break;
2915
2916 case TemplateArgument::Type:
2917 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002918 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002919
John McCall833ca992009-10-29 08:12:44 +00002920 break;
2921
Douglas Gregor788cd062009-11-11 01:00:40 +00002922 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002923 case TemplateArgument::TemplateExpansion: {
2924 NestedNameSpecifierLocBuilder Builder;
2925 TemplateName Template = Arg.getAsTemplate();
2926 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2927 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2928 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2929 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002930
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002931 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002932 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002933 Builder.getWithLocInContext(SemaRef.Context),
2934 Loc);
2935 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00002936 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002937 Builder.getWithLocInContext(SemaRef.Context),
2938 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002939
Douglas Gregor788cd062009-11-11 01:00:40 +00002940 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002941 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002942
John McCall833ca992009-10-29 08:12:44 +00002943 case TemplateArgument::Expression:
2944 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2945 break;
2946
2947 case TemplateArgument::Declaration:
2948 case TemplateArgument::Integral:
2949 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002950 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00002951 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002952 break;
2953 }
2954}
2955
2956template<typename Derived>
2957bool TreeTransform<Derived>::TransformTemplateArgument(
2958 const TemplateArgumentLoc &Input,
2959 TemplateArgumentLoc &Output) {
2960 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002961 switch (Arg.getKind()) {
2962 case TemplateArgument::Null:
2963 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00002964 case TemplateArgument::Pack:
2965 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002966 case TemplateArgument::NullPtr:
2967 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00002968
Douglas Gregor670444e2009-08-04 22:27:00 +00002969 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002970 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002971 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002972 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002973
2974 DI = getDerived().TransformType(DI);
2975 if (!DI) return true;
2976
2977 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2978 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002979 }
Mike Stump1eb44332009-09-09 15:08:12 +00002980
Douglas Gregor788cd062009-11-11 01:00:40 +00002981 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002982 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2983 if (QualifierLoc) {
2984 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2985 if (!QualifierLoc)
2986 return true;
2987 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002988
Douglas Gregor1d752d72011-03-02 18:46:51 +00002989 CXXScopeSpec SS;
2990 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002991 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00002992 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2993 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00002994 if (Template.isNull())
2995 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002996
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002997 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00002998 Input.getTemplateNameLoc());
2999 return false;
3000 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003001
3002 case TemplateArgument::TemplateExpansion:
3003 llvm_unreachable("Caller should expand pack expansions");
3004
Douglas Gregor670444e2009-08-04 22:27:00 +00003005 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003006 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003007 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003008 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003009
John McCall833ca992009-10-29 08:12:44 +00003010 Expr *InputExpr = Input.getSourceExpression();
3011 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3012
Chris Lattner223de242011-04-25 20:37:58 +00003013 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003014 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003015 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003016 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003017 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003018 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003019 }
Mike Stump1eb44332009-09-09 15:08:12 +00003020
Douglas Gregor670444e2009-08-04 22:27:00 +00003021 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003022 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003023}
3024
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003025/// \brief Iterator adaptor that invents template argument location information
3026/// for each of the template arguments in its underlying iterator.
3027template<typename Derived, typename InputIterator>
3028class TemplateArgumentLocInventIterator {
3029 TreeTransform<Derived> &Self;
3030 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003031
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003032public:
3033 typedef TemplateArgumentLoc value_type;
3034 typedef TemplateArgumentLoc reference;
3035 typedef typename std::iterator_traits<InputIterator>::difference_type
3036 difference_type;
3037 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003038
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003039 class pointer {
3040 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003041
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003042 public:
3043 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003044
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003045 const TemplateArgumentLoc *operator->() const { return &Arg; }
3046 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003047
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003048 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003049
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003050 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3051 InputIterator Iter)
3052 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003053
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003054 TemplateArgumentLocInventIterator &operator++() {
3055 ++Iter;
3056 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003057 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003058
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003059 TemplateArgumentLocInventIterator operator++(int) {
3060 TemplateArgumentLocInventIterator Old(*this);
3061 ++(*this);
3062 return Old;
3063 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003064
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003065 reference operator*() const {
3066 TemplateArgumentLoc Result;
3067 Self.InventTemplateArgumentLoc(*Iter, Result);
3068 return Result;
3069 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003070
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003071 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003072
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003073 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3074 const TemplateArgumentLocInventIterator &Y) {
3075 return X.Iter == Y.Iter;
3076 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003077
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003078 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3079 const TemplateArgumentLocInventIterator &Y) {
3080 return X.Iter != Y.Iter;
3081 }
3082};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003083
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003084template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003085template<typename InputIterator>
3086bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3087 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003088 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003089 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003090 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003091 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003092
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003093 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3094 // Unpack argument packs, which we translate them into separate
3095 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003096 // FIXME: We could do much better if we could guarantee that the
3097 // TemplateArgumentLocInfo for the pack expansion would be usable for
3098 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003099 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003100 TemplateArgument::pack_iterator>
3101 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003102 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003103 In.getArgument().pack_begin()),
3104 PackLocIterator(*this,
3105 In.getArgument().pack_end()),
3106 Outputs))
3107 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003108
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003109 continue;
3110 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003111
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003112 if (In.getArgument().isPackExpansion()) {
3113 // We have a pack expansion, for which we will be substituting into
3114 // the pattern.
3115 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003116 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003117 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003118 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003119 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003120
Chris Lattner686775d2011-07-20 06:58:45 +00003121 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003122 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3123 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003124
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003125 // Determine whether the set of unexpanded parameter packs can and should
3126 // be expanded.
3127 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003128 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003129 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003130 if (getDerived().TryExpandParameterPacks(Ellipsis,
3131 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003132 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003133 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003134 RetainExpansion,
3135 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003136 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003137
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003138 if (!Expand) {
3139 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003140 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003141 // expansion.
3142 TemplateArgumentLoc OutPattern;
3143 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3144 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3145 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003146
Douglas Gregorcded4f62011-01-14 17:04:44 +00003147 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3148 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003149 if (Out.getArgument().isNull())
3150 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003151
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003152 Outputs.addArgument(Out);
3153 continue;
3154 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003155
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003156 // The transform has determined that we should perform an elementwise
3157 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003158 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003159 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3160
3161 if (getDerived().TransformTemplateArgument(Pattern, Out))
3162 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003163
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003164 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003165 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3166 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003167 if (Out.getArgument().isNull())
3168 return true;
3169 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003170
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003171 Outputs.addArgument(Out);
3172 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003173
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003174 // If we're supposed to retain a pack expansion, do so by temporarily
3175 // forgetting the partially-substituted parameter pack.
3176 if (RetainExpansion) {
3177 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003178
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003179 if (getDerived().TransformTemplateArgument(Pattern, Out))
3180 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003181
Douglas Gregorcded4f62011-01-14 17:04:44 +00003182 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3183 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003184 if (Out.getArgument().isNull())
3185 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003186
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003187 Outputs.addArgument(Out);
3188 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003189
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003190 continue;
3191 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003192
3193 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003194 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003195 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003196
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003197 Outputs.addArgument(Out);
3198 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003199
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003200 return false;
3201
3202}
3203
Douglas Gregor577f75a2009-08-04 16:50:30 +00003204//===----------------------------------------------------------------------===//
3205// Type transformation
3206//===----------------------------------------------------------------------===//
3207
3208template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003209QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003210 if (getDerived().AlreadyTransformed(T))
3211 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003212
John McCalla2becad2009-10-21 00:40:46 +00003213 // Temporary workaround. All of these transformations should
3214 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003215 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3216 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003217
John McCall43fed0d2010-11-12 08:19:04 +00003218 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003219
John McCalla2becad2009-10-21 00:40:46 +00003220 if (!NewDI)
3221 return QualType();
3222
3223 return NewDI->getType();
3224}
3225
3226template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003227TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003228 // Refine the base location to the type's location.
3229 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3230 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003231 if (getDerived().AlreadyTransformed(DI->getType()))
3232 return DI;
3233
3234 TypeLocBuilder TLB;
3235
3236 TypeLoc TL = DI->getTypeLoc();
3237 TLB.reserve(TL.getFullDataSize());
3238
John McCall43fed0d2010-11-12 08:19:04 +00003239 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003240 if (Result.isNull())
3241 return 0;
3242
John McCalla93c9342009-12-07 02:54:59 +00003243 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003244}
3245
3246template<typename Derived>
3247QualType
John McCall43fed0d2010-11-12 08:19:04 +00003248TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003249 switch (T.getTypeLocClass()) {
3250#define ABSTRACT_TYPELOC(CLASS, PARENT)
3251#define TYPELOC(CLASS, PARENT) \
3252 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003253 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003254#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003255 }
Mike Stump1eb44332009-09-09 15:08:12 +00003256
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003257 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003258}
3259
3260/// FIXME: By default, this routine adds type qualifiers only to types
3261/// that can have qualifiers, and silently suppresses those qualifiers
3262/// that are not permitted (e.g., qualifiers on reference or function
3263/// types). This is the right thing for template instantiation, but
3264/// probably not for other clients.
3265template<typename Derived>
3266QualType
3267TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003268 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003269 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003270
John McCall43fed0d2010-11-12 08:19:04 +00003271 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003272 if (Result.isNull())
3273 return QualType();
3274
3275 // Silently suppress qualifiers if the result type can't be qualified.
3276 // FIXME: this is the right thing for template instantiation, but
3277 // probably not for other clients.
3278 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003279 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003280
John McCallf85e1932011-06-15 23:02:42 +00003281 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003282 // resulting type.
3283 if (Quals.hasObjCLifetime()) {
3284 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3285 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003286 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003287 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003288 // A lifetime qualifier applied to a substituted template parameter
3289 // overrides the lifetime qualifier from the template argument.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003290 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003291 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3292 QualType Replacement = SubstTypeParam->getReplacementType();
3293 Qualifiers Qs = Replacement.getQualifiers();
3294 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003295 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003296 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3297 Qs);
3298 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003299 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003300 Replacement);
3301 TLB.TypeWasModifiedSafely(Result);
3302 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003303 // Otherwise, complain about the addition of a qualifier to an
3304 // already-qualified type.
3305 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003306 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003307 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003308
Douglas Gregore559ca12011-06-17 22:11:49 +00003309 Quals.removeObjCLifetime();
3310 }
3311 }
3312 }
John McCall28654742010-06-05 06:41:15 +00003313 if (!Quals.empty()) {
3314 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3315 TLB.push<QualifiedTypeLoc>(Result);
3316 // No location information to preserve.
3317 }
John McCalla2becad2009-10-21 00:40:46 +00003318
3319 return Result;
3320}
3321
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003322template<typename Derived>
3323TypeLoc
3324TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3325 QualType ObjectType,
3326 NamedDecl *UnqualLookup,
3327 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003328 QualType T = TL.getType();
3329 if (getDerived().AlreadyTransformed(T))
3330 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003331
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003332 TypeLocBuilder TLB;
3333 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003334
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003335 if (isa<TemplateSpecializationType>(T)) {
3336 TemplateSpecializationTypeLoc SpecTL
3337 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003338
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003339 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003340 getDerived().TransformTemplateName(SS,
3341 SpecTL.getTypePtr()->getTemplateName(),
3342 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003343 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003344 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003345 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003346
3347 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003348 Template);
3349 } else if (isa<DependentTemplateSpecializationType>(T)) {
3350 DependentTemplateSpecializationTypeLoc SpecTL
3351 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003352
Douglas Gregora88f09f2011-02-28 17:23:35 +00003353 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003354 = getDerived().RebuildTemplateName(SS,
3355 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003356 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003357 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003358 if (Template.isNull())
3359 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003360
3361 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003362 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003363 Template,
3364 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003365 } else {
3366 // Nothing special needs to be done for these.
3367 Result = getDerived().TransformType(TLB, TL);
3368 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003369
3370 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003371 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003372
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003373 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3374}
3375
Douglas Gregorb71d8212011-03-02 18:32:08 +00003376template<typename Derived>
3377TypeSourceInfo *
3378TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3379 QualType ObjectType,
3380 NamedDecl *UnqualLookup,
3381 CXXScopeSpec &SS) {
3382 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003383
Douglas Gregorb71d8212011-03-02 18:32:08 +00003384 QualType T = TSInfo->getType();
3385 if (getDerived().AlreadyTransformed(T))
3386 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003387
Douglas Gregorb71d8212011-03-02 18:32:08 +00003388 TypeLocBuilder TLB;
3389 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003390
Douglas Gregorb71d8212011-03-02 18:32:08 +00003391 TypeLoc TL = TSInfo->getTypeLoc();
3392 if (isa<TemplateSpecializationType>(T)) {
3393 TemplateSpecializationTypeLoc SpecTL
3394 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003395
Douglas Gregorb71d8212011-03-02 18:32:08 +00003396 TemplateName Template
3397 = getDerived().TransformTemplateName(SS,
3398 SpecTL.getTypePtr()->getTemplateName(),
3399 SpecTL.getTemplateNameLoc(),
3400 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003401 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003402 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003403
3404 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003405 Template);
3406 } else if (isa<DependentTemplateSpecializationType>(T)) {
3407 DependentTemplateSpecializationTypeLoc SpecTL
3408 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003409
Douglas Gregorb71d8212011-03-02 18:32:08 +00003410 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003411 = getDerived().RebuildTemplateName(SS,
3412 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003413 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003414 ObjectType, UnqualLookup);
3415 if (Template.isNull())
3416 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003417
3418 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003419 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003420 Template,
3421 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003422 } else {
3423 // Nothing special needs to be done for these.
3424 Result = getDerived().TransformType(TLB, TL);
3425 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003426
3427 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003428 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003429
Douglas Gregorb71d8212011-03-02 18:32:08 +00003430 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3431}
3432
John McCalla2becad2009-10-21 00:40:46 +00003433template <class TyLoc> static inline
3434QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3435 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3436 NewT.setNameLoc(T.getNameLoc());
3437 return T.getType();
3438}
3439
John McCalla2becad2009-10-21 00:40:46 +00003440template<typename Derived>
3441QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003442 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003443 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3444 NewT.setBuiltinLoc(T.getBuiltinLoc());
3445 if (T.needsExtraLocalData())
3446 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3447 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003448}
Mike Stump1eb44332009-09-09 15:08:12 +00003449
Douglas Gregor577f75a2009-08-04 16:50:30 +00003450template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003451QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003452 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003453 // FIXME: recurse?
3454 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003455}
Mike Stump1eb44332009-09-09 15:08:12 +00003456
Douglas Gregor577f75a2009-08-04 16:50:30 +00003457template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003458QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003459 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003460 QualType PointeeType
3461 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003462 if (PointeeType.isNull())
3463 return QualType();
3464
3465 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003466 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003467 // A dependent pointer type 'T *' has is being transformed such
3468 // that an Objective-C class type is being replaced for 'T'. The
3469 // resulting pointer type is an ObjCObjectPointerType, not a
3470 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003471 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003472
John McCallc12c5bb2010-05-15 11:32:37 +00003473 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3474 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003475 return Result;
3476 }
John McCall43fed0d2010-11-12 08:19:04 +00003477
Douglas Gregor92e986e2010-04-22 16:44:27 +00003478 if (getDerived().AlwaysRebuild() ||
3479 PointeeType != TL.getPointeeLoc().getType()) {
3480 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3481 if (Result.isNull())
3482 return QualType();
3483 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003484
John McCallf85e1932011-06-15 23:02:42 +00003485 // Objective-C ARC can add lifetime qualifiers to the type that we're
3486 // pointing to.
3487 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003488
Douglas Gregor92e986e2010-04-22 16:44:27 +00003489 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3490 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003491 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003492}
Mike Stump1eb44332009-09-09 15:08:12 +00003493
3494template<typename Derived>
3495QualType
John McCalla2becad2009-10-21 00:40:46 +00003496TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003497 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003498 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003499 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3500 if (PointeeType.isNull())
3501 return QualType();
3502
3503 QualType Result = TL.getType();
3504 if (getDerived().AlwaysRebuild() ||
3505 PointeeType != TL.getPointeeLoc().getType()) {
3506 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003507 TL.getSigilLoc());
3508 if (Result.isNull())
3509 return QualType();
3510 }
3511
Douglas Gregor39968ad2010-04-22 16:50:51 +00003512 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003513 NewT.setSigilLoc(TL.getSigilLoc());
3514 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003515}
3516
John McCall85737a72009-10-30 00:06:24 +00003517/// Transforms a reference type. Note that somewhat paradoxically we
3518/// don't care whether the type itself is an l-value type or an r-value
3519/// type; we only care if the type was *written* as an l-value type
3520/// or an r-value type.
3521template<typename Derived>
3522QualType
3523TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003524 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003525 const ReferenceType *T = TL.getTypePtr();
3526
3527 // Note that this works with the pointee-as-written.
3528 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3529 if (PointeeType.isNull())
3530 return QualType();
3531
3532 QualType Result = TL.getType();
3533 if (getDerived().AlwaysRebuild() ||
3534 PointeeType != T->getPointeeTypeAsWritten()) {
3535 Result = getDerived().RebuildReferenceType(PointeeType,
3536 T->isSpelledAsLValue(),
3537 TL.getSigilLoc());
3538 if (Result.isNull())
3539 return QualType();
3540 }
3541
John McCallf85e1932011-06-15 23:02:42 +00003542 // Objective-C ARC can add lifetime qualifiers to the type that we're
3543 // referring to.
3544 TLB.TypeWasModifiedSafely(
3545 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3546
John McCall85737a72009-10-30 00:06:24 +00003547 // r-value references can be rebuilt as l-value references.
3548 ReferenceTypeLoc NewTL;
3549 if (isa<LValueReferenceType>(Result))
3550 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3551 else
3552 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3553 NewTL.setSigilLoc(TL.getSigilLoc());
3554
3555 return Result;
3556}
3557
Mike Stump1eb44332009-09-09 15:08:12 +00003558template<typename Derived>
3559QualType
John McCalla2becad2009-10-21 00:40:46 +00003560TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003561 LValueReferenceTypeLoc TL) {
3562 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003563}
3564
Mike Stump1eb44332009-09-09 15:08:12 +00003565template<typename Derived>
3566QualType
John McCalla2becad2009-10-21 00:40:46 +00003567TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003568 RValueReferenceTypeLoc TL) {
3569 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003570}
Mike Stump1eb44332009-09-09 15:08:12 +00003571
Douglas Gregor577f75a2009-08-04 16:50:30 +00003572template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003573QualType
John McCalla2becad2009-10-21 00:40:46 +00003574TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003575 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003576 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003577 if (PointeeType.isNull())
3578 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003579
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003580 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3581 TypeSourceInfo* NewClsTInfo = 0;
3582 if (OldClsTInfo) {
3583 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3584 if (!NewClsTInfo)
3585 return QualType();
3586 }
3587
3588 const MemberPointerType *T = TL.getTypePtr();
3589 QualType OldClsType = QualType(T->getClass(), 0);
3590 QualType NewClsType;
3591 if (NewClsTInfo)
3592 NewClsType = NewClsTInfo->getType();
3593 else {
3594 NewClsType = getDerived().TransformType(OldClsType);
3595 if (NewClsType.isNull())
3596 return QualType();
3597 }
Mike Stump1eb44332009-09-09 15:08:12 +00003598
John McCalla2becad2009-10-21 00:40:46 +00003599 QualType Result = TL.getType();
3600 if (getDerived().AlwaysRebuild() ||
3601 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003602 NewClsType != OldClsType) {
3603 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003604 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003605 if (Result.isNull())
3606 return QualType();
3607 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003608
John McCalla2becad2009-10-21 00:40:46 +00003609 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3610 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003611 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003612
3613 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003614}
3615
Mike Stump1eb44332009-09-09 15:08:12 +00003616template<typename Derived>
3617QualType
John McCalla2becad2009-10-21 00:40:46 +00003618TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003619 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003620 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003621 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003622 if (ElementType.isNull())
3623 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003624
John McCalla2becad2009-10-21 00:40:46 +00003625 QualType Result = TL.getType();
3626 if (getDerived().AlwaysRebuild() ||
3627 ElementType != T->getElementType()) {
3628 Result = getDerived().RebuildConstantArrayType(ElementType,
3629 T->getSizeModifier(),
3630 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003631 T->getIndexTypeCVRQualifiers(),
3632 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003633 if (Result.isNull())
3634 return QualType();
3635 }
Eli Friedman457a3772012-01-25 22:19:07 +00003636
3637 // We might have either a ConstantArrayType or a VariableArrayType now:
3638 // a ConstantArrayType is allowed to have an element type which is a
3639 // VariableArrayType if the type is dependent. Fortunately, all array
3640 // types have the same location layout.
3641 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003642 NewTL.setLBracketLoc(TL.getLBracketLoc());
3643 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003644
John McCalla2becad2009-10-21 00:40:46 +00003645 Expr *Size = TL.getSizeExpr();
3646 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003647 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3648 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003649 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003650 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003651 }
3652 NewTL.setSizeExpr(Size);
3653
3654 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003655}
Mike Stump1eb44332009-09-09 15:08:12 +00003656
Douglas Gregor577f75a2009-08-04 16:50:30 +00003657template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003658QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003659 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003660 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003661 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003662 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003663 if (ElementType.isNull())
3664 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003665
John McCalla2becad2009-10-21 00:40:46 +00003666 QualType Result = TL.getType();
3667 if (getDerived().AlwaysRebuild() ||
3668 ElementType != T->getElementType()) {
3669 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003670 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003671 T->getIndexTypeCVRQualifiers(),
3672 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003673 if (Result.isNull())
3674 return QualType();
3675 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003676
John McCalla2becad2009-10-21 00:40:46 +00003677 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3678 NewTL.setLBracketLoc(TL.getLBracketLoc());
3679 NewTL.setRBracketLoc(TL.getRBracketLoc());
3680 NewTL.setSizeExpr(0);
3681
3682 return Result;
3683}
3684
3685template<typename Derived>
3686QualType
3687TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003688 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003689 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003690 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3691 if (ElementType.isNull())
3692 return QualType();
3693
John McCall60d7b3a2010-08-24 06:29:42 +00003694 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003695 = getDerived().TransformExpr(T->getSizeExpr());
3696 if (SizeResult.isInvalid())
3697 return QualType();
3698
John McCall9ae2f072010-08-23 23:25:46 +00003699 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003700
3701 QualType Result = TL.getType();
3702 if (getDerived().AlwaysRebuild() ||
3703 ElementType != T->getElementType() ||
3704 Size != T->getSizeExpr()) {
3705 Result = getDerived().RebuildVariableArrayType(ElementType,
3706 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003707 Size,
John McCalla2becad2009-10-21 00:40:46 +00003708 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003709 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003710 if (Result.isNull())
3711 return QualType();
3712 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003713
John McCalla2becad2009-10-21 00:40:46 +00003714 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3715 NewTL.setLBracketLoc(TL.getLBracketLoc());
3716 NewTL.setRBracketLoc(TL.getRBracketLoc());
3717 NewTL.setSizeExpr(Size);
3718
3719 return Result;
3720}
3721
3722template<typename Derived>
3723QualType
3724TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003725 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003726 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003727 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3728 if (ElementType.isNull())
3729 return QualType();
3730
Richard Smithf6702a32011-12-20 02:08:33 +00003731 // Array bounds are constant expressions.
3732 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3733 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003734
John McCall3b657512011-01-19 10:06:00 +00003735 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3736 Expr *origSize = TL.getSizeExpr();
3737 if (!origSize) origSize = T->getSizeExpr();
3738
3739 ExprResult sizeResult
3740 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003741 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003742 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003743 return QualType();
3744
John McCall3b657512011-01-19 10:06:00 +00003745 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003746
3747 QualType Result = TL.getType();
3748 if (getDerived().AlwaysRebuild() ||
3749 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003750 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003751 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3752 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003753 size,
John McCalla2becad2009-10-21 00:40:46 +00003754 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003755 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003756 if (Result.isNull())
3757 return QualType();
3758 }
John McCalla2becad2009-10-21 00:40:46 +00003759
3760 // We might have any sort of array type now, but fortunately they
3761 // all have the same location layout.
3762 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3763 NewTL.setLBracketLoc(TL.getLBracketLoc());
3764 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003765 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003766
3767 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003768}
Mike Stump1eb44332009-09-09 15:08:12 +00003769
3770template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003771QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003772 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003773 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003774 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003775
3776 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003777 QualType ElementType = getDerived().TransformType(T->getElementType());
3778 if (ElementType.isNull())
3779 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003780
Richard Smithf6702a32011-12-20 02:08:33 +00003781 // Vector sizes are constant expressions.
3782 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3783 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003784
John McCall60d7b3a2010-08-24 06:29:42 +00003785 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003786 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003787 if (Size.isInvalid())
3788 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003789
John McCalla2becad2009-10-21 00:40:46 +00003790 QualType Result = TL.getType();
3791 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003792 ElementType != T->getElementType() ||
3793 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003794 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003795 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003796 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003797 if (Result.isNull())
3798 return QualType();
3799 }
John McCalla2becad2009-10-21 00:40:46 +00003800
3801 // Result might be dependent or not.
3802 if (isa<DependentSizedExtVectorType>(Result)) {
3803 DependentSizedExtVectorTypeLoc NewTL
3804 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3805 NewTL.setNameLoc(TL.getNameLoc());
3806 } else {
3807 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3808 NewTL.setNameLoc(TL.getNameLoc());
3809 }
3810
3811 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003812}
Mike Stump1eb44332009-09-09 15:08:12 +00003813
3814template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003815QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003816 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003817 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003818 QualType ElementType = getDerived().TransformType(T->getElementType());
3819 if (ElementType.isNull())
3820 return QualType();
3821
John McCalla2becad2009-10-21 00:40:46 +00003822 QualType Result = TL.getType();
3823 if (getDerived().AlwaysRebuild() ||
3824 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003825 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003826 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003827 if (Result.isNull())
3828 return QualType();
3829 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003830
John McCalla2becad2009-10-21 00:40:46 +00003831 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3832 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003833
John McCalla2becad2009-10-21 00:40:46 +00003834 return Result;
3835}
3836
3837template<typename Derived>
3838QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003839 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003840 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003841 QualType ElementType = getDerived().TransformType(T->getElementType());
3842 if (ElementType.isNull())
3843 return QualType();
3844
3845 QualType Result = TL.getType();
3846 if (getDerived().AlwaysRebuild() ||
3847 ElementType != T->getElementType()) {
3848 Result = getDerived().RebuildExtVectorType(ElementType,
3849 T->getNumElements(),
3850 /*FIXME*/ SourceLocation());
3851 if (Result.isNull())
3852 return QualType();
3853 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003854
John McCalla2becad2009-10-21 00:40:46 +00003855 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3856 NewTL.setNameLoc(TL.getNameLoc());
3857
3858 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003859}
Mike Stump1eb44332009-09-09 15:08:12 +00003860
3861template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003862ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003863TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003864 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003865 llvm::Optional<unsigned> NumExpansions,
3866 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003867 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003868 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003869
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003870 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003871 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003872 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003873 TypeLoc OldTL = OldDI->getTypeLoc();
3874 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003875
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003876 TypeLocBuilder TLB;
3877 TypeLoc NewTL = OldDI->getTypeLoc();
3878 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003879
3880 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003881 OldExpansionTL.getPatternLoc());
3882 if (Result.isNull())
3883 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003884
3885 Result = RebuildPackExpansionType(Result,
3886 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003887 OldExpansionTL.getEllipsisLoc(),
3888 NumExpansions);
3889 if (Result.isNull())
3890 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003891
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003892 PackExpansionTypeLoc NewExpansionTL
3893 = TLB.push<PackExpansionTypeLoc>(Result);
3894 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3895 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3896 } else
3897 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003898 if (!NewDI)
3899 return 0;
3900
John McCallfb44de92011-05-01 22:35:37 +00003901 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003902 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003903
3904 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3905 OldParm->getDeclContext(),
3906 OldParm->getInnerLocStart(),
3907 OldParm->getLocation(),
3908 OldParm->getIdentifier(),
3909 NewDI->getType(),
3910 NewDI,
3911 OldParm->getStorageClass(),
3912 OldParm->getStorageClassAsWritten(),
3913 /* DefArg */ NULL);
3914 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3915 OldParm->getFunctionScopeIndex() + indexAdjustment);
3916 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003917}
3918
3919template<typename Derived>
3920bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003921 TransformFunctionTypeParams(SourceLocation Loc,
3922 ParmVarDecl **Params, unsigned NumParams,
3923 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003924 SmallVectorImpl<QualType> &OutParamTypes,
3925 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003926 int indexAdjustment = 0;
3927
Douglas Gregora009b592011-01-07 00:20:55 +00003928 for (unsigned i = 0; i != NumParams; ++i) {
3929 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003930 assert(OldParm->getFunctionScopeIndex() == i);
3931
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003932 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003933 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003934 if (OldParm->isParameterPack()) {
3935 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003936 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003937
Douglas Gregor603cfb42011-01-05 23:12:31 +00003938 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003939 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3940 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3941 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3942 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003943 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3944
Douglas Gregor603cfb42011-01-05 23:12:31 +00003945 // Determine whether we should expand the parameter packs.
3946 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003947 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003948 llvm::Optional<unsigned> OrigNumExpansions
3949 = ExpansionTL.getTypePtr()->getNumExpansions();
3950 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003951 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3952 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00003953 Unexpanded,
3954 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00003955 RetainExpansion,
3956 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003957 return true;
3958 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003959
Douglas Gregor603cfb42011-01-05 23:12:31 +00003960 if (ShouldExpand) {
3961 // Expand the function parameter pack into multiple, separate
3962 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003963 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003964 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003965 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003966 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003967 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003968 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003969 OrigNumExpansions,
3970 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003971 if (!NewParm)
3972 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003973
Douglas Gregora009b592011-01-07 00:20:55 +00003974 OutParamTypes.push_back(NewParm->getType());
3975 if (PVars)
3976 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003977 }
Douglas Gregord3731192011-01-10 07:32:04 +00003978
3979 // If we're supposed to retain a pack expansion, do so by temporarily
3980 // forgetting the partially-substituted parameter pack.
3981 if (RetainExpansion) {
3982 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003983 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003984 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003985 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003986 OrigNumExpansions,
3987 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00003988 if (!NewParm)
3989 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003990
Douglas Gregord3731192011-01-10 07:32:04 +00003991 OutParamTypes.push_back(NewParm->getType());
3992 if (PVars)
3993 PVars->push_back(NewParm);
3994 }
3995
John McCallfb44de92011-05-01 22:35:37 +00003996 // The next parameter should have the same adjustment as the
3997 // last thing we pushed, but we post-incremented indexAdjustment
3998 // on every push. Also, if we push nothing, the adjustment should
3999 // go down by one.
4000 indexAdjustment--;
4001
Douglas Gregor603cfb42011-01-05 23:12:31 +00004002 // We're done with the pack expansion.
4003 continue;
4004 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004005
4006 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004007 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004008 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4009 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004010 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004011 NumExpansions,
4012 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004013 } else {
4014 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004015 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004016 llvm::Optional<unsigned>(),
4017 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004018 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004019
John McCall21ef0fa2010-03-11 09:03:00 +00004020 if (!NewParm)
4021 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004022
Douglas Gregora009b592011-01-07 00:20:55 +00004023 OutParamTypes.push_back(NewParm->getType());
4024 if (PVars)
4025 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004026 continue;
4027 }
John McCall21ef0fa2010-03-11 09:03:00 +00004028
4029 // Deal with the possibility that we don't have a parameter
4030 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004031 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004032 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004033 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004034 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004035 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004036 = dyn_cast<PackExpansionType>(OldType)) {
4037 // We have a function parameter pack that may need to be expanded.
4038 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004039 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004040 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004041
Douglas Gregor603cfb42011-01-05 23:12:31 +00004042 // Determine whether we should expand the parameter packs.
4043 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004044 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004045 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004046 Unexpanded,
4047 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004048 RetainExpansion,
4049 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004050 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004051 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004052
Douglas Gregor603cfb42011-01-05 23:12:31 +00004053 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004054 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004055 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004056 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004057 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4058 QualType NewType = getDerived().TransformType(Pattern);
4059 if (NewType.isNull())
4060 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004061
Douglas Gregora009b592011-01-07 00:20:55 +00004062 OutParamTypes.push_back(NewType);
4063 if (PVars)
4064 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004065 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004066
Douglas Gregor603cfb42011-01-05 23:12:31 +00004067 // We're done with the pack expansion.
4068 continue;
4069 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004070
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004071 // If we're supposed to retain a pack expansion, do so by temporarily
4072 // forgetting the partially-substituted parameter pack.
4073 if (RetainExpansion) {
4074 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4075 QualType NewType = getDerived().TransformType(Pattern);
4076 if (NewType.isNull())
4077 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004078
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004079 OutParamTypes.push_back(NewType);
4080 if (PVars)
4081 PVars->push_back(0);
4082 }
Douglas Gregord3731192011-01-10 07:32:04 +00004083
Chad Rosier4a9d7952012-08-08 18:46:20 +00004084 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004085 // expansion.
4086 OldType = Expansion->getPattern();
4087 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004088 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4089 NewType = getDerived().TransformType(OldType);
4090 } else {
4091 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004092 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004093
Douglas Gregor603cfb42011-01-05 23:12:31 +00004094 if (NewType.isNull())
4095 return true;
4096
4097 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004098 NewType = getSema().Context.getPackExpansionType(NewType,
4099 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004100
Douglas Gregora009b592011-01-07 00:20:55 +00004101 OutParamTypes.push_back(NewType);
4102 if (PVars)
4103 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004104 }
4105
John McCallfb44de92011-05-01 22:35:37 +00004106#ifndef NDEBUG
4107 if (PVars) {
4108 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4109 if (ParmVarDecl *parm = (*PVars)[i])
4110 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004111 }
John McCallfb44de92011-05-01 22:35:37 +00004112#endif
4113
4114 return false;
4115}
John McCall21ef0fa2010-03-11 09:03:00 +00004116
4117template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004118QualType
John McCalla2becad2009-10-21 00:40:46 +00004119TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004120 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004121 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4122}
4123
4124template<typename Derived>
4125QualType
4126TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4127 FunctionProtoTypeLoc TL,
4128 CXXRecordDecl *ThisContext,
4129 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004130 // Transform the parameters and return type.
4131 //
Richard Smithe6975e92012-04-17 00:58:00 +00004132 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004133 // When the function has a trailing return type, we instantiate the
4134 // parameters before the return type, since the return type can then refer
4135 // to the parameters themselves (via decltype, sizeof, etc.).
4136 //
Chris Lattner686775d2011-07-20 06:58:45 +00004137 SmallVector<QualType, 4> ParamTypes;
4138 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004139 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004140
Douglas Gregordab60ad2010-10-01 18:44:50 +00004141 QualType ResultType;
4142
Richard Smith9fbf3272012-08-14 22:51:13 +00004143 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004144 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004145 TL.getParmArray(),
4146 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004147 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004148 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004149 return QualType();
4150
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004151 {
4152 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004153 // If a declaration declares a member function or member function
4154 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004155 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004156 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004157 // declarator.
4158 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004159
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004160 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4161 if (ResultType.isNull())
4162 return QualType();
4163 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004164 }
4165 else {
4166 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4167 if (ResultType.isNull())
4168 return QualType();
4169
Chad Rosier4a9d7952012-08-08 18:46:20 +00004170 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004171 TL.getParmArray(),
4172 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004173 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004174 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004175 return QualType();
4176 }
4177
Richard Smithe6975e92012-04-17 00:58:00 +00004178 // FIXME: Need to transform the exception-specification too.
4179
John McCalla2becad2009-10-21 00:40:46 +00004180 QualType Result = TL.getType();
4181 if (getDerived().AlwaysRebuild() ||
4182 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004183 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004184 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4185 Result = getDerived().RebuildFunctionProtoType(ResultType,
4186 ParamTypes.data(),
4187 ParamTypes.size(),
4188 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004189 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004190 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004191 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004192 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004193 if (Result.isNull())
4194 return QualType();
4195 }
Mike Stump1eb44332009-09-09 15:08:12 +00004196
John McCalla2becad2009-10-21 00:40:46 +00004197 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004198 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004199 NewTL.setLParenLoc(TL.getLParenLoc());
4200 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004201 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004202 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4203 NewTL.setArg(i, ParamDecls[i]);
4204
4205 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004206}
Mike Stump1eb44332009-09-09 15:08:12 +00004207
Douglas Gregor577f75a2009-08-04 16:50:30 +00004208template<typename Derived>
4209QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004210 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004211 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004212 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004213 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4214 if (ResultType.isNull())
4215 return QualType();
4216
4217 QualType Result = TL.getType();
4218 if (getDerived().AlwaysRebuild() ||
4219 ResultType != T->getResultType())
4220 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4221
4222 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004223 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004224 NewTL.setLParenLoc(TL.getLParenLoc());
4225 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004226 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004227
4228 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004229}
Mike Stump1eb44332009-09-09 15:08:12 +00004230
John McCalled976492009-12-04 22:46:56 +00004231template<typename Derived> QualType
4232TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004233 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004234 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004235 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004236 if (!D)
4237 return QualType();
4238
4239 QualType Result = TL.getType();
4240 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4241 Result = getDerived().RebuildUnresolvedUsingType(D);
4242 if (Result.isNull())
4243 return QualType();
4244 }
4245
4246 // We might get an arbitrary type spec type back. We should at
4247 // least always get a type spec type, though.
4248 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4249 NewTL.setNameLoc(TL.getNameLoc());
4250
4251 return Result;
4252}
4253
Douglas Gregor577f75a2009-08-04 16:50:30 +00004254template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004255QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004256 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004257 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004258 TypedefNameDecl *Typedef
4259 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4260 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004261 if (!Typedef)
4262 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004263
John McCalla2becad2009-10-21 00:40:46 +00004264 QualType Result = TL.getType();
4265 if (getDerived().AlwaysRebuild() ||
4266 Typedef != T->getDecl()) {
4267 Result = getDerived().RebuildTypedefType(Typedef);
4268 if (Result.isNull())
4269 return QualType();
4270 }
Mike Stump1eb44332009-09-09 15:08:12 +00004271
John McCalla2becad2009-10-21 00:40:46 +00004272 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4273 NewTL.setNameLoc(TL.getNameLoc());
4274
4275 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004276}
Mike Stump1eb44332009-09-09 15:08:12 +00004277
Douglas Gregor577f75a2009-08-04 16:50:30 +00004278template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004279QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004280 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004281 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004282 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4283 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004284
John McCall60d7b3a2010-08-24 06:29:42 +00004285 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004286 if (E.isInvalid())
4287 return QualType();
4288
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004289 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4290 if (E.isInvalid())
4291 return QualType();
4292
John McCalla2becad2009-10-21 00:40:46 +00004293 QualType Result = TL.getType();
4294 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004295 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004296 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004297 if (Result.isNull())
4298 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004299 }
John McCalla2becad2009-10-21 00:40:46 +00004300 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004301
John McCalla2becad2009-10-21 00:40:46 +00004302 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004303 NewTL.setTypeofLoc(TL.getTypeofLoc());
4304 NewTL.setLParenLoc(TL.getLParenLoc());
4305 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004306
4307 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004308}
Mike Stump1eb44332009-09-09 15:08:12 +00004309
4310template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004311QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004312 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004313 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4314 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4315 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004316 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004317
John McCalla2becad2009-10-21 00:40:46 +00004318 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004319 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4320 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004321 if (Result.isNull())
4322 return QualType();
4323 }
Mike Stump1eb44332009-09-09 15:08:12 +00004324
John McCalla2becad2009-10-21 00:40:46 +00004325 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004326 NewTL.setTypeofLoc(TL.getTypeofLoc());
4327 NewTL.setLParenLoc(TL.getLParenLoc());
4328 NewTL.setRParenLoc(TL.getRParenLoc());
4329 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004330
4331 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004332}
Mike Stump1eb44332009-09-09 15:08:12 +00004333
4334template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004335QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004336 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004337 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004338
Douglas Gregor670444e2009-08-04 22:27:00 +00004339 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004340 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4341 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004342
John McCall60d7b3a2010-08-24 06:29:42 +00004343 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004344 if (E.isInvalid())
4345 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004346
Richard Smith76f3f692012-02-22 02:04:18 +00004347 E = getSema().ActOnDecltypeExpression(E.take());
4348 if (E.isInvalid())
4349 return QualType();
4350
John McCalla2becad2009-10-21 00:40:46 +00004351 QualType Result = TL.getType();
4352 if (getDerived().AlwaysRebuild() ||
4353 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004354 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
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 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4361 NewTL.setNameLoc(TL.getNameLoc());
4362
4363 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004364}
4365
4366template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004367QualType TreeTransform<Derived>::TransformUnaryTransformType(
4368 TypeLocBuilder &TLB,
4369 UnaryTransformTypeLoc TL) {
4370 QualType Result = TL.getType();
4371 if (Result->isDependentType()) {
4372 const UnaryTransformType *T = TL.getTypePtr();
4373 QualType NewBase =
4374 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4375 Result = getDerived().RebuildUnaryTransformType(NewBase,
4376 T->getUTTKind(),
4377 TL.getKWLoc());
4378 if (Result.isNull())
4379 return QualType();
4380 }
4381
4382 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4383 NewTL.setKWLoc(TL.getKWLoc());
4384 NewTL.setParensRange(TL.getParensRange());
4385 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4386 return Result;
4387}
4388
4389template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004390QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4391 AutoTypeLoc TL) {
4392 const AutoType *T = TL.getTypePtr();
4393 QualType OldDeduced = T->getDeducedType();
4394 QualType NewDeduced;
4395 if (!OldDeduced.isNull()) {
4396 NewDeduced = getDerived().TransformType(OldDeduced);
4397 if (NewDeduced.isNull())
4398 return QualType();
4399 }
4400
4401 QualType Result = TL.getType();
4402 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4403 Result = getDerived().RebuildAutoType(NewDeduced);
4404 if (Result.isNull())
4405 return QualType();
4406 }
4407
4408 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4409 NewTL.setNameLoc(TL.getNameLoc());
4410
4411 return Result;
4412}
4413
4414template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004415QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004416 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004417 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004418 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004419 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4420 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004421 if (!Record)
4422 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004423
John McCalla2becad2009-10-21 00:40:46 +00004424 QualType Result = TL.getType();
4425 if (getDerived().AlwaysRebuild() ||
4426 Record != T->getDecl()) {
4427 Result = getDerived().RebuildRecordType(Record);
4428 if (Result.isNull())
4429 return QualType();
4430 }
Mike Stump1eb44332009-09-09 15:08:12 +00004431
John McCalla2becad2009-10-21 00:40:46 +00004432 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4433 NewTL.setNameLoc(TL.getNameLoc());
4434
4435 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004436}
Mike Stump1eb44332009-09-09 15:08:12 +00004437
4438template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004439QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004440 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004441 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004442 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004443 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4444 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004445 if (!Enum)
4446 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004447
John McCalla2becad2009-10-21 00:40:46 +00004448 QualType Result = TL.getType();
4449 if (getDerived().AlwaysRebuild() ||
4450 Enum != T->getDecl()) {
4451 Result = getDerived().RebuildEnumType(Enum);
4452 if (Result.isNull())
4453 return QualType();
4454 }
Mike Stump1eb44332009-09-09 15:08:12 +00004455
John McCalla2becad2009-10-21 00:40:46 +00004456 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4457 NewTL.setNameLoc(TL.getNameLoc());
4458
4459 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004460}
John McCall7da24312009-09-05 00:15:47 +00004461
John McCall3cb0ebd2010-03-10 03:28:59 +00004462template<typename Derived>
4463QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4464 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004465 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004466 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4467 TL.getTypePtr()->getDecl());
4468 if (!D) return QualType();
4469
4470 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4471 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4472 return T;
4473}
4474
Douglas Gregor577f75a2009-08-04 16:50:30 +00004475template<typename Derived>
4476QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004477 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004478 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004479 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004480}
4481
Mike Stump1eb44332009-09-09 15:08:12 +00004482template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004483QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004484 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004485 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004486 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004487
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004488 // Substitute into the replacement type, which itself might involve something
4489 // that needs to be transformed. This only tends to occur with default
4490 // template arguments of template template parameters.
4491 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4492 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4493 if (Replacement.isNull())
4494 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004495
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004496 // Always canonicalize the replacement type.
4497 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4498 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004499 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004500 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004501
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004502 // Propagate type-source information.
4503 SubstTemplateTypeParmTypeLoc NewTL
4504 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4505 NewTL.setNameLoc(TL.getNameLoc());
4506 return Result;
4507
John McCall49a832b2009-10-18 09:09:24 +00004508}
4509
4510template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004511QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4512 TypeLocBuilder &TLB,
4513 SubstTemplateTypeParmPackTypeLoc TL) {
4514 return TransformTypeSpecType(TLB, TL);
4515}
4516
4517template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004518QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004519 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004520 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004521 const TemplateSpecializationType *T = TL.getTypePtr();
4522
Douglas Gregor1d752d72011-03-02 18:46:51 +00004523 // The nested-name-specifier never matters in a TemplateSpecializationType,
4524 // because we can't have a dependent nested-name-specifier anyway.
4525 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004526 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004527 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4528 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004529 if (Template.isNull())
4530 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004531
John McCall43fed0d2010-11-12 08:19:04 +00004532 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4533}
4534
Eli Friedmanb001de72011-10-06 23:00:33 +00004535template<typename Derived>
4536QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4537 AtomicTypeLoc TL) {
4538 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4539 if (ValueType.isNull())
4540 return QualType();
4541
4542 QualType Result = TL.getType();
4543 if (getDerived().AlwaysRebuild() ||
4544 ValueType != TL.getValueLoc().getType()) {
4545 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4546 if (Result.isNull())
4547 return QualType();
4548 }
4549
4550 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4551 NewTL.setKWLoc(TL.getKWLoc());
4552 NewTL.setLParenLoc(TL.getLParenLoc());
4553 NewTL.setRParenLoc(TL.getRParenLoc());
4554
4555 return Result;
4556}
4557
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004558namespace {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004559 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004560 /// container that provides a \c getArgLoc() member function.
4561 ///
4562 /// This iterator is intended to be used with the iterator form of
4563 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4564 template<typename ArgLocContainer>
4565 class TemplateArgumentLocContainerIterator {
4566 ArgLocContainer *Container;
4567 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004568
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004569 public:
4570 typedef TemplateArgumentLoc value_type;
4571 typedef TemplateArgumentLoc reference;
4572 typedef int difference_type;
4573 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004574
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004575 class pointer {
4576 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004577
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004578 public:
4579 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004580
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004581 const TemplateArgumentLoc *operator->() const {
4582 return &Arg;
4583 }
4584 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004585
4586
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004587 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004588
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004589 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4590 unsigned Index)
4591 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004592
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004593 TemplateArgumentLocContainerIterator &operator++() {
4594 ++Index;
4595 return *this;
4596 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004597
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004598 TemplateArgumentLocContainerIterator operator++(int) {
4599 TemplateArgumentLocContainerIterator Old(*this);
4600 ++(*this);
4601 return Old;
4602 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004603
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004604 TemplateArgumentLoc operator*() const {
4605 return Container->getArgLoc(Index);
4606 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004607
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004608 pointer operator->() const {
4609 return pointer(Container->getArgLoc(Index));
4610 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004611
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004612 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004613 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004614 return X.Container == Y.Container && X.Index == Y.Index;
4615 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004616
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004617 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004618 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004619 return !(X == Y);
4620 }
4621 };
4622}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004623
4624
John McCall43fed0d2010-11-12 08:19:04 +00004625template <typename Derived>
4626QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4627 TypeLocBuilder &TLB,
4628 TemplateSpecializationTypeLoc TL,
4629 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004630 TemplateArgumentListInfo NewTemplateArgs;
4631 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4632 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004633 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4634 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004635 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004636 ArgIterator(TL, TL.getNumArgs()),
4637 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004638 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004639
John McCall833ca992009-10-29 08:12:44 +00004640 // FIXME: maybe don't rebuild if all the template arguments are the same.
4641
4642 QualType Result =
4643 getDerived().RebuildTemplateSpecializationType(Template,
4644 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004645 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004646
4647 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004648 // Specializations of template template parameters are represented as
4649 // TemplateSpecializationTypes, and substitution of type alias templates
4650 // within a dependent context can transform them into
4651 // DependentTemplateSpecializationTypes.
4652 if (isa<DependentTemplateSpecializationType>(Result)) {
4653 DependentTemplateSpecializationTypeLoc NewTL
4654 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004655 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004656 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004657 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004658 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004659 NewTL.setLAngleLoc(TL.getLAngleLoc());
4660 NewTL.setRAngleLoc(TL.getRAngleLoc());
4661 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4662 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4663 return Result;
4664 }
4665
John McCall833ca992009-10-29 08:12:44 +00004666 TemplateSpecializationTypeLoc NewTL
4667 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004668 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004669 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4670 NewTL.setLAngleLoc(TL.getLAngleLoc());
4671 NewTL.setRAngleLoc(TL.getRAngleLoc());
4672 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4673 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004674 }
Mike Stump1eb44332009-09-09 15:08:12 +00004675
John McCall833ca992009-10-29 08:12:44 +00004676 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004677}
Mike Stump1eb44332009-09-09 15:08:12 +00004678
Douglas Gregora88f09f2011-02-28 17:23:35 +00004679template <typename Derived>
4680QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4681 TypeLocBuilder &TLB,
4682 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004683 TemplateName Template,
4684 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004685 TemplateArgumentListInfo NewTemplateArgs;
4686 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4687 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4688 typedef TemplateArgumentLocContainerIterator<
4689 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004690 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004691 ArgIterator(TL, TL.getNumArgs()),
4692 NewTemplateArgs))
4693 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004694
Douglas Gregora88f09f2011-02-28 17:23:35 +00004695 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004696
Douglas Gregora88f09f2011-02-28 17:23:35 +00004697 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4698 QualType Result
4699 = getSema().Context.getDependentTemplateSpecializationType(
4700 TL.getTypePtr()->getKeyword(),
4701 DTN->getQualifier(),
4702 DTN->getIdentifier(),
4703 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004704
Douglas Gregora88f09f2011-02-28 17:23:35 +00004705 DependentTemplateSpecializationTypeLoc NewTL
4706 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004707 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004708 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004709 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004710 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004711 NewTL.setLAngleLoc(TL.getLAngleLoc());
4712 NewTL.setRAngleLoc(TL.getRAngleLoc());
4713 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4714 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4715 return Result;
4716 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004717
4718 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004719 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004720 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004721 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004722
Douglas Gregora88f09f2011-02-28 17:23:35 +00004723 if (!Result.isNull()) {
4724 /// FIXME: Wrap this in an elaborated-type-specifier?
4725 TemplateSpecializationTypeLoc NewTL
4726 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004727 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004728 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004729 NewTL.setLAngleLoc(TL.getLAngleLoc());
4730 NewTL.setRAngleLoc(TL.getRAngleLoc());
4731 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4732 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4733 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004734
Douglas Gregora88f09f2011-02-28 17:23:35 +00004735 return Result;
4736}
4737
Mike Stump1eb44332009-09-09 15:08:12 +00004738template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004739QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004740TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004741 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004742 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004743
Douglas Gregor9e876872011-03-01 18:12:44 +00004744 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004745 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004746 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004747 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004748 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4749 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004750 return QualType();
4751 }
Mike Stump1eb44332009-09-09 15:08:12 +00004752
John McCall43fed0d2010-11-12 08:19:04 +00004753 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4754 if (NamedT.isNull())
4755 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004756
Richard Smith3e4c6c42011-05-05 21:57:07 +00004757 // C++0x [dcl.type.elab]p2:
4758 // If the identifier resolves to a typedef-name or the simple-template-id
4759 // resolves to an alias template specialization, the
4760 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004761 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4762 if (const TemplateSpecializationType *TST =
4763 NamedT->getAs<TemplateSpecializationType>()) {
4764 TemplateName Template = TST->getTemplateName();
4765 if (TypeAliasTemplateDecl *TAT =
4766 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4767 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4768 diag::err_tag_reference_non_tag) << 4;
4769 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4770 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004771 }
4772 }
4773
John McCalla2becad2009-10-21 00:40:46 +00004774 QualType Result = TL.getType();
4775 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004776 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004777 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004778 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004779 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004780 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004781 if (Result.isNull())
4782 return QualType();
4783 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004784
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004785 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004786 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004787 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004788 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004789}
Mike Stump1eb44332009-09-09 15:08:12 +00004790
4791template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004792QualType TreeTransform<Derived>::TransformAttributedType(
4793 TypeLocBuilder &TLB,
4794 AttributedTypeLoc TL) {
4795 const AttributedType *oldType = TL.getTypePtr();
4796 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4797 if (modifiedType.isNull())
4798 return QualType();
4799
4800 QualType result = TL.getType();
4801
4802 // FIXME: dependent operand expressions?
4803 if (getDerived().AlwaysRebuild() ||
4804 modifiedType != oldType->getModifiedType()) {
4805 // TODO: this is really lame; we should really be rebuilding the
4806 // equivalent type from first principles.
4807 QualType equivalentType
4808 = getDerived().TransformType(oldType->getEquivalentType());
4809 if (equivalentType.isNull())
4810 return QualType();
4811 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4812 modifiedType,
4813 equivalentType);
4814 }
4815
4816 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4817 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4818 if (TL.hasAttrOperand())
4819 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4820 if (TL.hasAttrExprOperand())
4821 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4822 else if (TL.hasAttrEnumOperand())
4823 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4824
4825 return result;
4826}
4827
4828template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004829QualType
4830TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4831 ParenTypeLoc TL) {
4832 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4833 if (Inner.isNull())
4834 return QualType();
4835
4836 QualType Result = TL.getType();
4837 if (getDerived().AlwaysRebuild() ||
4838 Inner != TL.getInnerLoc().getType()) {
4839 Result = getDerived().RebuildParenType(Inner);
4840 if (Result.isNull())
4841 return QualType();
4842 }
4843
4844 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4845 NewTL.setLParenLoc(TL.getLParenLoc());
4846 NewTL.setRParenLoc(TL.getRParenLoc());
4847 return Result;
4848}
4849
4850template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004851QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004852 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004853 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004854
Douglas Gregor2494dd02011-03-01 01:34:45 +00004855 NestedNameSpecifierLoc QualifierLoc
4856 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4857 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004858 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004859
John McCall33500952010-06-11 00:33:02 +00004860 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004861 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004862 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004863 QualifierLoc,
4864 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004865 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004866 if (Result.isNull())
4867 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004868
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004869 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4870 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004871 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4872
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004873 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004874 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004875 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004876 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004877 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004878 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004879 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004880 NewTL.setNameLoc(TL.getNameLoc());
4881 }
John McCalla2becad2009-10-21 00:40:46 +00004882 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004883}
Mike Stump1eb44332009-09-09 15:08:12 +00004884
Douglas Gregor577f75a2009-08-04 16:50:30 +00004885template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004886QualType TreeTransform<Derived>::
4887 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004888 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004889 NestedNameSpecifierLoc QualifierLoc;
4890 if (TL.getQualifierLoc()) {
4891 QualifierLoc
4892 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4893 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004894 return QualType();
4895 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004896
John McCall43fed0d2010-11-12 08:19:04 +00004897 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004898 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004899}
4900
4901template<typename Derived>
4902QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004903TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4904 DependentTemplateSpecializationTypeLoc TL,
4905 NestedNameSpecifierLoc QualifierLoc) {
4906 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004907
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004908 TemplateArgumentListInfo NewTemplateArgs;
4909 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4910 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004911
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004912 typedef TemplateArgumentLocContainerIterator<
4913 DependentTemplateSpecializationTypeLoc> ArgIterator;
4914 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4915 ArgIterator(TL, TL.getNumArgs()),
4916 NewTemplateArgs))
4917 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004918
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004919 QualType Result
4920 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4921 QualifierLoc,
4922 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004923 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004924 NewTemplateArgs);
4925 if (Result.isNull())
4926 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004927
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004928 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4929 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004930
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004931 // Copy information relevant to the template specialization.
4932 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004933 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004934 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004935 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004936 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4937 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004938 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004939 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004940
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004941 // Copy information relevant to the elaborated type.
4942 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004943 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004944 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004945 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4946 DependentTemplateSpecializationTypeLoc SpecTL
4947 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004948 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004949 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004950 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004951 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004952 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4953 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004954 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004955 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004956 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004957 TemplateSpecializationTypeLoc SpecTL
4958 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004959 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004960 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004961 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4962 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004963 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004964 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004965 }
4966 return Result;
4967}
4968
4969template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004970QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4971 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004972 QualType Pattern
4973 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004974 if (Pattern.isNull())
4975 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004976
4977 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004978 if (getDerived().AlwaysRebuild() ||
4979 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004980 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004981 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004982 TL.getEllipsisLoc(),
4983 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004984 if (Result.isNull())
4985 return QualType();
4986 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004987
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004988 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4989 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4990 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004991}
4992
4993template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004994QualType
4995TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004996 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004997 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004998 TLB.pushFullCopy(TL);
4999 return TL.getType();
5000}
5001
5002template<typename Derived>
5003QualType
5004TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005005 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005006 // ObjCObjectType is never dependent.
5007 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005008 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005009}
Mike Stump1eb44332009-09-09 15:08:12 +00005010
5011template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005012QualType
5013TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005014 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005015 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005016 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005017 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005018}
5019
Douglas Gregor577f75a2009-08-04 16:50:30 +00005020//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005021// Statement transformation
5022//===----------------------------------------------------------------------===//
5023template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005024StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005025TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005026 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005027}
5028
5029template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005030StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005031TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5032 return getDerived().TransformCompoundStmt(S, false);
5033}
5034
5035template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005036StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005037TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005038 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005039 Sema::CompoundScopeRAII CompoundScope(getSema());
5040
John McCall7114cba2010-08-27 19:56:05 +00005041 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005042 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005043 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005044 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5045 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005046 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005047 if (Result.isInvalid()) {
5048 // Immediately fail if this was a DeclStmt, since it's very
5049 // likely that this will cause problems for future statements.
5050 if (isa<DeclStmt>(*B))
5051 return StmtError();
5052
5053 // Otherwise, just keep processing substatements and fail later.
5054 SubStmtInvalid = true;
5055 continue;
5056 }
Mike Stump1eb44332009-09-09 15:08:12 +00005057
Douglas Gregor43959a92009-08-20 07:17:43 +00005058 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5059 Statements.push_back(Result.takeAs<Stmt>());
5060 }
Mike Stump1eb44332009-09-09 15:08:12 +00005061
John McCall7114cba2010-08-27 19:56:05 +00005062 if (SubStmtInvalid)
5063 return StmtError();
5064
Douglas Gregor43959a92009-08-20 07:17:43 +00005065 if (!getDerived().AlwaysRebuild() &&
5066 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005067 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005068
5069 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005070 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005071 S->getRBracLoc(),
5072 IsStmtExpr);
5073}
Mike Stump1eb44332009-09-09 15:08:12 +00005074
Douglas Gregor43959a92009-08-20 07:17:43 +00005075template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005076StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005077TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005078 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005079 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005080 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5081 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005082
Eli Friedman264c1f82009-11-19 03:14:00 +00005083 // Transform the left-hand case value.
5084 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005085 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005086 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005087 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005088
Eli Friedman264c1f82009-11-19 03:14:00 +00005089 // Transform the right-hand case value (for the GNU case-range extension).
5090 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005091 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005092 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005093 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005094 }
Mike Stump1eb44332009-09-09 15:08:12 +00005095
Douglas Gregor43959a92009-08-20 07:17:43 +00005096 // Build the case statement.
5097 // Case statements are always rebuilt so that they will attached to their
5098 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005099 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005100 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005101 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005102 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005103 S->getColonLoc());
5104 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005105 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005106
Douglas Gregor43959a92009-08-20 07:17:43 +00005107 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005108 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005109 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005110 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005111
Douglas Gregor43959a92009-08-20 07:17:43 +00005112 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005113 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005114}
5115
5116template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005117StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005118TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005119 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005120 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005121 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005122 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005123
Douglas Gregor43959a92009-08-20 07:17:43 +00005124 // Default statements are always rebuilt
5125 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005126 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005127}
Mike Stump1eb44332009-09-09 15:08:12 +00005128
Douglas Gregor43959a92009-08-20 07:17:43 +00005129template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005130StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005131TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005132 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005133 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005134 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005135
Chris Lattner57ad3782011-02-17 20:34:02 +00005136 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5137 S->getDecl());
5138 if (!LD)
5139 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005140
5141
Douglas Gregor43959a92009-08-20 07:17:43 +00005142 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005143 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005144 cast<LabelDecl>(LD), SourceLocation(),
5145 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005146}
Mike Stump1eb44332009-09-09 15:08:12 +00005147
Douglas Gregor43959a92009-08-20 07:17:43 +00005148template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005149StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005150TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5151 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5152 if (SubStmt.isInvalid())
5153 return StmtError();
5154
5155 // TODO: transform attributes
5156 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5157 return S;
5158
5159 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5160 S->getAttrs(),
5161 SubStmt.get());
5162}
5163
5164template<typename Derived>
5165StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005166TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005167 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005168 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005169 VarDecl *ConditionVar = 0;
5170 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005171 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005172 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005173 getDerived().TransformDefinition(
5174 S->getConditionVariable()->getLocation(),
5175 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005176 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005177 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005178 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005179 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005180
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005181 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005182 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005183
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005184 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005185 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005186 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005187 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005188 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005189 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005190
John McCall9ae2f072010-08-23 23:25:46 +00005191 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005192 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005193 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005194
John McCall9ae2f072010-08-23 23:25:46 +00005195 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5196 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005197 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005198
Douglas Gregor43959a92009-08-20 07:17:43 +00005199 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005200 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005201 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005202 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005203
Douglas Gregor43959a92009-08-20 07:17:43 +00005204 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005205 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005206 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005207 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005208
Douglas Gregor43959a92009-08-20 07:17:43 +00005209 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005210 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005211 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005212 Then.get() == S->getThen() &&
5213 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005214 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005215
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005216 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005217 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005218 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005219}
5220
5221template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005222StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005223TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005224 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005225 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005226 VarDecl *ConditionVar = 0;
5227 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005228 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005229 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005230 getDerived().TransformDefinition(
5231 S->getConditionVariable()->getLocation(),
5232 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005233 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005234 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005235 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005236 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005237
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005238 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005239 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005240 }
Mike Stump1eb44332009-09-09 15:08:12 +00005241
Douglas Gregor43959a92009-08-20 07:17:43 +00005242 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005243 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005244 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005245 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005246 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005247 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005248
Douglas Gregor43959a92009-08-20 07:17:43 +00005249 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005250 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005251 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005252 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005253
Douglas Gregor43959a92009-08-20 07:17:43 +00005254 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005255 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5256 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005257}
Mike Stump1eb44332009-09-09 15:08:12 +00005258
Douglas Gregor43959a92009-08-20 07:17:43 +00005259template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005260StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005261TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005262 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005263 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005264 VarDecl *ConditionVar = 0;
5265 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005266 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005267 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005268 getDerived().TransformDefinition(
5269 S->getConditionVariable()->getLocation(),
5270 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005271 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005272 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005273 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005274 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005275
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005276 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005277 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005278
5279 if (S->getCond()) {
5280 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005281 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005282 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005283 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005284 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005285 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005286 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005287 }
Mike Stump1eb44332009-09-09 15:08:12 +00005288
John McCall9ae2f072010-08-23 23:25:46 +00005289 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5290 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005291 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005292
Douglas Gregor43959a92009-08-20 07:17:43 +00005293 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005294 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005295 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005296 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005297
Douglas Gregor43959a92009-08-20 07:17:43 +00005298 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005299 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005300 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005301 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005302 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005303
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005304 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005305 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005306}
Mike Stump1eb44332009-09-09 15:08:12 +00005307
Douglas Gregor43959a92009-08-20 07:17:43 +00005308template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005309StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005310TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005311 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005312 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005313 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005314 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005315
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005316 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005317 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005318 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005319 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005320
Douglas Gregor43959a92009-08-20 07:17:43 +00005321 if (!getDerived().AlwaysRebuild() &&
5322 Cond.get() == S->getCond() &&
5323 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005324 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005325
John McCall9ae2f072010-08-23 23:25:46 +00005326 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5327 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005328 S->getRParenLoc());
5329}
Mike Stump1eb44332009-09-09 15:08:12 +00005330
Douglas Gregor43959a92009-08-20 07:17:43 +00005331template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005332StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005333TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005334 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005335 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005336 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005337 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005338
Douglas Gregor43959a92009-08-20 07:17:43 +00005339 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005340 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005341 VarDecl *ConditionVar = 0;
5342 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005343 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005344 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005345 getDerived().TransformDefinition(
5346 S->getConditionVariable()->getLocation(),
5347 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005348 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005349 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005350 } else {
5351 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005352
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005353 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005354 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005355
5356 if (S->getCond()) {
5357 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005358 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005359 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005360 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005361 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005362
John McCall9ae2f072010-08-23 23:25:46 +00005363 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005364 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005365 }
Mike Stump1eb44332009-09-09 15:08:12 +00005366
Chad Rosier4a9d7952012-08-08 18:46:20 +00005367 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005368 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005369 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005370
Douglas Gregor43959a92009-08-20 07:17:43 +00005371 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005372 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005373 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005374 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005375
John McCall9ae2f072010-08-23 23:25:46 +00005376 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5377 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005378 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005379
Douglas Gregor43959a92009-08-20 07:17:43 +00005380 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005381 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005382 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005383 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005384
Douglas Gregor43959a92009-08-20 07:17:43 +00005385 if (!getDerived().AlwaysRebuild() &&
5386 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005387 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005388 Inc.get() == S->getInc() &&
5389 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005390 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005391
Douglas Gregor43959a92009-08-20 07:17:43 +00005392 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005393 Init.get(), FullCond, ConditionVar,
5394 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005395}
5396
5397template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005398StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005399TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005400 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5401 S->getLabel());
5402 if (!LD)
5403 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005404
Douglas Gregor43959a92009-08-20 07:17:43 +00005405 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005406 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005407 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005408}
5409
5410template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005411StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005412TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005413 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005414 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005415 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005416 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005417
Douglas Gregor43959a92009-08-20 07:17:43 +00005418 if (!getDerived().AlwaysRebuild() &&
5419 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005420 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005421
5422 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005423 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005424}
5425
5426template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005427StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005428TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005429 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005430}
Mike Stump1eb44332009-09-09 15:08:12 +00005431
Douglas Gregor43959a92009-08-20 07:17:43 +00005432template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005433StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005434TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005435 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005436}
Mike Stump1eb44332009-09-09 15:08:12 +00005437
Douglas Gregor43959a92009-08-20 07:17:43 +00005438template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005439StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005440TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005441 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005442 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005443 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005444
Mike Stump1eb44332009-09-09 15:08:12 +00005445 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005446 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005447 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005448}
Mike Stump1eb44332009-09-09 15:08:12 +00005449
Douglas Gregor43959a92009-08-20 07:17:43 +00005450template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005451StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005452TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005453 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005454 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005455 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5456 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005457 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5458 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005459 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005460 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005461
Douglas Gregor43959a92009-08-20 07:17:43 +00005462 if (Transformed != *D)
5463 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005464
Douglas Gregor43959a92009-08-20 07:17:43 +00005465 Decls.push_back(Transformed);
5466 }
Mike Stump1eb44332009-09-09 15:08:12 +00005467
Douglas Gregor43959a92009-08-20 07:17:43 +00005468 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005469 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005470
5471 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005472 S->getStartLoc(), S->getEndLoc());
5473}
Mike Stump1eb44332009-09-09 15:08:12 +00005474
Douglas Gregor43959a92009-08-20 07:17:43 +00005475template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005476StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005477TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005478
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005479 SmallVector<Expr*, 8> Constraints;
5480 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005481 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005482
John McCall60d7b3a2010-08-24 06:29:42 +00005483 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005484 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005485
5486 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005487
Anders Carlsson703e3942010-01-24 05:50:09 +00005488 // Go through the outputs.
5489 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005490 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005491
Anders Carlsson703e3942010-01-24 05:50:09 +00005492 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005493 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005494
Anders Carlsson703e3942010-01-24 05:50:09 +00005495 // Transform the output expr.
5496 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005497 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005498 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005499 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005500
Anders Carlsson703e3942010-01-24 05:50:09 +00005501 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005502
John McCall9ae2f072010-08-23 23:25:46 +00005503 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005504 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005505
Anders Carlsson703e3942010-01-24 05:50:09 +00005506 // Go through the inputs.
5507 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005508 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005509
Anders Carlsson703e3942010-01-24 05:50:09 +00005510 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005511 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005512
Anders Carlsson703e3942010-01-24 05:50:09 +00005513 // Transform the input expr.
5514 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005515 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005516 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005517 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005518
Anders Carlsson703e3942010-01-24 05:50:09 +00005519 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005520
John McCall9ae2f072010-08-23 23:25:46 +00005521 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005522 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005523
Anders Carlsson703e3942010-01-24 05:50:09 +00005524 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005525 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005526
5527 // Go through the clobbers.
5528 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005529 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005530
5531 // No need to transform the asm string literal.
5532 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005533 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5534 S->isVolatile(), S->getNumOutputs(),
5535 S->getNumInputs(), Names.data(),
5536 Constraints, Exprs, AsmString.get(),
5537 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005538}
5539
Chad Rosier8cd64b42012-06-11 20:47:18 +00005540template<typename Derived>
5541StmtResult
5542TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005543 ArrayRef<Token> AsmToks =
5544 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005545
Chad Rosier7bd092b2012-08-15 16:53:30 +00005546 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5547 AsmToks, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005548}
Douglas Gregor43959a92009-08-20 07:17:43 +00005549
5550template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005551StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005552TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005553 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005554 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005555 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005556 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005557
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005558 // Transform the @catch statements (if present).
5559 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005560 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005561 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005562 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005563 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005564 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005565 if (Catch.get() != S->getCatchStmt(I))
5566 AnyCatchChanged = true;
5567 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005568 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005569
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005570 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005571 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005572 if (S->getFinallyStmt()) {
5573 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5574 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005575 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005576 }
5577
5578 // If nothing changed, just retain this statement.
5579 if (!getDerived().AlwaysRebuild() &&
5580 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005581 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005582 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005583 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005584
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005585 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005586 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005587 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005588}
Mike Stump1eb44332009-09-09 15:08:12 +00005589
Douglas Gregor43959a92009-08-20 07:17:43 +00005590template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005591StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005592TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005593 // Transform the @catch parameter, if there is one.
5594 VarDecl *Var = 0;
5595 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5596 TypeSourceInfo *TSInfo = 0;
5597 if (FromVar->getTypeSourceInfo()) {
5598 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5599 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005600 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005601 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005602
Douglas Gregorbe270a02010-04-26 17:57:08 +00005603 QualType T;
5604 if (TSInfo)
5605 T = TSInfo->getType();
5606 else {
5607 T = getDerived().TransformType(FromVar->getType());
5608 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005609 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005610 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005611
Douglas Gregorbe270a02010-04-26 17:57:08 +00005612 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5613 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005614 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005615 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005616
John McCall60d7b3a2010-08-24 06:29:42 +00005617 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005618 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005619 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005620
5621 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005622 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005623 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005624}
Mike Stump1eb44332009-09-09 15:08:12 +00005625
Douglas Gregor43959a92009-08-20 07:17:43 +00005626template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005627StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005628TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005629 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005630 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005631 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005632 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005633
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005634 // If nothing changed, just retain this statement.
5635 if (!getDerived().AlwaysRebuild() &&
5636 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005637 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005638
5639 // Build a new statement.
5640 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005641 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005642}
Mike Stump1eb44332009-09-09 15:08:12 +00005643
Douglas Gregor43959a92009-08-20 07:17:43 +00005644template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005645StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005646TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005647 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005648 if (S->getThrowExpr()) {
5649 Operand = getDerived().TransformExpr(S->getThrowExpr());
5650 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005651 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005652 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005653
Douglas Gregord1377b22010-04-22 21:44:01 +00005654 if (!getDerived().AlwaysRebuild() &&
5655 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005656 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005657
John McCall9ae2f072010-08-23 23:25:46 +00005658 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005659}
Mike Stump1eb44332009-09-09 15:08:12 +00005660
Douglas Gregor43959a92009-08-20 07:17:43 +00005661template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005662StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005663TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005664 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005665 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005666 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005667 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005668 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005669 Object =
5670 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5671 Object.get());
5672 if (Object.isInvalid())
5673 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005674
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005675 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005676 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005677 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005678 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005679
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005680 // If nothing change, just retain the current statement.
5681 if (!getDerived().AlwaysRebuild() &&
5682 Object.get() == S->getSynchExpr() &&
5683 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005684 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005685
5686 // Build a new statement.
5687 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005688 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005689}
5690
5691template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005692StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005693TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5694 ObjCAutoreleasePoolStmt *S) {
5695 // Transform the body.
5696 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5697 if (Body.isInvalid())
5698 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005699
John McCallf85e1932011-06-15 23:02:42 +00005700 // If nothing changed, just retain this statement.
5701 if (!getDerived().AlwaysRebuild() &&
5702 Body.get() == S->getSubStmt())
5703 return SemaRef.Owned(S);
5704
5705 // Build a new statement.
5706 return getDerived().RebuildObjCAutoreleasePoolStmt(
5707 S->getAtLoc(), Body.get());
5708}
5709
5710template<typename Derived>
5711StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005712TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005713 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005714 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005715 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005716 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005717 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005718
Douglas Gregorc3203e72010-04-22 23:10:45 +00005719 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005720 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005721 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005722 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005723
Douglas Gregorc3203e72010-04-22 23:10:45 +00005724 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005725 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005726 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005727 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005728
Douglas Gregorc3203e72010-04-22 23:10:45 +00005729 // If nothing changed, just retain this statement.
5730 if (!getDerived().AlwaysRebuild() &&
5731 Element.get() == S->getElement() &&
5732 Collection.get() == S->getCollection() &&
5733 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005734 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005735
Douglas Gregorc3203e72010-04-22 23:10:45 +00005736 // Build a new statement.
5737 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005738 Element.get(),
5739 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005740 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005741 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005742}
5743
5744
5745template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005746StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005747TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5748 // Transform the exception declaration, if any.
5749 VarDecl *Var = 0;
5750 if (S->getExceptionDecl()) {
5751 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005752 TypeSourceInfo *T = getDerived().TransformType(
5753 ExceptionDecl->getTypeSourceInfo());
5754 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005755 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005756
Douglas Gregor83cb9422010-09-09 17:09:21 +00005757 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005758 ExceptionDecl->getInnerLocStart(),
5759 ExceptionDecl->getLocation(),
5760 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005761 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005762 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005763 }
Mike Stump1eb44332009-09-09 15:08:12 +00005764
Douglas Gregor43959a92009-08-20 07:17:43 +00005765 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005766 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005767 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005768 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005769
Douglas Gregor43959a92009-08-20 07:17:43 +00005770 if (!getDerived().AlwaysRebuild() &&
5771 !Var &&
5772 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005773 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005774
5775 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5776 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005777 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005778}
Mike Stump1eb44332009-09-09 15:08:12 +00005779
Douglas Gregor43959a92009-08-20 07:17:43 +00005780template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005781StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005782TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5783 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005784 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005785 = getDerived().TransformCompoundStmt(S->getTryBlock());
5786 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005787 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005788
Douglas Gregor43959a92009-08-20 07:17:43 +00005789 // Transform the handlers.
5790 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005791 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005792 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005793 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005794 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5795 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005796 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005797
Douglas Gregor43959a92009-08-20 07:17:43 +00005798 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5799 Handlers.push_back(Handler.takeAs<Stmt>());
5800 }
Mike Stump1eb44332009-09-09 15:08:12 +00005801
Douglas Gregor43959a92009-08-20 07:17:43 +00005802 if (!getDerived().AlwaysRebuild() &&
5803 TryBlock.get() == S->getTryBlock() &&
5804 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005805 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005806
John McCall9ae2f072010-08-23 23:25:46 +00005807 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005808 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005809}
Mike Stump1eb44332009-09-09 15:08:12 +00005810
Richard Smithad762fc2011-04-14 22:09:26 +00005811template<typename Derived>
5812StmtResult
5813TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5814 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5815 if (Range.isInvalid())
5816 return StmtError();
5817
5818 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5819 if (BeginEnd.isInvalid())
5820 return StmtError();
5821
5822 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5823 if (Cond.isInvalid())
5824 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005825 if (Cond.get())
5826 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5827 if (Cond.isInvalid())
5828 return StmtError();
5829 if (Cond.get())
5830 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005831
5832 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5833 if (Inc.isInvalid())
5834 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005835 if (Inc.get())
5836 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005837
5838 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5839 if (LoopVar.isInvalid())
5840 return StmtError();
5841
5842 StmtResult NewStmt = S;
5843 if (getDerived().AlwaysRebuild() ||
5844 Range.get() != S->getRangeStmt() ||
5845 BeginEnd.get() != S->getBeginEndStmt() ||
5846 Cond.get() != S->getCond() ||
5847 Inc.get() != S->getInc() ||
5848 LoopVar.get() != S->getLoopVarStmt())
5849 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5850 S->getColonLoc(), Range.get(),
5851 BeginEnd.get(), Cond.get(),
5852 Inc.get(), LoopVar.get(),
5853 S->getRParenLoc());
5854
5855 StmtResult Body = getDerived().TransformStmt(S->getBody());
5856 if (Body.isInvalid())
5857 return StmtError();
5858
5859 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5860 // it now so we have a new statement to attach the body to.
5861 if (Body.get() != S->getBody() && NewStmt.get() == S)
5862 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5863 S->getColonLoc(), Range.get(),
5864 BeginEnd.get(), Cond.get(),
5865 Inc.get(), LoopVar.get(),
5866 S->getRParenLoc());
5867
5868 if (NewStmt.get() == S)
5869 return SemaRef.Owned(S);
5870
5871 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5872}
5873
John Wiegley28bbe4b2011-04-28 01:08:34 +00005874template<typename Derived>
5875StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005876TreeTransform<Derived>::TransformMSDependentExistsStmt(
5877 MSDependentExistsStmt *S) {
5878 // Transform the nested-name-specifier, if any.
5879 NestedNameSpecifierLoc QualifierLoc;
5880 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005881 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005882 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5883 if (!QualifierLoc)
5884 return StmtError();
5885 }
5886
5887 // Transform the declaration name.
5888 DeclarationNameInfo NameInfo = S->getNameInfo();
5889 if (NameInfo.getName()) {
5890 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5891 if (!NameInfo.getName())
5892 return StmtError();
5893 }
5894
5895 // Check whether anything changed.
5896 if (!getDerived().AlwaysRebuild() &&
5897 QualifierLoc == S->getQualifierLoc() &&
5898 NameInfo.getName() == S->getNameInfo().getName())
5899 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005900
Douglas Gregorba0513d2011-10-25 01:33:02 +00005901 // Determine whether this name exists, if we can.
5902 CXXScopeSpec SS;
5903 SS.Adopt(QualifierLoc);
5904 bool Dependent = false;
5905 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5906 case Sema::IER_Exists:
5907 if (S->isIfExists())
5908 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005909
Douglas Gregorba0513d2011-10-25 01:33:02 +00005910 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5911
5912 case Sema::IER_DoesNotExist:
5913 if (S->isIfNotExists())
5914 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005915
Douglas Gregorba0513d2011-10-25 01:33:02 +00005916 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005917
Douglas Gregorba0513d2011-10-25 01:33:02 +00005918 case Sema::IER_Dependent:
5919 Dependent = true;
5920 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005921
Douglas Gregor65019ac2011-10-25 03:44:56 +00005922 case Sema::IER_Error:
5923 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005924 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005925
Douglas Gregorba0513d2011-10-25 01:33:02 +00005926 // We need to continue with the instantiation, so do so now.
5927 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5928 if (SubStmt.isInvalid())
5929 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005930
Douglas Gregorba0513d2011-10-25 01:33:02 +00005931 // If we have resolved the name, just transform to the substatement.
5932 if (!Dependent)
5933 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005934
Douglas Gregorba0513d2011-10-25 01:33:02 +00005935 // The name is still dependent, so build a dependent expression again.
5936 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5937 S->isIfExists(),
5938 QualifierLoc,
5939 NameInfo,
5940 SubStmt.get());
5941}
5942
5943template<typename Derived>
5944StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00005945TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5946 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5947 if(TryBlock.isInvalid()) return StmtError();
5948
5949 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5950 if(!getDerived().AlwaysRebuild() &&
5951 TryBlock.get() == S->getTryBlock() &&
5952 Handler.get() == S->getHandler())
5953 return SemaRef.Owned(S);
5954
5955 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5956 S->getTryLoc(),
5957 TryBlock.take(),
5958 Handler.take());
5959}
5960
5961template<typename Derived>
5962StmtResult
5963TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5964 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5965 if(Block.isInvalid()) return StmtError();
5966
5967 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5968 Block.take());
5969}
5970
5971template<typename Derived>
5972StmtResult
5973TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5974 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5975 if(FilterExpr.isInvalid()) return StmtError();
5976
5977 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5978 if(Block.isInvalid()) return StmtError();
5979
5980 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5981 FilterExpr.take(),
5982 Block.take());
5983}
5984
5985template<typename Derived>
5986StmtResult
5987TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5988 if(isa<SEHFinallyStmt>(Handler))
5989 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5990 else
5991 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5992}
5993
Douglas Gregor43959a92009-08-20 07:17:43 +00005994//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005995// Expression transformation
5996//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005997template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005998ExprResult
John McCall454feb92009-12-08 09:21:05 +00005999TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006000 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006001}
Mike Stump1eb44332009-09-09 15:08:12 +00006002
6003template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006004ExprResult
John McCall454feb92009-12-08 09:21:05 +00006005TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006006 NestedNameSpecifierLoc QualifierLoc;
6007 if (E->getQualifierLoc()) {
6008 QualifierLoc
6009 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6010 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006011 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006012 }
John McCalldbd872f2009-12-08 09:08:17 +00006013
6014 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006015 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6016 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006017 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006018 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006019
John McCallec8045d2010-08-17 21:27:17 +00006020 DeclarationNameInfo NameInfo = E->getNameInfo();
6021 if (NameInfo.getName()) {
6022 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6023 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006024 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006025 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006026
6027 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006028 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006029 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006030 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006031 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006032
6033 // Mark it referenced in the new context regardless.
6034 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006035 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006036
John McCall3fa5cae2010-10-26 07:05:15 +00006037 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006038 }
John McCalldbd872f2009-12-08 09:08:17 +00006039
6040 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006041 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006042 TemplateArgs = &TransArgs;
6043 TransArgs.setLAngleLoc(E->getLAngleLoc());
6044 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006045 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6046 E->getNumTemplateArgs(),
6047 TransArgs))
6048 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006049 }
6050
Chad Rosier4a9d7952012-08-08 18:46:20 +00006051 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006052 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006053}
Mike Stump1eb44332009-09-09 15:08:12 +00006054
Douglas Gregorb98b1992009-08-11 05:31:07 +00006055template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006056ExprResult
John McCall454feb92009-12-08 09:21:05 +00006057TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006058 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006059}
Mike Stump1eb44332009-09-09 15:08:12 +00006060
Douglas Gregorb98b1992009-08-11 05:31:07 +00006061template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006062ExprResult
John McCall454feb92009-12-08 09:21:05 +00006063TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006064 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006065}
Mike Stump1eb44332009-09-09 15:08:12 +00006066
Douglas Gregorb98b1992009-08-11 05:31:07 +00006067template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006068ExprResult
John McCall454feb92009-12-08 09:21:05 +00006069TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006070 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006071}
Mike Stump1eb44332009-09-09 15:08:12 +00006072
Douglas Gregorb98b1992009-08-11 05:31:07 +00006073template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006074ExprResult
John McCall454feb92009-12-08 09:21:05 +00006075TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006076 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006077}
Mike Stump1eb44332009-09-09 15:08:12 +00006078
Douglas Gregorb98b1992009-08-11 05:31:07 +00006079template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006080ExprResult
John McCall454feb92009-12-08 09:21:05 +00006081TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006082 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006083}
6084
6085template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006086ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006087TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6088 return SemaRef.MaybeBindToTemporary(E);
6089}
6090
6091template<typename Derived>
6092ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006093TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6094 ExprResult ControllingExpr =
6095 getDerived().TransformExpr(E->getControllingExpr());
6096 if (ControllingExpr.isInvalid())
6097 return ExprError();
6098
Chris Lattner686775d2011-07-20 06:58:45 +00006099 SmallVector<Expr *, 4> AssocExprs;
6100 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006101 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6102 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6103 if (TS) {
6104 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6105 if (!AssocType)
6106 return ExprError();
6107 AssocTypes.push_back(AssocType);
6108 } else {
6109 AssocTypes.push_back(0);
6110 }
6111
6112 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6113 if (AssocExpr.isInvalid())
6114 return ExprError();
6115 AssocExprs.push_back(AssocExpr.release());
6116 }
6117
6118 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6119 E->getDefaultLoc(),
6120 E->getRParenLoc(),
6121 ControllingExpr.release(),
6122 AssocTypes.data(),
6123 AssocExprs.data(),
6124 E->getNumAssocs());
6125}
6126
6127template<typename Derived>
6128ExprResult
John McCall454feb92009-12-08 09:21:05 +00006129TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006130 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006131 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006132 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006133
Douglas Gregorb98b1992009-08-11 05:31:07 +00006134 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006135 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006136
John McCall9ae2f072010-08-23 23:25:46 +00006137 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006138 E->getRParen());
6139}
6140
Mike Stump1eb44332009-09-09 15:08:12 +00006141template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006142ExprResult
John McCall454feb92009-12-08 09:21:05 +00006143TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006144 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006145 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006146 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006147
Douglas Gregorb98b1992009-08-11 05:31:07 +00006148 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006149 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006150
Douglas Gregorb98b1992009-08-11 05:31:07 +00006151 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6152 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006153 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006154}
Mike Stump1eb44332009-09-09 15:08:12 +00006155
Douglas Gregorb98b1992009-08-11 05:31:07 +00006156template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006157ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006158TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6159 // Transform the type.
6160 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6161 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006162 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006163
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006164 // Transform all of the components into components similar to what the
6165 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006166 // FIXME: It would be slightly more efficient in the non-dependent case to
6167 // just map FieldDecls, rather than requiring the rebuilder to look for
6168 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006169 // template code that we don't care.
6170 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006171 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006172 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006173 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006174 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6175 const Node &ON = E->getComponent(I);
6176 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006177 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006178 Comp.LocStart = ON.getSourceRange().getBegin();
6179 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006180 switch (ON.getKind()) {
6181 case Node::Array: {
6182 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006183 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006184 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006185 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006186
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006187 ExprChanged = ExprChanged || Index.get() != FromIndex;
6188 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006189 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006190 break;
6191 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006192
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006193 case Node::Field:
6194 case Node::Identifier:
6195 Comp.isBrackets = false;
6196 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006197 if (!Comp.U.IdentInfo)
6198 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006199
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006200 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006201
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006202 case Node::Base:
6203 // Will be recomputed during the rebuild.
6204 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006205 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006206
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006207 Components.push_back(Comp);
6208 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006209
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006210 // If nothing changed, retain the existing expression.
6211 if (!getDerived().AlwaysRebuild() &&
6212 Type == E->getTypeSourceInfo() &&
6213 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006214 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006215
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006216 // Build a new offsetof expression.
6217 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6218 Components.data(), Components.size(),
6219 E->getRParenLoc());
6220}
6221
6222template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006223ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006224TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6225 assert(getDerived().AlreadyTransformed(E->getType()) &&
6226 "opaque value expression requires transformation");
6227 return SemaRef.Owned(E);
6228}
6229
6230template<typename Derived>
6231ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006232TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006233 // Rebuild the syntactic form. The original syntactic form has
6234 // opaque-value expressions in it, so strip those away and rebuild
6235 // the result. This is a really awful way of doing this, but the
6236 // better solution (rebuilding the semantic expressions and
6237 // rebinding OVEs as necessary) doesn't work; we'd need
6238 // TreeTransform to not strip away implicit conversions.
6239 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6240 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006241 if (result.isInvalid()) return ExprError();
6242
6243 // If that gives us a pseudo-object result back, the pseudo-object
6244 // expression must have been an lvalue-to-rvalue conversion which we
6245 // should reapply.
6246 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6247 result = SemaRef.checkPseudoObjectRValue(result.take());
6248
6249 return result;
6250}
6251
6252template<typename Derived>
6253ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006254TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6255 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006256 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006257 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006258
John McCalla93c9342009-12-07 02:54:59 +00006259 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006260 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006261 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006262
John McCall5ab75172009-11-04 07:28:41 +00006263 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006264 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006265
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006266 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6267 E->getKind(),
6268 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006269 }
Mike Stump1eb44332009-09-09 15:08:12 +00006270
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006271 // C++0x [expr.sizeof]p1:
6272 // The operand is either an expression, which is an unevaluated operand
6273 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006274 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6275 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006276
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006277 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6278 if (SubExpr.isInvalid())
6279 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006280
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006281 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6282 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006283
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006284 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6285 E->getOperatorLoc(),
6286 E->getKind(),
6287 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006288}
Mike Stump1eb44332009-09-09 15:08:12 +00006289
Douglas Gregorb98b1992009-08-11 05:31:07 +00006290template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006291ExprResult
John McCall454feb92009-12-08 09:21:05 +00006292TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006293 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006294 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006295 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006296
John McCall60d7b3a2010-08-24 06:29:42 +00006297 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006298 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006299 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006300
6301
Douglas Gregorb98b1992009-08-11 05:31:07 +00006302 if (!getDerived().AlwaysRebuild() &&
6303 LHS.get() == E->getLHS() &&
6304 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006305 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006306
John McCall9ae2f072010-08-23 23:25:46 +00006307 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006308 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006309 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006310 E->getRBracketLoc());
6311}
Mike Stump1eb44332009-09-09 15:08:12 +00006312
6313template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006314ExprResult
John McCall454feb92009-12-08 09:21:05 +00006315TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006316 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006317 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006318 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006319 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006320
6321 // Transform arguments.
6322 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006323 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006324 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006325 &ArgChanged))
6326 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006327
Douglas Gregorb98b1992009-08-11 05:31:07 +00006328 if (!getDerived().AlwaysRebuild() &&
6329 Callee.get() == E->getCallee() &&
6330 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006331 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006332
Douglas Gregorb98b1992009-08-11 05:31:07 +00006333 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006334 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006335 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006336 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006337 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006338 E->getRParenLoc());
6339}
Mike Stump1eb44332009-09-09 15:08:12 +00006340
6341template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006342ExprResult
John McCall454feb92009-12-08 09:21:05 +00006343TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006344 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006345 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006346 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006347
Douglas Gregor40d96a62011-02-28 21:54:11 +00006348 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006349 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006350 QualifierLoc
6351 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006352
Douglas Gregor40d96a62011-02-28 21:54:11 +00006353 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006354 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006355 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006356 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006357
Eli Friedmanf595cc42009-12-04 06:40:45 +00006358 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006359 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6360 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006361 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006362 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006363
John McCall6bb80172010-03-30 21:47:33 +00006364 NamedDecl *FoundDecl = E->getFoundDecl();
6365 if (FoundDecl == E->getMemberDecl()) {
6366 FoundDecl = Member;
6367 } else {
6368 FoundDecl = cast_or_null<NamedDecl>(
6369 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6370 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006371 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006372 }
6373
Douglas Gregorb98b1992009-08-11 05:31:07 +00006374 if (!getDerived().AlwaysRebuild() &&
6375 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006376 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006377 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006378 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006379 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006380
Anders Carlsson1f240322009-12-22 05:24:09 +00006381 // Mark it referenced in the new context regardless.
6382 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006383 SemaRef.MarkMemberReferenced(E);
6384
John McCall3fa5cae2010-10-26 07:05:15 +00006385 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006386 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006387
John McCalld5532b62009-11-23 01:53:49 +00006388 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006389 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006390 TransArgs.setLAngleLoc(E->getLAngleLoc());
6391 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006392 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6393 E->getNumTemplateArgs(),
6394 TransArgs))
6395 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006396 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006397
Douglas Gregorb98b1992009-08-11 05:31:07 +00006398 // FIXME: Bogus source location for the operator
6399 SourceLocation FakeOperatorLoc
6400 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6401
John McCallc2233c52010-01-15 08:34:02 +00006402 // FIXME: to do this check properly, we will need to preserve the
6403 // first-qualifier-in-scope here, just in case we had a dependent
6404 // base (and therefore couldn't do the check) and a
6405 // nested-name-qualifier (and therefore could do the lookup).
6406 NamedDecl *FirstQualifierInScope = 0;
6407
John McCall9ae2f072010-08-23 23:25:46 +00006408 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006409 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006410 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006411 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006412 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006413 Member,
John McCall6bb80172010-03-30 21:47:33 +00006414 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006415 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006416 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006417 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006418}
Mike Stump1eb44332009-09-09 15:08:12 +00006419
Douglas Gregorb98b1992009-08-11 05:31:07 +00006420template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006421ExprResult
John McCall454feb92009-12-08 09:21:05 +00006422TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006423 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006424 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006425 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006426
John McCall60d7b3a2010-08-24 06:29:42 +00006427 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006428 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006429 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006430
Douglas Gregorb98b1992009-08-11 05:31:07 +00006431 if (!getDerived().AlwaysRebuild() &&
6432 LHS.get() == E->getLHS() &&
6433 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006434 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006435
Lang Hamesbe9af122012-10-02 04:45:10 +00006436 Sema::FPContractStateRAII FPContractState(getSema());
6437 getSema().FPFeatures.fp_contract = E->isFPContractable();
6438
Douglas Gregorb98b1992009-08-11 05:31:07 +00006439 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006440 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006441}
6442
Mike Stump1eb44332009-09-09 15:08:12 +00006443template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006444ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006445TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006446 CompoundAssignOperator *E) {
6447 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006448}
Mike Stump1eb44332009-09-09 15:08:12 +00006449
Douglas Gregorb98b1992009-08-11 05:31:07 +00006450template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006451ExprResult TreeTransform<Derived>::
6452TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6453 // Just rebuild the common and RHS expressions and see whether we
6454 // get any changes.
6455
6456 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6457 if (commonExpr.isInvalid())
6458 return ExprError();
6459
6460 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6461 if (rhs.isInvalid())
6462 return ExprError();
6463
6464 if (!getDerived().AlwaysRebuild() &&
6465 commonExpr.get() == e->getCommon() &&
6466 rhs.get() == e->getFalseExpr())
6467 return SemaRef.Owned(e);
6468
6469 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6470 e->getQuestionLoc(),
6471 0,
6472 e->getColonLoc(),
6473 rhs.get());
6474}
6475
6476template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006477ExprResult
John McCall454feb92009-12-08 09:21:05 +00006478TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006479 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006480 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006481 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006482
John McCall60d7b3a2010-08-24 06:29:42 +00006483 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006485 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006486
John McCall60d7b3a2010-08-24 06:29:42 +00006487 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006488 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006489 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006490
Douglas Gregorb98b1992009-08-11 05:31:07 +00006491 if (!getDerived().AlwaysRebuild() &&
6492 Cond.get() == E->getCond() &&
6493 LHS.get() == E->getLHS() &&
6494 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006495 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006496
John McCall9ae2f072010-08-23 23:25:46 +00006497 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006498 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006499 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006500 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006501 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006502}
Mike Stump1eb44332009-09-09 15:08:12 +00006503
6504template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006505ExprResult
John McCall454feb92009-12-08 09:21:05 +00006506TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006507 // Implicit casts are eliminated during transformation, since they
6508 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006509 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006510}
Mike Stump1eb44332009-09-09 15:08:12 +00006511
Douglas Gregorb98b1992009-08-11 05:31:07 +00006512template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006513ExprResult
John McCall454feb92009-12-08 09:21:05 +00006514TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006515 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6516 if (!Type)
6517 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006518
John McCall60d7b3a2010-08-24 06:29:42 +00006519 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006520 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006521 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006522 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006523
Douglas Gregorb98b1992009-08-11 05:31:07 +00006524 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006525 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006526 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006527 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006528
John McCall9d125032010-01-15 18:39:57 +00006529 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006530 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006531 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006532 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006533}
Mike Stump1eb44332009-09-09 15:08:12 +00006534
Douglas Gregorb98b1992009-08-11 05:31:07 +00006535template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006536ExprResult
John McCall454feb92009-12-08 09:21:05 +00006537TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006538 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6539 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6540 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006541 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006542
John McCall60d7b3a2010-08-24 06:29:42 +00006543 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006544 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006545 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006546
Douglas Gregorb98b1992009-08-11 05:31:07 +00006547 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006548 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006549 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006550 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006551
John McCall1d7d8d62010-01-19 22:33:45 +00006552 // Note: the expression type doesn't necessarily match the
6553 // type-as-written, but that's okay, because it should always be
6554 // derivable from the initializer.
6555
John McCall42f56b52010-01-18 19:35:47 +00006556 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006557 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006558 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006559}
Mike Stump1eb44332009-09-09 15:08:12 +00006560
Douglas Gregorb98b1992009-08-11 05:31:07 +00006561template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006562ExprResult
John McCall454feb92009-12-08 09:21:05 +00006563TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006564 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006565 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006566 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006567
Douglas Gregorb98b1992009-08-11 05:31:07 +00006568 if (!getDerived().AlwaysRebuild() &&
6569 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006570 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006571
Douglas Gregorb98b1992009-08-11 05:31:07 +00006572 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006573 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006574 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006575 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006576 E->getAccessorLoc(),
6577 E->getAccessor());
6578}
Mike Stump1eb44332009-09-09 15:08:12 +00006579
Douglas Gregorb98b1992009-08-11 05:31:07 +00006580template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006581ExprResult
John McCall454feb92009-12-08 09:21:05 +00006582TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006583 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006584
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006585 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006586 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006587 Inits, &InitChanged))
6588 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006589
Douglas Gregorb98b1992009-08-11 05:31:07 +00006590 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006591 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006592
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006593 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006594 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006595}
Mike Stump1eb44332009-09-09 15:08:12 +00006596
Douglas Gregorb98b1992009-08-11 05:31:07 +00006597template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006598ExprResult
John McCall454feb92009-12-08 09:21:05 +00006599TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006600 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006601
Douglas Gregor43959a92009-08-20 07:17:43 +00006602 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006603 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006604 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006605 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006606
Douglas Gregor43959a92009-08-20 07:17:43 +00006607 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006608 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006609 bool ExprChanged = false;
6610 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6611 DEnd = E->designators_end();
6612 D != DEnd; ++D) {
6613 if (D->isFieldDesignator()) {
6614 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6615 D->getDotLoc(),
6616 D->getFieldLoc()));
6617 continue;
6618 }
Mike Stump1eb44332009-09-09 15:08:12 +00006619
Douglas Gregorb98b1992009-08-11 05:31:07 +00006620 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006621 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006622 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006623 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006624
6625 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006626 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006627
Douglas Gregorb98b1992009-08-11 05:31:07 +00006628 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6629 ArrayExprs.push_back(Index.release());
6630 continue;
6631 }
Mike Stump1eb44332009-09-09 15:08:12 +00006632
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006634 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6636 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006637 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006638
John McCall60d7b3a2010-08-24 06:29:42 +00006639 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006641 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006642
6643 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006644 End.get(),
6645 D->getLBracketLoc(),
6646 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006647
Douglas Gregorb98b1992009-08-11 05:31:07 +00006648 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6649 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006650
Douglas Gregorb98b1992009-08-11 05:31:07 +00006651 ArrayExprs.push_back(Start.release());
6652 ArrayExprs.push_back(End.release());
6653 }
Mike Stump1eb44332009-09-09 15:08:12 +00006654
Douglas Gregorb98b1992009-08-11 05:31:07 +00006655 if (!getDerived().AlwaysRebuild() &&
6656 Init.get() == E->getInit() &&
6657 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006658 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006659
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006660 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006661 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006662 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006663}
Mike Stump1eb44332009-09-09 15:08:12 +00006664
Douglas Gregorb98b1992009-08-11 05:31:07 +00006665template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006666ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006668 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006669 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006670
Douglas Gregor5557b252009-10-28 00:29:27 +00006671 // FIXME: Will we ever have proper type location here? Will we actually
6672 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006673 QualType T = getDerived().TransformType(E->getType());
6674 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006675 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006676
Douglas Gregorb98b1992009-08-11 05:31:07 +00006677 if (!getDerived().AlwaysRebuild() &&
6678 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006679 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006680
Douglas Gregorb98b1992009-08-11 05:31:07 +00006681 return getDerived().RebuildImplicitValueInitExpr(T);
6682}
Mike Stump1eb44332009-09-09 15:08:12 +00006683
Douglas Gregorb98b1992009-08-11 05:31:07 +00006684template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006685ExprResult
John McCall454feb92009-12-08 09:21:05 +00006686TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006687 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6688 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006689 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006690
John McCall60d7b3a2010-08-24 06:29:42 +00006691 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006693 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006694
Douglas Gregorb98b1992009-08-11 05:31:07 +00006695 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006696 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006697 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006698 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006699
John McCall9ae2f072010-08-23 23:25:46 +00006700 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006701 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006702}
6703
6704template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006705ExprResult
John McCall454feb92009-12-08 09:21:05 +00006706TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006707 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006708 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006709 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6710 &ArgumentChanged))
6711 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006712
Douglas Gregorb98b1992009-08-11 05:31:07 +00006713 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006714 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006715 E->getRParenLoc());
6716}
Mike Stump1eb44332009-09-09 15:08:12 +00006717
Douglas Gregorb98b1992009-08-11 05:31:07 +00006718/// \brief Transform an address-of-label expression.
6719///
6720/// By default, the transformation of an address-of-label expression always
6721/// rebuilds the expression, so that the label identifier can be resolved to
6722/// the corresponding label statement by semantic analysis.
6723template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006724ExprResult
John McCall454feb92009-12-08 09:21:05 +00006725TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006726 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6727 E->getLabel());
6728 if (!LD)
6729 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006730
Douglas Gregorb98b1992009-08-11 05:31:07 +00006731 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006732 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733}
Mike Stump1eb44332009-09-09 15:08:12 +00006734
6735template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006736ExprResult
John McCall454feb92009-12-08 09:21:05 +00006737TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006738 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006739 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006740 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006741 if (SubStmt.isInvalid()) {
6742 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006743 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006744 }
Mike Stump1eb44332009-09-09 15:08:12 +00006745
Douglas Gregorb98b1992009-08-11 05:31:07 +00006746 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006747 SubStmt.get() == E->getSubStmt()) {
6748 // Calling this an 'error' is unintuitive, but it does the right thing.
6749 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006750 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006751 }
Mike Stump1eb44332009-09-09 15:08:12 +00006752
6753 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006754 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006755 E->getRParenLoc());
6756}
Mike Stump1eb44332009-09-09 15:08:12 +00006757
Douglas Gregorb98b1992009-08-11 05:31:07 +00006758template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006759ExprResult
John McCall454feb92009-12-08 09:21:05 +00006760TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006761 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006762 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006763 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006764
John McCall60d7b3a2010-08-24 06:29:42 +00006765 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006766 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006767 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006768
John McCall60d7b3a2010-08-24 06:29:42 +00006769 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006770 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006771 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006772
Douglas Gregorb98b1992009-08-11 05:31:07 +00006773 if (!getDerived().AlwaysRebuild() &&
6774 Cond.get() == E->getCond() &&
6775 LHS.get() == E->getLHS() &&
6776 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006777 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006778
Douglas Gregorb98b1992009-08-11 05:31:07 +00006779 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006780 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006781 E->getRParenLoc());
6782}
Mike Stump1eb44332009-09-09 15:08:12 +00006783
Douglas Gregorb98b1992009-08-11 05:31:07 +00006784template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006785ExprResult
John McCall454feb92009-12-08 09:21:05 +00006786TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006787 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006788}
6789
6790template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006791ExprResult
John McCall454feb92009-12-08 09:21:05 +00006792TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006793 switch (E->getOperator()) {
6794 case OO_New:
6795 case OO_Delete:
6796 case OO_Array_New:
6797 case OO_Array_Delete:
6798 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006799
Douglas Gregor668d6d92009-12-13 20:44:55 +00006800 case OO_Call: {
6801 // This is a call to an object's operator().
6802 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6803
6804 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006805 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006806 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006807 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006808
6809 // FIXME: Poor location information
6810 SourceLocation FakeLParenLoc
6811 = SemaRef.PP.getLocForEndOfToken(
6812 static_cast<Expr *>(Object.get())->getLocEnd());
6813
6814 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006815 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006816 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006817 Args))
6818 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006819
John McCall9ae2f072010-08-23 23:25:46 +00006820 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006821 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006822 E->getLocEnd());
6823 }
6824
6825#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6826 case OO_##Name:
6827#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6828#include "clang/Basic/OperatorKinds.def"
6829 case OO_Subscript:
6830 // Handled below.
6831 break;
6832
6833 case OO_Conditional:
6834 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006835
6836 case OO_None:
6837 case NUM_OVERLOADED_OPERATORS:
6838 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006839 }
6840
John McCall60d7b3a2010-08-24 06:29:42 +00006841 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006842 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006843 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006844
John McCall60d7b3a2010-08-24 06:29:42 +00006845 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006846 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006847 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006848
John McCall60d7b3a2010-08-24 06:29:42 +00006849 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006850 if (E->getNumArgs() == 2) {
6851 Second = getDerived().TransformExpr(E->getArg(1));
6852 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006853 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006854 }
Mike Stump1eb44332009-09-09 15:08:12 +00006855
Douglas Gregorb98b1992009-08-11 05:31:07 +00006856 if (!getDerived().AlwaysRebuild() &&
6857 Callee.get() == E->getCallee() &&
6858 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006859 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006860 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006861
Lang Hamesbe9af122012-10-02 04:45:10 +00006862 Sema::FPContractStateRAII FPContractState(getSema());
6863 getSema().FPFeatures.fp_contract = E->isFPContractable();
6864
Douglas Gregorb98b1992009-08-11 05:31:07 +00006865 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6866 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006867 Callee.get(),
6868 First.get(),
6869 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006870}
Mike Stump1eb44332009-09-09 15:08:12 +00006871
Douglas Gregorb98b1992009-08-11 05:31:07 +00006872template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006873ExprResult
John McCall454feb92009-12-08 09:21:05 +00006874TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6875 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006876}
Mike Stump1eb44332009-09-09 15:08:12 +00006877
Douglas Gregorb98b1992009-08-11 05:31:07 +00006878template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006879ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006880TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6881 // Transform the callee.
6882 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6883 if (Callee.isInvalid())
6884 return ExprError();
6885
6886 // Transform exec config.
6887 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6888 if (EC.isInvalid())
6889 return ExprError();
6890
6891 // Transform arguments.
6892 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006893 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006894 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006895 &ArgChanged))
6896 return ExprError();
6897
6898 if (!getDerived().AlwaysRebuild() &&
6899 Callee.get() == E->getCallee() &&
6900 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006901 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006902
6903 // FIXME: Wrong source location information for the '('.
6904 SourceLocation FakeLParenLoc
6905 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6906 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006907 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006908 E->getRParenLoc(), EC.get());
6909}
6910
6911template<typename Derived>
6912ExprResult
John McCall454feb92009-12-08 09:21:05 +00006913TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006914 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6915 if (!Type)
6916 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006917
John McCall60d7b3a2010-08-24 06:29:42 +00006918 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006919 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006920 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006921 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006922
Douglas Gregorb98b1992009-08-11 05:31:07 +00006923 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006924 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006925 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006926 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006927
Douglas Gregorb98b1992009-08-11 05:31:07 +00006928 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006929 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006930 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6931 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6932 SourceLocation FakeRParenLoc
6933 = SemaRef.PP.getLocForEndOfToken(
6934 E->getSubExpr()->getSourceRange().getEnd());
6935 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006936 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006937 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006938 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006939 FakeRAngleLoc,
6940 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006941 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006942 FakeRParenLoc);
6943}
Mike Stump1eb44332009-09-09 15:08:12 +00006944
Douglas Gregorb98b1992009-08-11 05:31:07 +00006945template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006946ExprResult
John McCall454feb92009-12-08 09:21:05 +00006947TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6948 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006949}
Mike Stump1eb44332009-09-09 15:08:12 +00006950
6951template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006952ExprResult
John McCall454feb92009-12-08 09:21:05 +00006953TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6954 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006955}
6956
Douglas Gregorb98b1992009-08-11 05:31:07 +00006957template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006958ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006959TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006960 CXXReinterpretCastExpr *E) {
6961 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006962}
Mike Stump1eb44332009-09-09 15:08:12 +00006963
Douglas Gregorb98b1992009-08-11 05:31:07 +00006964template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006965ExprResult
John McCall454feb92009-12-08 09:21:05 +00006966TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6967 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006968}
Mike Stump1eb44332009-09-09 15:08:12 +00006969
Douglas Gregorb98b1992009-08-11 05:31:07 +00006970template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006971ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006972TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006973 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006974 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6975 if (!Type)
6976 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006977
John McCall60d7b3a2010-08-24 06:29:42 +00006978 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006979 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006980 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006981 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006982
Douglas Gregorb98b1992009-08-11 05:31:07 +00006983 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006984 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006985 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006986 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006987
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006988 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006989 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006990 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006991 E->getRParenLoc());
6992}
Mike Stump1eb44332009-09-09 15:08:12 +00006993
Douglas Gregorb98b1992009-08-11 05:31:07 +00006994template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006995ExprResult
John McCall454feb92009-12-08 09:21:05 +00006996TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006997 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006998 TypeSourceInfo *TInfo
6999 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7000 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007001 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007002
Douglas Gregorb98b1992009-08-11 05:31:07 +00007003 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007004 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007005 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007006
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007007 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7008 E->getLocStart(),
7009 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007010 E->getLocEnd());
7011 }
Mike Stump1eb44332009-09-09 15:08:12 +00007012
Eli Friedmanef331b72012-01-20 01:26:23 +00007013 // We don't know whether the subexpression is potentially evaluated until
7014 // after we perform semantic analysis. We speculatively assume it is
7015 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007016 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007017 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7018 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007019
John McCall60d7b3a2010-08-24 06:29:42 +00007020 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007021 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007022 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007023
Douglas Gregorb98b1992009-08-11 05:31:07 +00007024 if (!getDerived().AlwaysRebuild() &&
7025 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007026 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007027
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007028 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7029 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007030 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031 E->getLocEnd());
7032}
7033
7034template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007035ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007036TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7037 if (E->isTypeOperand()) {
7038 TypeSourceInfo *TInfo
7039 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7040 if (!TInfo)
7041 return ExprError();
7042
7043 if (!getDerived().AlwaysRebuild() &&
7044 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007045 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007046
Douglas Gregor3c52a212011-03-06 17:40:41 +00007047 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007048 E->getLocStart(),
7049 TInfo,
7050 E->getLocEnd());
7051 }
7052
Francois Pichet01b7c302010-09-08 12:20:18 +00007053 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7054
7055 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7056 if (SubExpr.isInvalid())
7057 return ExprError();
7058
7059 if (!getDerived().AlwaysRebuild() &&
7060 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007061 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007062
7063 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7064 E->getLocStart(),
7065 SubExpr.get(),
7066 E->getLocEnd());
7067}
7068
7069template<typename Derived>
7070ExprResult
John McCall454feb92009-12-08 09:21:05 +00007071TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007072 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007073}
Mike Stump1eb44332009-09-09 15:08:12 +00007074
Douglas Gregorb98b1992009-08-11 05:31:07 +00007075template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007076ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007077TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007078 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007079 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007080}
Mike Stump1eb44332009-09-09 15:08:12 +00007081
Douglas Gregorb98b1992009-08-11 05:31:07 +00007082template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007083ExprResult
John McCall454feb92009-12-08 09:21:05 +00007084TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007085 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007086 QualType T;
7087 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7088 T = MD->getThisType(getSema().Context);
7089 else
7090 T = getSema().Context.getPointerType(
7091 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007092
Douglas Gregorec79d872012-02-24 17:41:38 +00007093 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7094 // Make sure that we capture 'this'.
7095 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007096 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007097 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007098
Douglas Gregor828a1972010-01-07 23:12:05 +00007099 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007100}
Mike Stump1eb44332009-09-09 15:08:12 +00007101
Douglas Gregorb98b1992009-08-11 05:31:07 +00007102template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007103ExprResult
John McCall454feb92009-12-08 09:21:05 +00007104TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007105 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007106 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007107 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007108
Douglas Gregorb98b1992009-08-11 05:31:07 +00007109 if (!getDerived().AlwaysRebuild() &&
7110 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007111 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007112
Douglas Gregorbca01b42011-07-06 22:04:06 +00007113 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7114 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007115}
Mike Stump1eb44332009-09-09 15:08:12 +00007116
Douglas Gregorb98b1992009-08-11 05:31:07 +00007117template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007118ExprResult
John McCall454feb92009-12-08 09:21:05 +00007119TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007120 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007121 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7122 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007123 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007124 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007125
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007126 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007127 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007128 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007129
Douglas Gregor036aed12009-12-23 23:03:06 +00007130 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007131}
Mike Stump1eb44332009-09-09 15:08:12 +00007132
Douglas Gregorb98b1992009-08-11 05:31:07 +00007133template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007134ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007135TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7136 CXXScalarValueInitExpr *E) {
7137 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7138 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007139 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007140
Douglas Gregorb98b1992009-08-11 05:31:07 +00007141 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007142 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007143 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007144
Chad Rosier4a9d7952012-08-08 18:46:20 +00007145 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007146 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007147 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007148}
Mike Stump1eb44332009-09-09 15:08:12 +00007149
Douglas Gregorb98b1992009-08-11 05:31:07 +00007150template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007151ExprResult
John McCall454feb92009-12-08 09:21:05 +00007152TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007153 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007154 TypeSourceInfo *AllocTypeInfo
7155 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7156 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007157 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007158
Douglas Gregorb98b1992009-08-11 05:31:07 +00007159 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007160 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007161 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007162 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007163
Douglas Gregorb98b1992009-08-11 05:31:07 +00007164 // Transform the placement arguments (if any).
7165 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007166 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007167 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007168 E->getNumPlacementArgs(), true,
7169 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007170 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007171
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007172 // Transform the initializer (if any).
7173 Expr *OldInit = E->getInitializer();
7174 ExprResult NewInit;
7175 if (OldInit)
7176 NewInit = getDerived().TransformExpr(OldInit);
7177 if (NewInit.isInvalid())
7178 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007179
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007180 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007181 FunctionDecl *OperatorNew = 0;
7182 if (E->getOperatorNew()) {
7183 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007184 getDerived().TransformDecl(E->getLocStart(),
7185 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007186 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007187 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007188 }
7189
7190 FunctionDecl *OperatorDelete = 0;
7191 if (E->getOperatorDelete()) {
7192 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007193 getDerived().TransformDecl(E->getLocStart(),
7194 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007195 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007196 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007197 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007198
Douglas Gregorb98b1992009-08-11 05:31:07 +00007199 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007200 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007201 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007202 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007203 OperatorNew == E->getOperatorNew() &&
7204 OperatorDelete == E->getOperatorDelete() &&
7205 !ArgumentChanged) {
7206 // Mark any declarations we need as referenced.
7207 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007208 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007209 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007210 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007211 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007212
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007213 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007214 QualType ElementType
7215 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7216 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7217 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7218 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007219 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007220 }
7221 }
7222 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007223
John McCall3fa5cae2010-10-26 07:05:15 +00007224 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007225 }
Mike Stump1eb44332009-09-09 15:08:12 +00007226
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007227 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007228 if (!ArraySize.get()) {
7229 // If no array size was specified, but the new expression was
7230 // instantiated with an array type (e.g., "new T" where T is
7231 // instantiated with "int[4]"), extract the outer bound from the
7232 // array type as our array size. We do this with constant and
7233 // dependently-sized array types.
7234 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7235 if (!ArrayT) {
7236 // Do nothing
7237 } else if (const ConstantArrayType *ConsArrayT
7238 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007239 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007240 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007241 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007242 SemaRef.Context.getSizeType(),
7243 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007244 AllocType = ConsArrayT->getElementType();
7245 } else if (const DependentSizedArrayType *DepArrayT
7246 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7247 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007248 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007249 AllocType = DepArrayT->getElementType();
7250 }
7251 }
7252 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007253
Douglas Gregorb98b1992009-08-11 05:31:07 +00007254 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7255 E->isGlobalNew(),
7256 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007257 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007258 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007259 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007260 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007261 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007262 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007263 E->getDirectInitRange(),
7264 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007265}
Mike Stump1eb44332009-09-09 15:08:12 +00007266
Douglas Gregorb98b1992009-08-11 05:31:07 +00007267template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007268ExprResult
John McCall454feb92009-12-08 09:21:05 +00007269TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007270 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007271 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007272 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007273
Douglas Gregor1af74512010-02-26 00:38:10 +00007274 // Transform the delete operator, if known.
7275 FunctionDecl *OperatorDelete = 0;
7276 if (E->getOperatorDelete()) {
7277 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007278 getDerived().TransformDecl(E->getLocStart(),
7279 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007280 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007281 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007282 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007283
Douglas Gregorb98b1992009-08-11 05:31:07 +00007284 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007285 Operand.get() == E->getArgument() &&
7286 OperatorDelete == E->getOperatorDelete()) {
7287 // Mark any declarations we need as referenced.
7288 // FIXME: instantiation-specific.
7289 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007290 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007291
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007292 if (!E->getArgument()->isTypeDependent()) {
7293 QualType Destroyed = SemaRef.Context.getBaseElementType(
7294 E->getDestroyedType());
7295 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7296 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007297 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007298 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007299 }
7300 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007301
John McCall3fa5cae2010-10-26 07:05:15 +00007302 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007303 }
Mike Stump1eb44332009-09-09 15:08:12 +00007304
Douglas Gregorb98b1992009-08-11 05:31:07 +00007305 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7306 E->isGlobalDelete(),
7307 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007308 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007309}
Mike Stump1eb44332009-09-09 15:08:12 +00007310
Douglas Gregorb98b1992009-08-11 05:31:07 +00007311template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007312ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007313TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007314 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007315 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007316 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007317 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007318
John McCallb3d87482010-08-24 05:47:05 +00007319 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007320 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007321 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007322 E->getOperatorLoc(),
7323 E->isArrow()? tok::arrow : tok::period,
7324 ObjectTypePtr,
7325 MayBePseudoDestructor);
7326 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007327 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007328
John McCallb3d87482010-08-24 05:47:05 +00007329 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007330 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7331 if (QualifierLoc) {
7332 QualifierLoc
7333 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7334 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007335 return ExprError();
7336 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007337 CXXScopeSpec SS;
7338 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007339
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007340 PseudoDestructorTypeStorage Destroyed;
7341 if (E->getDestroyedTypeInfo()) {
7342 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007343 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007344 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007345 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007346 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007347 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007348 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007349 // We aren't likely to be able to resolve the identifier down to a type
7350 // now anyway, so just retain the identifier.
7351 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7352 E->getDestroyedTypeLoc());
7353 } else {
7354 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007355 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007356 *E->getDestroyedTypeIdentifier(),
7357 E->getDestroyedTypeLoc(),
7358 /*Scope=*/0,
7359 SS, ObjectTypePtr,
7360 false);
7361 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007362 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007363
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007364 Destroyed
7365 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7366 E->getDestroyedTypeLoc());
7367 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007368
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007369 TypeSourceInfo *ScopeTypeInfo = 0;
7370 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007371 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007372 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007373 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007374 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007375
John McCall9ae2f072010-08-23 23:25:46 +00007376 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007377 E->getOperatorLoc(),
7378 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007379 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007380 ScopeTypeInfo,
7381 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007382 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007383 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007384}
Mike Stump1eb44332009-09-09 15:08:12 +00007385
Douglas Gregora71d8192009-09-04 17:36:40 +00007386template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007387ExprResult
John McCallba135432009-11-21 08:51:07 +00007388TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007389 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007390 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7391 Sema::LookupOrdinaryName);
7392
7393 // Transform all the decls.
7394 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7395 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007396 NamedDecl *InstD = static_cast<NamedDecl*>(
7397 getDerived().TransformDecl(Old->getNameLoc(),
7398 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007399 if (!InstD) {
7400 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7401 // This can happen because of dependent hiding.
7402 if (isa<UsingShadowDecl>(*I))
7403 continue;
7404 else
John McCallf312b1e2010-08-26 23:41:50 +00007405 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007406 }
John McCallf7a1a742009-11-24 19:00:30 +00007407
7408 // Expand using declarations.
7409 if (isa<UsingDecl>(InstD)) {
7410 UsingDecl *UD = cast<UsingDecl>(InstD);
7411 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7412 E = UD->shadow_end(); I != E; ++I)
7413 R.addDecl(*I);
7414 continue;
7415 }
7416
7417 R.addDecl(InstD);
7418 }
7419
7420 // Resolve a kind, but don't do any further analysis. If it's
7421 // ambiguous, the callee needs to deal with it.
7422 R.resolveKind();
7423
7424 // Rebuild the nested-name qualifier, if present.
7425 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007426 if (Old->getQualifierLoc()) {
7427 NestedNameSpecifierLoc QualifierLoc
7428 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7429 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007430 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007431
Douglas Gregor4c9be892011-02-28 20:01:57 +00007432 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007433 }
7434
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007435 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007436 CXXRecordDecl *NamingClass
7437 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7438 Old->getNameLoc(),
7439 Old->getNamingClass()));
7440 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007441 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007442
Douglas Gregor66c45152010-04-27 16:10:10 +00007443 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007444 }
7445
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007446 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7447
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007448 // If we have neither explicit template arguments, nor the template keyword,
7449 // it's a normal declaration name.
7450 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007451 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7452
7453 // If we have template arguments, rebuild them, then rebuild the
7454 // templateid expression.
7455 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007456 if (Old->hasExplicitTemplateArgs() &&
7457 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007458 Old->getNumTemplateArgs(),
7459 TransArgs))
7460 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007461
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007462 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007463 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007464}
Mike Stump1eb44332009-09-09 15:08:12 +00007465
Douglas Gregorb98b1992009-08-11 05:31:07 +00007466template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007467ExprResult
John McCall454feb92009-12-08 09:21:05 +00007468TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007469 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7470 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007471 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007472
Douglas Gregorb98b1992009-08-11 05:31:07 +00007473 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007474 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007475 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007476
Mike Stump1eb44332009-09-09 15:08:12 +00007477 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007478 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007479 T,
7480 E->getLocEnd());
7481}
Mike Stump1eb44332009-09-09 15:08:12 +00007482
Douglas Gregorb98b1992009-08-11 05:31:07 +00007483template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007484ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007485TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7486 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7487 if (!LhsT)
7488 return ExprError();
7489
7490 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7491 if (!RhsT)
7492 return ExprError();
7493
7494 if (!getDerived().AlwaysRebuild() &&
7495 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7496 return SemaRef.Owned(E);
7497
7498 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7499 E->getLocStart(),
7500 LhsT, RhsT,
7501 E->getLocEnd());
7502}
7503
7504template<typename Derived>
7505ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007506TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7507 bool ArgChanged = false;
7508 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7509 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7510 TypeSourceInfo *From = E->getArg(I);
7511 TypeLoc FromTL = From->getTypeLoc();
7512 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7513 TypeLocBuilder TLB;
7514 TLB.reserve(FromTL.getFullDataSize());
7515 QualType To = getDerived().TransformType(TLB, FromTL);
7516 if (To.isNull())
7517 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007518
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007519 if (To == From->getType())
7520 Args.push_back(From);
7521 else {
7522 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7523 ArgChanged = true;
7524 }
7525 continue;
7526 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007527
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007528 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007529
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007530 // We have a pack expansion. Instantiate it.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007531 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007532 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7533 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7534 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007535
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007536 // Determine whether the set of unexpanded parameter packs can and should
7537 // be expanded.
7538 bool Expand = true;
7539 bool RetainExpansion = false;
7540 llvm::Optional<unsigned> OrigNumExpansions
7541 = ExpansionTL.getTypePtr()->getNumExpansions();
7542 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7543 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7544 PatternTL.getSourceRange(),
7545 Unexpanded,
7546 Expand, RetainExpansion,
7547 NumExpansions))
7548 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007549
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007550 if (!Expand) {
7551 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007552 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007553 // expansion.
7554 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007555
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007556 TypeLocBuilder TLB;
7557 TLB.reserve(From->getTypeLoc().getFullDataSize());
7558
7559 QualType To = getDerived().TransformType(TLB, PatternTL);
7560 if (To.isNull())
7561 return ExprError();
7562
Chad Rosier4a9d7952012-08-08 18:46:20 +00007563 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007564 PatternTL.getSourceRange(),
7565 ExpansionTL.getEllipsisLoc(),
7566 NumExpansions);
7567 if (To.isNull())
7568 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007569
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007570 PackExpansionTypeLoc ToExpansionTL
7571 = TLB.push<PackExpansionTypeLoc>(To);
7572 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7573 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7574 continue;
7575 }
7576
7577 // Expand the pack expansion by substituting for each argument in the
7578 // pack(s).
7579 for (unsigned I = 0; I != *NumExpansions; ++I) {
7580 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7581 TypeLocBuilder TLB;
7582 TLB.reserve(PatternTL.getFullDataSize());
7583 QualType To = getDerived().TransformType(TLB, PatternTL);
7584 if (To.isNull())
7585 return ExprError();
7586
7587 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7588 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007589
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007590 if (!RetainExpansion)
7591 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007592
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007593 // If we're supposed to retain a pack expansion, do so by temporarily
7594 // forgetting the partially-substituted parameter pack.
7595 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7596
7597 TypeLocBuilder TLB;
7598 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007599
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007600 QualType To = getDerived().TransformType(TLB, PatternTL);
7601 if (To.isNull())
7602 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007603
7604 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007605 PatternTL.getSourceRange(),
7606 ExpansionTL.getEllipsisLoc(),
7607 NumExpansions);
7608 if (To.isNull())
7609 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007610
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007611 PackExpansionTypeLoc ToExpansionTL
7612 = TLB.push<PackExpansionTypeLoc>(To);
7613 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7614 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7615 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007616
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007617 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7618 return SemaRef.Owned(E);
7619
7620 return getDerived().RebuildTypeTrait(E->getTrait(),
7621 E->getLocStart(),
7622 Args,
7623 E->getLocEnd());
7624}
7625
7626template<typename Derived>
7627ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007628TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7629 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7630 if (!T)
7631 return ExprError();
7632
7633 if (!getDerived().AlwaysRebuild() &&
7634 T == E->getQueriedTypeSourceInfo())
7635 return SemaRef.Owned(E);
7636
7637 ExprResult SubExpr;
7638 {
7639 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7640 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7641 if (SubExpr.isInvalid())
7642 return ExprError();
7643
7644 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7645 return SemaRef.Owned(E);
7646 }
7647
7648 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7649 E->getLocStart(),
7650 T,
7651 SubExpr.get(),
7652 E->getLocEnd());
7653}
7654
7655template<typename Derived>
7656ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007657TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7658 ExprResult SubExpr;
7659 {
7660 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7661 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7662 if (SubExpr.isInvalid())
7663 return ExprError();
7664
7665 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7666 return SemaRef.Owned(E);
7667 }
7668
7669 return getDerived().RebuildExpressionTrait(
7670 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7671}
7672
7673template<typename Derived>
7674ExprResult
John McCall865d4472009-11-19 22:55:06 +00007675TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007676 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007677 NestedNameSpecifierLoc QualifierLoc
7678 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7679 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007680 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007681 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007682
John McCall43fed0d2010-11-12 08:19:04 +00007683 // TODO: If this is a conversion-function-id, verify that the
7684 // destination type name (if present) resolves the same way after
7685 // instantiation as it did in the local scope.
7686
Abramo Bagnara25777432010-08-11 22:01:17 +00007687 DeclarationNameInfo NameInfo
7688 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7689 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007690 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007691
John McCallf7a1a742009-11-24 19:00:30 +00007692 if (!E->hasExplicitTemplateArgs()) {
7693 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007694 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007695 // Note: it is sufficient to compare the Name component of NameInfo:
7696 // if name has not changed, DNLoc has not changed either.
7697 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007698 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007699
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007700 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007701 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007702 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007703 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007704 }
John McCalld5532b62009-11-23 01:53:49 +00007705
7706 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007707 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7708 E->getNumTemplateArgs(),
7709 TransArgs))
7710 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007711
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007712 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007713 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007714 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007715 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007716}
7717
7718template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007719ExprResult
John McCall454feb92009-12-08 09:21:05 +00007720TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007721 // CXXConstructExprs are always implicit, so when we have a
7722 // 1-argument construction we just transform that argument.
7723 if (E->getNumArgs() == 1 ||
7724 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7725 return getDerived().TransformExpr(E->getArg(0));
7726
Douglas Gregorb98b1992009-08-11 05:31:07 +00007727 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7728
7729 QualType T = getDerived().TransformType(E->getType());
7730 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007731 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007732
7733 CXXConstructorDecl *Constructor
7734 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007735 getDerived().TransformDecl(E->getLocStart(),
7736 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007737 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007738 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007739
Douglas Gregorb98b1992009-08-11 05:31:07 +00007740 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007741 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007742 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007743 &ArgumentChanged))
7744 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007745
Douglas Gregorb98b1992009-08-11 05:31:07 +00007746 if (!getDerived().AlwaysRebuild() &&
7747 T == E->getType() &&
7748 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007749 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007750 // Mark the constructor as referenced.
7751 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007752 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007753 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007754 }
Mike Stump1eb44332009-09-09 15:08:12 +00007755
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007756 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7757 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007758 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007759 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007760 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007761 E->getConstructionKind(),
7762 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007763}
Mike Stump1eb44332009-09-09 15:08:12 +00007764
Douglas Gregorb98b1992009-08-11 05:31:07 +00007765/// \brief Transform a C++ temporary-binding expression.
7766///
Douglas Gregor51326552009-12-24 18:51:59 +00007767/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7768/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007769template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007770ExprResult
John McCall454feb92009-12-08 09:21:05 +00007771TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007772 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007773}
Mike Stump1eb44332009-09-09 15:08:12 +00007774
John McCall4765fa02010-12-06 08:20:24 +00007775/// \brief Transform a C++ expression that contains cleanups that should
7776/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007777///
John McCall4765fa02010-12-06 08:20:24 +00007778/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007779/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007780template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007781ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007782TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007783 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007784}
Mike Stump1eb44332009-09-09 15:08:12 +00007785
Douglas Gregorb98b1992009-08-11 05:31:07 +00007786template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007787ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007788TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007789 CXXTemporaryObjectExpr *E) {
7790 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7791 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007792 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007793
Douglas Gregorb98b1992009-08-11 05:31:07 +00007794 CXXConstructorDecl *Constructor
7795 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007796 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007797 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007798 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007799 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007800
Douglas Gregorb98b1992009-08-11 05:31:07 +00007801 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007802 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007803 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007804 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007805 &ArgumentChanged))
7806 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007807
Douglas Gregorb98b1992009-08-11 05:31:07 +00007808 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007809 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007810 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007811 !ArgumentChanged) {
7812 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007813 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007814 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007815 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007816
Douglas Gregorab6677e2010-09-08 00:15:04 +00007817 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7818 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007819 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007820 E->getLocEnd());
7821}
Mike Stump1eb44332009-09-09 15:08:12 +00007822
Douglas Gregorb98b1992009-08-11 05:31:07 +00007823template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007824ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007825TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007826 // Transform the type of the lambda parameters and start the definition of
7827 // the lambda itself.
7828 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00007829 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00007830 if (!MethodTy)
7831 return ExprError();
7832
Eli Friedman8da8a662012-09-19 01:18:11 +00007833 // Create the local class that will describe the lambda.
7834 CXXRecordDecl *Class
7835 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7836 MethodTy,
7837 /*KnownDependent=*/false);
7838 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7839
Douglas Gregorc6889e72012-02-14 22:28:59 +00007840 // Transform lambda parameters.
Douglas Gregorc6889e72012-02-14 22:28:59 +00007841 llvm::SmallVector<QualType, 4> ParamTypes;
7842 llvm::SmallVector<ParmVarDecl *, 4> Params;
7843 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7844 E->getCallOperator()->param_begin(),
7845 E->getCallOperator()->param_size(),
7846 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00007847 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00007848
Douglas Gregordfca6f52012-02-13 22:00:16 +00007849 // Build the call operator.
7850 CXXMethodDecl *CallOperator
7851 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007852 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007853 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007854 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007855 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00007856
Richard Smith612409e2012-07-25 03:56:55 +00007857 return getDerived().TransformLambdaScope(E, CallOperator);
7858}
7859
7860template<typename Derived>
7861ExprResult
7862TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
7863 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00007864 // Introduce the context of the call operator.
7865 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7866
Douglas Gregordfca6f52012-02-13 22:00:16 +00007867 // Enter the scope of the lambda.
7868 sema::LambdaScopeInfo *LSI
7869 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7870 E->getCaptureDefault(),
7871 E->hasExplicitParameters(),
7872 E->hasExplicitResultType(),
7873 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007874
Douglas Gregordfca6f52012-02-13 22:00:16 +00007875 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00007876 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00007877 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007878 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007879 CEnd = E->capture_end();
7880 C != CEnd; ++C) {
7881 // When we hit the first implicit capture, tell Sema that we've finished
7882 // the list of explicit captures.
7883 if (!FinishedExplicitCaptures && C->isImplicit()) {
7884 getSema().finishLambdaExplicitCaptures(LSI);
7885 FinishedExplicitCaptures = true;
7886 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007887
Douglas Gregordfca6f52012-02-13 22:00:16 +00007888 // Capturing 'this' is trivial.
7889 if (C->capturesThis()) {
7890 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7891 continue;
7892 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007893
Douglas Gregora7365242012-02-14 19:27:52 +00007894 // Determine the capture kind for Sema.
7895 Sema::TryCaptureKind Kind
7896 = C->isImplicit()? Sema::TryCapture_Implicit
7897 : C->getCaptureKind() == LCK_ByCopy
7898 ? Sema::TryCapture_ExplicitByVal
7899 : Sema::TryCapture_ExplicitByRef;
7900 SourceLocation EllipsisLoc;
7901 if (C->isPackExpansion()) {
7902 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7903 bool ShouldExpand = false;
7904 bool RetainExpansion = false;
7905 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007906 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7907 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00007908 Unexpanded,
7909 ShouldExpand, RetainExpansion,
7910 NumExpansions))
7911 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007912
Douglas Gregora7365242012-02-14 19:27:52 +00007913 if (ShouldExpand) {
7914 // The transform has determined that we should perform an expansion;
7915 // transform and capture each of the arguments.
7916 // expansion of the pattern. Do so.
7917 VarDecl *Pack = C->getCapturedVar();
7918 for (unsigned I = 0; I != *NumExpansions; ++I) {
7919 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7920 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00007921 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00007922 Pack));
7923 if (!CapturedVar) {
7924 Invalid = true;
7925 continue;
7926 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007927
Douglas Gregora7365242012-02-14 19:27:52 +00007928 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007929 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
7930 }
Douglas Gregora7365242012-02-14 19:27:52 +00007931 continue;
7932 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007933
Douglas Gregora7365242012-02-14 19:27:52 +00007934 EllipsisLoc = C->getEllipsisLoc();
7935 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007936
Douglas Gregordfca6f52012-02-13 22:00:16 +00007937 // Transform the captured variable.
7938 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00007939 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007940 C->getCapturedVar()));
7941 if (!CapturedVar) {
7942 Invalid = true;
7943 continue;
7944 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007945
Douglas Gregordfca6f52012-02-13 22:00:16 +00007946 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007947 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007948 }
7949 if (!FinishedExplicitCaptures)
7950 getSema().finishLambdaExplicitCaptures(LSI);
7951
Douglas Gregordfca6f52012-02-13 22:00:16 +00007952
7953 // Enter a new evaluation context to insulate the lambda from any
7954 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007955 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007956
7957 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007958 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00007959 /*IsInstantiation=*/true);
7960 return ExprError();
7961 }
7962
7963 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00007964 StmtResult Body = getDerived().TransformStmt(E->getBody());
7965 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007966 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00007967 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007968 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00007969 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00007970
Chad Rosier4a9d7952012-08-08 18:46:20 +00007971 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00007972 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00007973}
7974
7975template<typename Derived>
7976ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007977TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007978 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007979 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7980 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007981 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007982
Douglas Gregorb98b1992009-08-11 05:31:07 +00007983 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007984 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00007985 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007986 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007987 &ArgumentChanged))
7988 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007989
Douglas Gregorb98b1992009-08-11 05:31:07 +00007990 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007991 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007992 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007993 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007994
Douglas Gregorb98b1992009-08-11 05:31:07 +00007995 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007996 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007997 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007998 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007999 E->getRParenLoc());
8000}
Mike Stump1eb44332009-09-09 15:08:12 +00008001
Douglas Gregorb98b1992009-08-11 05:31:07 +00008002template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008003ExprResult
John McCall865d4472009-11-19 22:55:06 +00008004TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008005 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008006 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008007 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008008 Expr *OldBase;
8009 QualType BaseType;
8010 QualType ObjectType;
8011 if (!E->isImplicitAccess()) {
8012 OldBase = E->getBase();
8013 Base = getDerived().TransformExpr(OldBase);
8014 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008015 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008016
John McCallaa81e162009-12-01 22:10:20 +00008017 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008018 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008019 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008020 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008021 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008022 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008023 ObjectTy,
8024 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008025 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008026 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008027
John McCallb3d87482010-08-24 05:47:05 +00008028 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008029 BaseType = ((Expr*) Base.get())->getType();
8030 } else {
8031 OldBase = 0;
8032 BaseType = getDerived().TransformType(E->getBaseType());
8033 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8034 }
Mike Stump1eb44332009-09-09 15:08:12 +00008035
Douglas Gregor6cd21982009-10-20 05:58:46 +00008036 // Transform the first part of the nested-name-specifier that qualifies
8037 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008038 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008039 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008040 E->getFirstQualifierFoundInScope(),
8041 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008042
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008043 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008044 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008045 QualifierLoc
8046 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8047 ObjectType,
8048 FirstQualifierInScope);
8049 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008050 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008051 }
Mike Stump1eb44332009-09-09 15:08:12 +00008052
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008053 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8054
John McCall43fed0d2010-11-12 08:19:04 +00008055 // TODO: If this is a conversion-function-id, verify that the
8056 // destination type name (if present) resolves the same way after
8057 // instantiation as it did in the local scope.
8058
Abramo Bagnara25777432010-08-11 22:01:17 +00008059 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008060 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008061 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008062 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008063
John McCallaa81e162009-12-01 22:10:20 +00008064 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008065 // This is a reference to a member without an explicitly-specified
8066 // template argument list. Optimize for this common case.
8067 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008068 Base.get() == OldBase &&
8069 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008070 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008071 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008072 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008073 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008074
John McCall9ae2f072010-08-23 23:25:46 +00008075 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008076 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008077 E->isArrow(),
8078 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008079 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008080 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008081 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008082 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008083 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008084 }
8085
John McCalld5532b62009-11-23 01:53:49 +00008086 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008087 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8088 E->getNumTemplateArgs(),
8089 TransArgs))
8090 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008091
John McCall9ae2f072010-08-23 23:25:46 +00008092 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008093 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008094 E->isArrow(),
8095 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008096 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008097 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008098 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008099 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008100 &TransArgs);
8101}
8102
8103template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008104ExprResult
John McCall454feb92009-12-08 09:21:05 +00008105TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008106 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008107 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008108 QualType BaseType;
8109 if (!Old->isImplicitAccess()) {
8110 Base = getDerived().TransformExpr(Old->getBase());
8111 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008112 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008113 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8114 Old->isArrow());
8115 if (Base.isInvalid())
8116 return ExprError();
8117 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008118 } else {
8119 BaseType = getDerived().TransformType(Old->getBaseType());
8120 }
John McCall129e2df2009-11-30 22:42:35 +00008121
Douglas Gregor4c9be892011-02-28 20:01:57 +00008122 NestedNameSpecifierLoc QualifierLoc;
8123 if (Old->getQualifierLoc()) {
8124 QualifierLoc
8125 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8126 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008127 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008128 }
8129
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008130 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8131
Abramo Bagnara25777432010-08-11 22:01:17 +00008132 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008133 Sema::LookupOrdinaryName);
8134
8135 // Transform all the decls.
8136 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8137 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008138 NamedDecl *InstD = static_cast<NamedDecl*>(
8139 getDerived().TransformDecl(Old->getMemberLoc(),
8140 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008141 if (!InstD) {
8142 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8143 // This can happen because of dependent hiding.
8144 if (isa<UsingShadowDecl>(*I))
8145 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008146 else {
8147 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008148 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008149 }
John McCall9f54ad42009-12-10 09:41:52 +00008150 }
John McCall129e2df2009-11-30 22:42:35 +00008151
8152 // Expand using declarations.
8153 if (isa<UsingDecl>(InstD)) {
8154 UsingDecl *UD = cast<UsingDecl>(InstD);
8155 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8156 E = UD->shadow_end(); I != E; ++I)
8157 R.addDecl(*I);
8158 continue;
8159 }
8160
8161 R.addDecl(InstD);
8162 }
8163
8164 R.resolveKind();
8165
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008166 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008167 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008168 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008169 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008170 Old->getMemberLoc(),
8171 Old->getNamingClass()));
8172 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008173 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008174
Douglas Gregor66c45152010-04-27 16:10:10 +00008175 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008176 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008177
John McCall129e2df2009-11-30 22:42:35 +00008178 TemplateArgumentListInfo TransArgs;
8179 if (Old->hasExplicitTemplateArgs()) {
8180 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8181 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008182 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8183 Old->getNumTemplateArgs(),
8184 TransArgs))
8185 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008186 }
John McCallc2233c52010-01-15 08:34:02 +00008187
8188 // FIXME: to do this check properly, we will need to preserve the
8189 // first-qualifier-in-scope here, just in case we had a dependent
8190 // base (and therefore couldn't do the check) and a
8191 // nested-name-qualifier (and therefore could do the lookup).
8192 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008193
John McCall9ae2f072010-08-23 23:25:46 +00008194 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008195 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008196 Old->getOperatorLoc(),
8197 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008198 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008199 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008200 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008201 R,
8202 (Old->hasExplicitTemplateArgs()
8203 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008204}
8205
8206template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008207ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008208TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008209 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008210 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8211 if (SubExpr.isInvalid())
8212 return ExprError();
8213
8214 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008215 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008216
8217 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8218}
8219
8220template<typename Derived>
8221ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008222TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008223 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8224 if (Pattern.isInvalid())
8225 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008226
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008227 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8228 return SemaRef.Owned(E);
8229
Douglas Gregor67fd1252011-01-14 21:20:45 +00008230 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8231 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008232}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008233
8234template<typename Derived>
8235ExprResult
8236TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8237 // If E is not value-dependent, then nothing will change when we transform it.
8238 // Note: This is an instantiation-centric view.
8239 if (!E->isValueDependent())
8240 return SemaRef.Owned(E);
8241
8242 // Note: None of the implementations of TryExpandParameterPacks can ever
8243 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008244 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008245 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8246 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008247 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008248 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008249 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008250 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008251 ShouldExpand, RetainExpansion,
8252 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008253 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008254
Douglas Gregor089e8932011-10-10 18:59:29 +00008255 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008256 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008257
Douglas Gregor089e8932011-10-10 18:59:29 +00008258 NamedDecl *Pack = E->getPack();
8259 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008260 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008261 Pack));
8262 if (!Pack)
8263 return ExprError();
8264 }
8265
Chad Rosier4a9d7952012-08-08 18:46:20 +00008266
Douglas Gregoree8aff02011-01-04 17:33:58 +00008267 // We now know the length of the parameter pack, so build a new expression
8268 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008269 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8270 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008271 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008272}
8273
Douglas Gregorbe230c32011-01-03 17:17:50 +00008274template<typename Derived>
8275ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008276TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8277 SubstNonTypeTemplateParmPackExpr *E) {
8278 // Default behavior is to do nothing with this transformation.
8279 return SemaRef.Owned(E);
8280}
8281
8282template<typename Derived>
8283ExprResult
John McCall91a57552011-07-15 05:09:51 +00008284TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8285 SubstNonTypeTemplateParmExpr *E) {
8286 // Default behavior is to do nothing with this transformation.
8287 return SemaRef.Owned(E);
8288}
8289
8290template<typename Derived>
8291ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008292TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8293 // Default behavior is to do nothing with this transformation.
8294 return SemaRef.Owned(E);
8295}
8296
8297template<typename Derived>
8298ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008299TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8300 MaterializeTemporaryExpr *E) {
8301 return getDerived().TransformExpr(E->GetTemporaryExpr());
8302}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008303
Douglas Gregor03e80032011-06-21 17:03:29 +00008304template<typename Derived>
8305ExprResult
John McCall454feb92009-12-08 09:21:05 +00008306TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008307 return SemaRef.MaybeBindToTemporary(E);
8308}
8309
8310template<typename Derived>
8311ExprResult
8312TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008313 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008314}
8315
8316template<typename Derived>
8317ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008318TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8319 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8320 if (SubExpr.isInvalid())
8321 return ExprError();
8322
8323 if (!getDerived().AlwaysRebuild() &&
8324 SubExpr.get() == E->getSubExpr())
8325 return SemaRef.Owned(E);
8326
8327 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008328}
8329
8330template<typename Derived>
8331ExprResult
8332TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8333 // Transform each of the elements.
8334 llvm::SmallVector<Expr *, 8> Elements;
8335 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008336 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008337 /*IsCall=*/false, Elements, &ArgChanged))
8338 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008339
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008340 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8341 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008342
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008343 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8344 Elements.data(),
8345 Elements.size());
8346}
8347
8348template<typename Derived>
8349ExprResult
8350TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008351 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008352 // Transform each of the elements.
8353 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8354 bool ArgChanged = false;
8355 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8356 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008357
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008358 if (OrigElement.isPackExpansion()) {
8359 // This key/value element is a pack expansion.
8360 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8361 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8362 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8363 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8364
8365 // Determine whether the set of unexpanded parameter packs can
8366 // and should be expanded.
8367 bool Expand = true;
8368 bool RetainExpansion = false;
8369 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8370 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8371 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8372 OrigElement.Value->getLocEnd());
8373 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8374 PatternRange,
8375 Unexpanded,
8376 Expand, RetainExpansion,
8377 NumExpansions))
8378 return ExprError();
8379
8380 if (!Expand) {
8381 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008382 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008383 // expansion.
8384 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8385 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8386 if (Key.isInvalid())
8387 return ExprError();
8388
8389 if (Key.get() != OrigElement.Key)
8390 ArgChanged = true;
8391
8392 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8393 if (Value.isInvalid())
8394 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008395
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008396 if (Value.get() != OrigElement.Value)
8397 ArgChanged = true;
8398
Chad Rosier4a9d7952012-08-08 18:46:20 +00008399 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008400 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8401 };
8402 Elements.push_back(Expansion);
8403 continue;
8404 }
8405
8406 // Record right away that the argument was changed. This needs
8407 // to happen even if the array expands to nothing.
8408 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008409
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008410 // The transform has determined that we should perform an elementwise
8411 // expansion of the pattern. Do so.
8412 for (unsigned I = 0; I != *NumExpansions; ++I) {
8413 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8414 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8415 if (Key.isInvalid())
8416 return ExprError();
8417
8418 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8419 if (Value.isInvalid())
8420 return ExprError();
8421
Chad Rosier4a9d7952012-08-08 18:46:20 +00008422 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008423 Key.get(), Value.get(), SourceLocation(), NumExpansions
8424 };
8425
8426 // If any unexpanded parameter packs remain, we still have a
8427 // pack expansion.
8428 if (Key.get()->containsUnexpandedParameterPack() ||
8429 Value.get()->containsUnexpandedParameterPack())
8430 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008431
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008432 Elements.push_back(Element);
8433 }
8434
8435 // We've finished with this pack expansion.
8436 continue;
8437 }
8438
8439 // Transform and check key.
8440 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8441 if (Key.isInvalid())
8442 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008443
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008444 if (Key.get() != OrigElement.Key)
8445 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008446
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008447 // Transform and check value.
8448 ExprResult Value
8449 = getDerived().TransformExpr(OrigElement.Value);
8450 if (Value.isInvalid())
8451 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008452
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008453 if (Value.get() != OrigElement.Value)
8454 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008455
8456 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008457 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8458 };
8459 Elements.push_back(Element);
8460 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008461
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008462 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8463 return SemaRef.MaybeBindToTemporary(E);
8464
8465 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8466 Elements.data(),
8467 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008468}
8469
Mike Stump1eb44332009-09-09 15:08:12 +00008470template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008471ExprResult
John McCall454feb92009-12-08 09:21:05 +00008472TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008473 TypeSourceInfo *EncodedTypeInfo
8474 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8475 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008476 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008477
Douglas Gregorb98b1992009-08-11 05:31:07 +00008478 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008479 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008480 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008481
8482 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008483 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008484 E->getRParenLoc());
8485}
Mike Stump1eb44332009-09-09 15:08:12 +00008486
Douglas Gregorb98b1992009-08-11 05:31:07 +00008487template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008488ExprResult TreeTransform<Derived>::
8489TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8490 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8491 if (result.isInvalid()) return ExprError();
8492 Expr *subExpr = result.take();
8493
8494 if (!getDerived().AlwaysRebuild() &&
8495 subExpr == E->getSubExpr())
8496 return SemaRef.Owned(E);
8497
8498 return SemaRef.Owned(new(SemaRef.Context)
8499 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8500}
8501
8502template<typename Derived>
8503ExprResult TreeTransform<Derived>::
8504TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008505 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008506 = getDerived().TransformType(E->getTypeInfoAsWritten());
8507 if (!TSInfo)
8508 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008509
John McCallf85e1932011-06-15 23:02:42 +00008510 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008511 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008512 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008513
John McCallf85e1932011-06-15 23:02:42 +00008514 if (!getDerived().AlwaysRebuild() &&
8515 TSInfo == E->getTypeInfoAsWritten() &&
8516 Result.get() == E->getSubExpr())
8517 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008518
John McCallf85e1932011-06-15 23:02:42 +00008519 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008520 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008521 Result.get());
8522}
8523
8524template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008525ExprResult
John McCall454feb92009-12-08 09:21:05 +00008526TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008527 // Transform arguments.
8528 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008529 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008530 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008531 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008532 &ArgChanged))
8533 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008534
Douglas Gregor92e986e2010-04-22 16:44:27 +00008535 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8536 // Class message: transform the receiver type.
8537 TypeSourceInfo *ReceiverTypeInfo
8538 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8539 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008540 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008541
Douglas Gregor92e986e2010-04-22 16:44:27 +00008542 // If nothing changed, just retain the existing message send.
8543 if (!getDerived().AlwaysRebuild() &&
8544 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008545 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008546
8547 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008548 SmallVector<SourceLocation, 16> SelLocs;
8549 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008550 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8551 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008552 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008553 E->getMethodDecl(),
8554 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008555 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008556 E->getRightLoc());
8557 }
8558
8559 // Instance message: transform the receiver
8560 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8561 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008562 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008563 = getDerived().TransformExpr(E->getInstanceReceiver());
8564 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008565 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008566
8567 // If nothing changed, just retain the existing message send.
8568 if (!getDerived().AlwaysRebuild() &&
8569 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008570 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008571
Douglas Gregor92e986e2010-04-22 16:44:27 +00008572 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008573 SmallVector<SourceLocation, 16> SelLocs;
8574 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008575 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008576 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008577 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008578 E->getMethodDecl(),
8579 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008580 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008581 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008582}
8583
Mike Stump1eb44332009-09-09 15:08:12 +00008584template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008585ExprResult
John McCall454feb92009-12-08 09:21:05 +00008586TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008587 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008588}
8589
Mike Stump1eb44332009-09-09 15:08:12 +00008590template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008591ExprResult
John McCall454feb92009-12-08 09:21:05 +00008592TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008593 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008594}
8595
Mike Stump1eb44332009-09-09 15:08:12 +00008596template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008597ExprResult
John McCall454feb92009-12-08 09:21:05 +00008598TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008599 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008600 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008601 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008602 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008603
8604 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008605
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008606 // If nothing changed, just retain the existing expression.
8607 if (!getDerived().AlwaysRebuild() &&
8608 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008609 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008610
John McCall9ae2f072010-08-23 23:25:46 +00008611 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008612 E->getLocation(),
8613 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008614}
8615
Mike Stump1eb44332009-09-09 15:08:12 +00008616template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008617ExprResult
John McCall454feb92009-12-08 09:21:05 +00008618TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008619 // 'super' and types never change. Property never changes. Just
8620 // retain the existing expression.
8621 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008622 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008623
Douglas Gregore3303542010-04-26 20:47:02 +00008624 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008625 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008626 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008627 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008628
Douglas Gregore3303542010-04-26 20:47:02 +00008629 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008630
Douglas Gregore3303542010-04-26 20:47:02 +00008631 // If nothing changed, just retain the existing expression.
8632 if (!getDerived().AlwaysRebuild() &&
8633 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008634 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008635
John McCall12f78a62010-12-02 01:19:52 +00008636 if (E->isExplicitProperty())
8637 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8638 E->getExplicitProperty(),
8639 E->getLocation());
8640
8641 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008642 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008643 E->getImplicitPropertyGetter(),
8644 E->getImplicitPropertySetter(),
8645 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008646}
8647
Mike Stump1eb44332009-09-09 15:08:12 +00008648template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008649ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008650TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8651 // Transform the base expression.
8652 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8653 if (Base.isInvalid())
8654 return ExprError();
8655
8656 // Transform the key expression.
8657 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8658 if (Key.isInvalid())
8659 return ExprError();
8660
8661 // If nothing changed, just retain the existing expression.
8662 if (!getDerived().AlwaysRebuild() &&
8663 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8664 return SemaRef.Owned(E);
8665
Chad Rosier4a9d7952012-08-08 18:46:20 +00008666 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008667 Base.get(), Key.get(),
8668 E->getAtIndexMethodDecl(),
8669 E->setAtIndexMethodDecl());
8670}
8671
8672template<typename Derived>
8673ExprResult
John McCall454feb92009-12-08 09:21:05 +00008674TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008675 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008676 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008677 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008678 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008679
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008680 // If nothing changed, just retain the existing expression.
8681 if (!getDerived().AlwaysRebuild() &&
8682 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008683 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008684
John McCall9ae2f072010-08-23 23:25:46 +00008685 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008686 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008687}
8688
Mike Stump1eb44332009-09-09 15:08:12 +00008689template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008690ExprResult
John McCall454feb92009-12-08 09:21:05 +00008691TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008692 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008693 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008694 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008695 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008696 SubExprs, &ArgumentChanged))
8697 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008698
Douglas Gregorb98b1992009-08-11 05:31:07 +00008699 if (!getDerived().AlwaysRebuild() &&
8700 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008701 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008702
Douglas Gregorb98b1992009-08-11 05:31:07 +00008703 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008704 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008705 E->getRParenLoc());
8706}
8707
Mike Stump1eb44332009-09-09 15:08:12 +00008708template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008709ExprResult
John McCall454feb92009-12-08 09:21:05 +00008710TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008711 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008712
John McCallc6ac9c32011-02-04 18:33:18 +00008713 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8714 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8715
8716 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008717 blockScope->TheDecl->setBlockMissingReturnType(
8718 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008719
Chris Lattner686775d2011-07-20 06:58:45 +00008720 SmallVector<ParmVarDecl*, 4> params;
8721 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008722
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008723 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008724 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8725 oldBlock->param_begin(),
8726 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008727 0, paramTypes, &params)) {
8728 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008729 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008730 }
John McCallc6ac9c32011-02-04 18:33:18 +00008731
8732 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008733 QualType exprResultType =
8734 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008735
8736 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008737 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008738 getSema().Diag(E->getCaretLocation(),
8739 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008740 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008741 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008742 return ExprError();
8743 }
John McCall711c52b2011-01-05 12:14:39 +00008744
John McCallc6ac9c32011-02-04 18:33:18 +00008745 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008746 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008747 paramTypes.data(),
8748 paramTypes.size(),
8749 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008750 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008751 exprFunctionType->getExtInfo());
8752 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008753
8754 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008755 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008756 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008757
8758 if (!oldBlock->blockMissingReturnType()) {
8759 blockScope->HasImplicitReturnType = false;
8760 blockScope->ReturnType = exprResultType;
8761 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008762
John McCall711c52b2011-01-05 12:14:39 +00008763 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008764 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008765 if (body.isInvalid()) {
8766 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008767 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008768 }
John McCall711c52b2011-01-05 12:14:39 +00008769
John McCallc6ac9c32011-02-04 18:33:18 +00008770#ifndef NDEBUG
8771 // In builds with assertions, make sure that we captured everything we
8772 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008773 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8774 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8775 e = oldBlock->capture_end(); i != e; ++i) {
8776 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008777
Douglas Gregorfc921372011-05-20 15:32:55 +00008778 // Ignore parameter packs.
8779 if (isa<ParmVarDecl>(oldCapture) &&
8780 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8781 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008782
Douglas Gregorfc921372011-05-20 15:32:55 +00008783 VarDecl *newCapture =
8784 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8785 oldCapture));
8786 assert(blockScope->CaptureMap.count(newCapture));
8787 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008788 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008789 }
8790#endif
8791
8792 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8793 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008794}
8795
Mike Stump1eb44332009-09-09 15:08:12 +00008796template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008797ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008798TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008799 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008800}
Eli Friedman276b0612011-10-11 02:20:01 +00008801
8802template<typename Derived>
8803ExprResult
8804TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008805 QualType RetTy = getDerived().TransformType(E->getType());
8806 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008807 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008808 SubExprs.reserve(E->getNumSubExprs());
8809 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8810 SubExprs, &ArgumentChanged))
8811 return ExprError();
8812
8813 if (!getDerived().AlwaysRebuild() &&
8814 !ArgumentChanged)
8815 return SemaRef.Owned(E);
8816
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008817 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008818 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008819}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008820
Douglas Gregorb98b1992009-08-11 05:31:07 +00008821//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008822// Type reconstruction
8823//===----------------------------------------------------------------------===//
8824
Mike Stump1eb44332009-09-09 15:08:12 +00008825template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008826QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8827 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008828 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008829 getDerived().getBaseEntity());
8830}
8831
Mike Stump1eb44332009-09-09 15:08:12 +00008832template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008833QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8834 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008835 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008836 getDerived().getBaseEntity());
8837}
8838
Mike Stump1eb44332009-09-09 15:08:12 +00008839template<typename Derived>
8840QualType
John McCall85737a72009-10-30 00:06:24 +00008841TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8842 bool WrittenAsLValue,
8843 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008844 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008845 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008846}
8847
8848template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008849QualType
John McCall85737a72009-10-30 00:06:24 +00008850TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8851 QualType ClassType,
8852 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008853 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008854 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008855}
8856
8857template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008858QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008859TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8860 ArrayType::ArraySizeModifier SizeMod,
8861 const llvm::APInt *Size,
8862 Expr *SizeExpr,
8863 unsigned IndexTypeQuals,
8864 SourceRange BracketsRange) {
8865 if (SizeExpr || !Size)
8866 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8867 IndexTypeQuals, BracketsRange,
8868 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008869
8870 QualType Types[] = {
8871 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8872 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8873 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008874 };
8875 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8876 QualType SizeType;
8877 for (unsigned I = 0; I != NumTypes; ++I)
8878 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8879 SizeType = Types[I];
8880 break;
8881 }
Mike Stump1eb44332009-09-09 15:08:12 +00008882
Eli Friedman01f276d2012-01-25 23:20:27 +00008883 // Note that we can return a VariableArrayType here in the case where
8884 // the element type was a dependent VariableArrayType.
8885 IntegerLiteral *ArraySize
8886 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8887 /*FIXME*/BracketsRange.getBegin());
8888 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008889 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008890 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008891}
Mike Stump1eb44332009-09-09 15:08:12 +00008892
Douglas Gregor577f75a2009-08-04 16:50:30 +00008893template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008894QualType
8895TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008896 ArrayType::ArraySizeModifier SizeMod,
8897 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008898 unsigned IndexTypeQuals,
8899 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008900 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008901 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008902}
8903
8904template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008905QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008906TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008907 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008908 unsigned IndexTypeQuals,
8909 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008910 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008911 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008912}
Mike Stump1eb44332009-09-09 15:08:12 +00008913
Douglas Gregor577f75a2009-08-04 16:50:30 +00008914template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008915QualType
8916TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008917 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008918 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008919 unsigned IndexTypeQuals,
8920 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008921 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008922 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008923 IndexTypeQuals, BracketsRange);
8924}
8925
8926template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008927QualType
8928TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008929 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008930 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008931 unsigned IndexTypeQuals,
8932 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008933 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008934 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008935 IndexTypeQuals, BracketsRange);
8936}
8937
8938template<typename Derived>
8939QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008940 unsigned NumElements,
8941 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008942 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008943 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008944}
Mike Stump1eb44332009-09-09 15:08:12 +00008945
Douglas Gregor577f75a2009-08-04 16:50:30 +00008946template<typename Derived>
8947QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8948 unsigned NumElements,
8949 SourceLocation AttributeLoc) {
8950 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8951 NumElements, true);
8952 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008953 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8954 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008955 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008956}
Mike Stump1eb44332009-09-09 15:08:12 +00008957
Douglas Gregor577f75a2009-08-04 16:50:30 +00008958template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008959QualType
8960TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008961 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008962 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008963 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008964}
Mike Stump1eb44332009-09-09 15:08:12 +00008965
Douglas Gregor577f75a2009-08-04 16:50:30 +00008966template<typename Derived>
8967QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008968 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008969 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008970 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008971 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00008972 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008973 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008974 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008975 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008976 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008977 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008978 getDerived().getBaseEntity(),
8979 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008980}
Mike Stump1eb44332009-09-09 15:08:12 +00008981
Douglas Gregor577f75a2009-08-04 16:50:30 +00008982template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008983QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8984 return SemaRef.Context.getFunctionNoProtoType(T);
8985}
8986
8987template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008988QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8989 assert(D && "no decl found");
8990 if (D->isInvalidDecl()) return QualType();
8991
Douglas Gregor92e986e2010-04-22 16:44:27 +00008992 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008993 TypeDecl *Ty;
8994 if (isa<UsingDecl>(D)) {
8995 UsingDecl *Using = cast<UsingDecl>(D);
8996 assert(Using->isTypeName() &&
8997 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8998
8999 // A valid resolved using typename decl points to exactly one type decl.
9000 assert(++Using->shadow_begin() == Using->shadow_end());
9001 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009002
John McCalled976492009-12-04 22:46:56 +00009003 } else {
9004 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9005 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9006 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9007 }
9008
9009 return SemaRef.Context.getTypeDeclType(Ty);
9010}
9011
9012template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009013QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9014 SourceLocation Loc) {
9015 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009016}
9017
9018template<typename Derived>
9019QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9020 return SemaRef.Context.getTypeOfType(Underlying);
9021}
9022
9023template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009024QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9025 SourceLocation Loc) {
9026 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009027}
9028
9029template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009030QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9031 UnaryTransformType::UTTKind UKind,
9032 SourceLocation Loc) {
9033 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9034}
9035
9036template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009037QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009038 TemplateName Template,
9039 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009040 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009041 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009042}
Mike Stump1eb44332009-09-09 15:08:12 +00009043
Douglas Gregordcee1a12009-08-06 05:28:30 +00009044template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009045QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9046 SourceLocation KWLoc) {
9047 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9048}
9049
9050template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009051TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009052TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009053 bool TemplateKW,
9054 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009055 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009056 Template);
9057}
9058
9059template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009060TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009061TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9062 const IdentifierInfo &Name,
9063 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009064 QualType ObjectType,
9065 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009066 UnqualifiedId TemplateName;
9067 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009068 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009069 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009070 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009071 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009072 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009073 /*EnteringContext=*/false,
9074 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009075 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009076}
Mike Stump1eb44332009-09-09 15:08:12 +00009077
Douglas Gregorb98b1992009-08-11 05:31:07 +00009078template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009079TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009080TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009081 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009082 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009083 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009084 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009085 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009086 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009087 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009088 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009089 Sema::TemplateTy Template;
9090 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009091 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009092 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009093 /*EnteringContext=*/false,
9094 Template);
9095 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009096}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009097
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009098template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009099ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009100TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9101 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009102 Expr *OrigCallee,
9103 Expr *First,
9104 Expr *Second) {
9105 Expr *Callee = OrigCallee->IgnoreParenCasts();
9106 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009107
Douglas Gregorb98b1992009-08-11 05:31:07 +00009108 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009109 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009110 if (!First->getType()->isOverloadableType() &&
9111 !Second->getType()->isOverloadableType())
9112 return getSema().CreateBuiltinArraySubscriptExpr(First,
9113 Callee->getLocStart(),
9114 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009115 } else if (Op == OO_Arrow) {
9116 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009117 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9118 } else if (Second == 0 || isPostIncDec) {
9119 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009120 // The argument is not of overloadable type, so try to create a
9121 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009122 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009123 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009124
John McCall9ae2f072010-08-23 23:25:46 +00009125 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009126 }
9127 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009128 if (!First->getType()->isOverloadableType() &&
9129 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009130 // Neither of the arguments is an overloadable type, so try to
9131 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009132 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009133 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009134 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009135 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009136 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009137
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009138 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009139 }
9140 }
Mike Stump1eb44332009-09-09 15:08:12 +00009141
9142 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009143 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009144 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009145
John McCall9ae2f072010-08-23 23:25:46 +00009146 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009147 assert(ULE->requiresADL());
9148
9149 // FIXME: Do we have to check
9150 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009151 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009152 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009153 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00009154 }
Mike Stump1eb44332009-09-09 15:08:12 +00009155
Douglas Gregorb98b1992009-08-11 05:31:07 +00009156 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009157 Expr *Args[2] = { First, Second };
9158 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009159
Douglas Gregorb98b1992009-08-11 05:31:07 +00009160 // Create the overloaded operator invocation for unary operators.
9161 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009162 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009163 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009164 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009165 }
Mike Stump1eb44332009-09-09 15:08:12 +00009166
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009167 if (Op == OO_Subscript) {
9168 SourceLocation LBrace;
9169 SourceLocation RBrace;
9170
9171 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9172 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9173 LBrace = SourceLocation::getFromRawEncoding(
9174 NameLoc.CXXOperatorName.BeginOpNameLoc);
9175 RBrace = SourceLocation::getFromRawEncoding(
9176 NameLoc.CXXOperatorName.EndOpNameLoc);
9177 } else {
9178 LBrace = Callee->getLocStart();
9179 RBrace = OpLoc;
9180 }
9181
9182 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9183 First, Second);
9184 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009185
Douglas Gregorb98b1992009-08-11 05:31:07 +00009186 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009187 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009188 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009189 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9190 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009191 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009192
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009193 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009194}
Mike Stump1eb44332009-09-09 15:08:12 +00009195
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009196template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009197ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009198TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009199 SourceLocation OperatorLoc,
9200 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009201 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009202 TypeSourceInfo *ScopeType,
9203 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009204 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009205 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009206 QualType BaseType = Base->getType();
9207 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009208 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009209 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009210 !BaseType->getAs<PointerType>()->getPointeeType()
9211 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009212 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009213 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009214 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009215 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009216 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009217 /*FIXME?*/true);
9218 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009219
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009220 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009221 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9222 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9223 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9224 NameInfo.setNamedTypeInfo(DestroyedType);
9225
Richard Smith6314db92012-05-15 06:15:11 +00009226 // The scope type is now known to be a valid nested name specifier
9227 // component. Tack it on to the end of the nested name specifier.
9228 if (ScopeType)
9229 SS.Extend(SemaRef.Context, SourceLocation(),
9230 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009231
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009232 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009233 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009234 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009235 SS, TemplateKWLoc,
9236 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009237 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009238 /*TemplateArgs*/ 0);
9239}
9240
Douglas Gregor577f75a2009-08-04 16:50:30 +00009241} // end namespace clang
9242
9243#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H