blob: af4f0a47fb33ba753ee94da143fe2810a90395f4 [file] [log] [blame]
Chris Lattner57ad3782011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner57ad3782011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattner57ad3782011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregor577f75a2009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall2d887082010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor8491ffe2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Richard Smith3e4c6c42011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall19510852010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000034#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000035#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000036#include "TypeLocBuilder.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCall781472f2010-08-25 08:40:02 +000040using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000041
Douglas Gregor577f75a2009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump1eb44332009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump1eb44332009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000101
Douglas Gregord3731192011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000106
Douglas Gregord3731192011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier4a9d7952012-08-08 18:46:20 +0000111
Douglas Gregor577f75a2009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000114
Douglas Gregordfca6f52012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000119
Mike Stump1eb44332009-09-09 15:08:12 +0000120public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000123
Douglas Gregor577f75a2009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000130 }
131
John McCall60d7b3a2010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000134
Douglas Gregor577f75a2009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000138
Douglas Gregor577f75a2009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
144 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000145
Douglas Gregor577f75a2009-08-04 16:50:30 +0000146 /// \brief Returns the location of the entity being transformed, if that
147 /// information was not available elsewhere in the AST.
148 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000149 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000150 /// provide an alternative implementation that provides better location
151 /// information.
152 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000153
Douglas Gregor577f75a2009-08-04 16:50:30 +0000154 /// \brief Returns the name of the entity being transformed, if that
155 /// information was not available elsewhere in the AST.
156 ///
157 /// By default, returns an empty name. Subclasses can provide an alternative
158 /// implementation with a more precise name.
159 DeclarationName getBaseEntity() { return DeclarationName(); }
160
Douglas Gregorb98b1992009-08-11 05:31:07 +0000161 /// \brief Sets the "base" location and entity when that
162 /// information is known based on another transformation.
163 ///
164 /// By default, the source location and entity are ignored. Subclasses can
165 /// override this function to provide a customized implementation.
166 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000167
Douglas Gregorb98b1992009-08-11 05:31:07 +0000168 /// \brief RAII object that temporarily sets the base location and entity
169 /// used for reporting diagnostics in types.
170 class TemporaryBase {
171 TreeTransform &Self;
172 SourceLocation OldLocation;
173 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000174
Douglas Gregorb98b1992009-08-11 05:31:07 +0000175 public:
176 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000177 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000178 OldLocation = Self.getDerived().getBaseLocation();
179 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000180
Douglas Gregorae201f72011-01-25 17:51:48 +0000181 if (Location.isValid())
182 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000183 }
Mike Stump1eb44332009-09-09 15:08:12 +0000184
Douglas Gregorb98b1992009-08-11 05:31:07 +0000185 ~TemporaryBase() {
186 Self.getDerived().setBase(OldLocation, OldEntity);
187 }
188 };
Mike Stump1eb44332009-09-09 15:08:12 +0000189
190 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000191 /// transformed.
192 ///
193 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000194 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000195 /// not change. For example, template instantiation need not traverse
196 /// non-dependent types.
197 bool AlreadyTransformed(QualType T) {
198 return T.isNull();
199 }
200
Douglas Gregor6eef5192009-12-14 19:27:10 +0000201 /// \brief Determine whether the given call argument should be dropped, e.g.,
202 /// because it is a default argument.
203 ///
204 /// Subclasses can provide an alternative implementation of this routine to
205 /// determine which kinds of call arguments get dropped. By default,
206 /// CXXDefaultArgument nodes are dropped (prior to transformation).
207 bool DropCallArgument(Expr *E) {
208 return E->isDefaultArgument();
209 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000210
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000211 /// \brief Determine whether we should expand a pack expansion with the
212 /// given set of parameter packs into separate arguments by repeatedly
213 /// transforming the pattern.
214 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000215 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000216 /// Subclasses can override this routine to provide different behavior.
217 ///
218 /// \param EllipsisLoc The location of the ellipsis that identifies the
219 /// pack expansion.
220 ///
221 /// \param PatternRange The source range that covers the entire pattern of
222 /// the pack expansion.
223 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000224 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000225 /// pattern.
226 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000227 /// \param ShouldExpand Will be set to \c true if the transformer should
228 /// expand the corresponding pack expansions into separate arguments. When
229 /// set, \c NumExpansions must also be set.
230 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000231 /// \param RetainExpansion Whether the caller should add an unexpanded
232 /// pack expansion after all of the expanded arguments. This is used
233 /// when extending explicitly-specified template argument packs per
234 /// C++0x [temp.arg.explicit]p9.
235 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000236 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000237 /// the expanded form of the corresponding pack expansion. This is both an
238 /// input and an output parameter, which can be set by the caller if the
239 /// number of expansions is known a priori (e.g., due to a prior substitution)
240 /// and will be set by the callee when the number of expansions is known.
241 /// The callee must set this value when \c ShouldExpand is \c true; it may
242 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000243 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000244 /// \returns true if an error occurred (e.g., because the parameter packs
245 /// are to be instantiated with arguments of different lengths), false
246 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000247 /// must be set.
248 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
249 SourceRange PatternRange,
David Blaikiea71f9d02011-09-22 02:34:54 +0000250 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000251 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000252 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000253 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000254 ShouldExpand = false;
255 return false;
256 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000257
Douglas Gregord3731192011-01-10 07:32:04 +0000258 /// \brief "Forget" about the partially-substituted pack template argument,
259 /// when performing an instantiation that must preserve the parameter pack
260 /// use.
261 ///
262 /// This routine is meant to be overridden by the template instantiator.
263 TemplateArgument ForgetPartiallySubstitutedPack() {
264 return TemplateArgument();
265 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000266
Douglas Gregord3731192011-01-10 07:32:04 +0000267 /// \brief "Remember" the partially-substituted pack template argument
268 /// after performing an instantiation that must preserve the parameter pack
269 /// use.
270 ///
271 /// This routine is meant to be overridden by the template instantiator.
272 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000273
Douglas Gregor12c9c002011-01-07 16:43:16 +0000274 /// \brief Note to the derived class when a function parameter pack is
275 /// being expanded.
276 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000277
Douglas Gregor577f75a2009-08-04 16:50:30 +0000278 /// \brief Transforms the given type into another type.
279 ///
John McCalla2becad2009-10-21 00:40:46 +0000280 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000281 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000282 /// function. This is expensive, but we don't mind, because
283 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000284 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000285 ///
286 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000287 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000288
John McCalla2becad2009-10-21 00:40:46 +0000289 /// \brief Transforms the given type-with-location into a new
290 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000291 ///
John McCalla2becad2009-10-21 00:40:46 +0000292 /// By default, this routine transforms a type by delegating to the
293 /// appropriate TransformXXXType to build a new type. Subclasses
294 /// may override this function (to take over all type
295 /// transformations) or some set of the TransformXXXType functions
296 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000297 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000298
299 /// \brief Transform the given type-with-location into a new
300 /// type, collecting location information in the given builder
301 /// as necessary.
302 ///
John McCall43fed0d2010-11-12 08:19:04 +0000303 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000304
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000305 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000306 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000307 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000308 /// appropriate TransformXXXStmt function to transform a specific kind of
309 /// statement or the TransformExpr() function to transform an expression.
310 /// Subclasses may override this function to transform statements using some
311 /// other mechanism.
312 ///
313 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000314 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000315
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000316 /// \brief Transform the given expression.
317 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000318 /// By default, this routine transforms an expression by delegating to the
319 /// appropriate TransformXXXExpr function to build a new expression.
320 /// Subclasses may override this function to transform expressions using some
321 /// other mechanism.
322 ///
323 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000324 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000325
Douglas Gregoraa165f82011-01-03 19:04:46 +0000326 /// \brief Transform the given list of expressions.
327 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000328 /// This routine transforms a list of expressions by invoking
329 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregoraa165f82011-01-03 19:04:46 +0000330 /// support for variadic templates by expanding any pack expansions (if the
331 /// derived class permits such expansion) along the way. When pack expansions
332 /// are present, the number of outputs may not equal the number of inputs.
333 ///
334 /// \param Inputs The set of expressions to be transformed.
335 ///
336 /// \param NumInputs The number of expressions in \c Inputs.
337 ///
338 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier4a9d7952012-08-08 18:46:20 +0000339 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregoraa165f82011-01-03 19:04:46 +0000340 /// be.
341 ///
342 /// \param Outputs The transformed input expressions will be added to this
343 /// vector.
344 ///
345 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
346 /// due to transformation.
347 ///
348 /// \returns true if an error occurred, false otherwise.
349 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000350 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000351 bool *ArgChanged = 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000352
Douglas Gregor577f75a2009-08-04 16:50:30 +0000353 /// \brief Transform the given declaration, which is referenced from a type
354 /// or expression.
355 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000356 /// By default, acts as the identity function on declarations, unless the
357 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000358 /// may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000359 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregordfca6f52012-02-13 22:00:16 +0000360 llvm::DenseMap<Decl *, Decl *>::iterator Known
361 = TransformedLocalDecls.find(D);
362 if (Known != TransformedLocalDecls.end())
363 return Known->second;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000364
365 return D;
Douglas Gregordfca6f52012-02-13 22:00:16 +0000366 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000367
Chad Rosier4a9d7952012-08-08 18:46:20 +0000368 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregordfca6f52012-02-13 22:00:16 +0000369 /// place them on the new declaration.
370 ///
371 /// By default, this operation does nothing. Subclasses may override this
372 /// behavior to transform attributes.
373 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000374
Douglas Gregordfca6f52012-02-13 22:00:16 +0000375 /// \brief Note that a local declaration has been transformed by this
376 /// transformer.
377 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000378 /// Local declarations are typically transformed via a call to
Douglas Gregordfca6f52012-02-13 22:00:16 +0000379 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
380 /// the transformer itself has to transform the declarations. This routine
381 /// can be overridden by a subclass that keeps track of such mappings.
382 void transformedLocalDecl(Decl *Old, Decl *New) {
383 TransformedLocalDecls[Old] = New;
384 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000385
Douglas Gregor43959a92009-08-20 07:17:43 +0000386 /// \brief Transform the definition of the given declaration.
387 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000388 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000389 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000390 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
391 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000392 }
Mike Stump1eb44332009-09-09 15:08:12 +0000393
Douglas Gregor6cd21982009-10-20 05:58:46 +0000394 /// \brief Transform the given declaration, which was the first part of a
395 /// nested-name-specifier in a member access expression.
396 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000397 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000398 /// identifier in a nested-name-specifier of a member access expression, e.g.,
399 /// the \c T in \c x->T::member
400 ///
401 /// By default, invokes TransformDecl() to transform the declaration.
402 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000403 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
404 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000405 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000406
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000407 /// \brief Transform the given nested-name-specifier with source-location
408 /// information.
409 ///
410 /// By default, transforms all of the types and declarations within the
411 /// nested-name-specifier. Subclasses may override this function to provide
412 /// alternate behavior.
413 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
414 NestedNameSpecifierLoc NNS,
415 QualType ObjectType = QualType(),
416 NamedDecl *FirstQualifierInScope = 0);
417
Douglas Gregor81499bb2009-09-03 22:13:48 +0000418 /// \brief Transform the given declaration name.
419 ///
420 /// By default, transforms the types of conversion function, constructor,
421 /// and destructor names and then (if needed) rebuilds the declaration name.
422 /// Identifiers and selectors are returned unmodified. Sublcasses may
423 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000424 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000425 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000426
Douglas Gregor577f75a2009-08-04 16:50:30 +0000427 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000428 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000429 /// \param SS The nested-name-specifier that qualifies the template
430 /// name. This nested-name-specifier must already have been transformed.
431 ///
432 /// \param Name The template name to transform.
433 ///
434 /// \param NameLoc The source location of the template name.
435 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000436 /// \param ObjectType If we're translating a template name within a member
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000437 /// access expression, this is the type of the object whose member template
438 /// is being referenced.
439 ///
440 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
441 /// also refers to a name within the current (lexical) scope, this is the
442 /// declaration it refers to.
443 ///
444 /// By default, transforms the template name by transforming the declarations
445 /// and nested-name-specifiers that occur within the template name.
446 /// Subclasses may override this function to provide alternate behavior.
447 TemplateName TransformTemplateName(CXXScopeSpec &SS,
448 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000449 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000450 QualType ObjectType = QualType(),
451 NamedDecl *FirstQualifierInScope = 0);
452
Douglas Gregor577f75a2009-08-04 16:50:30 +0000453 /// \brief Transform the given template argument.
454 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000455 /// By default, this operation transforms the type, expression, or
456 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000457 /// new template argument from the transformed result. Subclasses may
458 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000459 ///
460 /// Returns true if there was an error.
461 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
462 TemplateArgumentLoc &Output);
463
Douglas Gregorfcc12532010-12-20 17:31:10 +0000464 /// \brief Transform the given set of template arguments.
465 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000466 /// By default, this operation transforms all of the template arguments
Douglas Gregorfcc12532010-12-20 17:31:10 +0000467 /// in the input set using \c TransformTemplateArgument(), and appends
468 /// the transformed arguments to the output list.
469 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000470 /// Note that this overload of \c TransformTemplateArguments() is merely
471 /// a convenience function. Subclasses that wish to override this behavior
472 /// should override the iterator-based member template version.
473 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000474 /// \param Inputs The set of template arguments to be transformed.
475 ///
476 /// \param NumInputs The number of template arguments in \p Inputs.
477 ///
478 /// \param Outputs The set of transformed template arguments output by this
479 /// routine.
480 ///
481 /// Returns true if an error occurred.
482 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
483 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000484 TemplateArgumentListInfo &Outputs) {
485 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
486 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000487
488 /// \brief Transform the given set of template arguments.
489 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000490 /// By default, this operation transforms all of the template arguments
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000491 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier4a9d7952012-08-08 18:46:20 +0000492 /// the transformed arguments to the output list.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000493 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000494 /// \param First An iterator to the first template argument.
495 ///
496 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000497 ///
498 /// \param Outputs The set of transformed template arguments output by this
499 /// routine.
500 ///
501 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000502 template<typename InputIterator>
503 bool TransformTemplateArguments(InputIterator First,
504 InputIterator Last,
505 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000506
John McCall833ca992009-10-29 08:12:44 +0000507 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
508 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
509 TemplateArgumentLoc &ArgLoc);
510
John McCalla93c9342009-12-07 02:54:59 +0000511 /// \brief Fakes up a TypeSourceInfo for a type.
512 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
513 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000514 getDerived().getBaseLocation());
515 }
Mike Stump1eb44332009-09-09 15:08:12 +0000516
John McCalla2becad2009-10-21 00:40:46 +0000517#define ABSTRACT_TYPELOC(CLASS, PARENT)
518#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000519 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000520#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000521
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000522 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
523 FunctionProtoTypeLoc TL,
524 CXXRecordDecl *ThisContext,
525 unsigned ThisTypeQuals);
526
John Wiegley28bbe4b2011-04-28 01:08:34 +0000527 StmtResult
528 TransformSEHHandler(Stmt *Handler);
529
Chad Rosier4a9d7952012-08-08 18:46:20 +0000530 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000531 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
532 TemplateSpecializationTypeLoc TL,
533 TemplateName Template);
534
Chad Rosier4a9d7952012-08-08 18:46:20 +0000535 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000536 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
537 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000538 TemplateName Template,
539 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000540
Chad Rosier4a9d7952012-08-08 18:46:20 +0000541 QualType
Douglas Gregora88f09f2011-02-28 17:23:35 +0000542 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000543 DependentTemplateSpecializationTypeLoc TL,
544 NestedNameSpecifierLoc QualifierLoc);
545
John McCall21ef0fa2010-03-11 09:03:00 +0000546 /// \brief Transforms the parameters of a function type into the
547 /// given vectors.
548 ///
549 /// The result vectors should be kept in sync; null entries in the
550 /// variables vector are acceptable.
551 ///
552 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000553 bool TransformFunctionTypeParams(SourceLocation Loc,
554 ParmVarDecl **Params, unsigned NumParams,
555 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000556 SmallVectorImpl<QualType> &PTypes,
557 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000558
559 /// \brief Transforms a single function-type parameter. Return null
560 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000561 ///
562 /// \param indexAdjustment - A number to add to the parameter's
563 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000564 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000565 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000566 llvm::Optional<unsigned> NumExpansions,
567 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000568
John McCall43fed0d2010-11-12 08:19:04 +0000569 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000570
John McCall60d7b3a2010-08-24 06:29:42 +0000571 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
572 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000573
Richard Smith612409e2012-07-25 03:56:55 +0000574 /// \brief Transform the captures and body of a lambda expression.
575 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
576
Douglas Gregor43959a92009-08-20 07:17:43 +0000577#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000578 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000579#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000580 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000581#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000582#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000583
Douglas Gregor577f75a2009-08-04 16:50:30 +0000584 /// \brief Build a new pointer type given its pointee type.
585 ///
586 /// By default, performs semantic analysis when building the pointer type.
587 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000588 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000589
590 /// \brief Build a new block pointer type given its pointee type.
591 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000592 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000593 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000594 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000595
John McCall85737a72009-10-30 00:06:24 +0000596 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000597 ///
John McCall85737a72009-10-30 00:06:24 +0000598 /// By default, performs semantic analysis when building the
599 /// reference type. Subclasses may override this routine to provide
600 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000601 ///
John McCall85737a72009-10-30 00:06:24 +0000602 /// \param LValue whether the type was written with an lvalue sigil
603 /// or an rvalue sigil.
604 QualType RebuildReferenceType(QualType ReferentType,
605 bool LValue,
606 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000607
Douglas Gregor577f75a2009-08-04 16:50:30 +0000608 /// \brief Build a new member pointer type given the pointee type and the
609 /// class type it refers into.
610 ///
611 /// By default, performs semantic analysis when building the member pointer
612 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000613 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
614 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000615
Douglas Gregor577f75a2009-08-04 16:50:30 +0000616 /// \brief Build a new array type given the element type, size
617 /// modifier, size of the array (if known), size expression, and index type
618 /// qualifiers.
619 ///
620 /// By default, performs semantic analysis when building the array type.
621 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000622 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000623 QualType RebuildArrayType(QualType ElementType,
624 ArrayType::ArraySizeModifier SizeMod,
625 const llvm::APInt *Size,
626 Expr *SizeExpr,
627 unsigned IndexTypeQuals,
628 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000629
Douglas Gregor577f75a2009-08-04 16:50:30 +0000630 /// \brief Build a new constant array type given the element type, size
631 /// modifier, (known) size of the array, and index type qualifiers.
632 ///
633 /// By default, performs semantic analysis when building the array type.
634 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000635 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636 ArrayType::ArraySizeModifier SizeMod,
637 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000638 unsigned IndexTypeQuals,
639 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000640
Douglas Gregor577f75a2009-08-04 16:50:30 +0000641 /// \brief Build a new incomplete array type given the element type, size
642 /// modifier, and index type qualifiers.
643 ///
644 /// By default, performs semantic analysis when building the array type.
645 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000646 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000647 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000648 unsigned IndexTypeQuals,
649 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000650
Mike Stump1eb44332009-09-09 15:08:12 +0000651 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000652 /// size modifier, size expression, and index type qualifiers.
653 ///
654 /// By default, performs semantic analysis when building the array type.
655 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000656 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000657 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000658 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000659 unsigned IndexTypeQuals,
660 SourceRange BracketsRange);
661
Mike Stump1eb44332009-09-09 15:08:12 +0000662 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663 /// size modifier, size expression, and index type qualifiers.
664 ///
665 /// By default, performs semantic analysis when building the array type.
666 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000667 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000668 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000669 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000670 unsigned IndexTypeQuals,
671 SourceRange BracketsRange);
672
673 /// \brief Build a new vector type given the element type and
674 /// number of elements.
675 ///
676 /// By default, performs semantic analysis when building the vector type.
677 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000678 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000679 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000680
Douglas Gregor577f75a2009-08-04 16:50:30 +0000681 /// \brief Build a new extended vector type given the element type and
682 /// number of elements.
683 ///
684 /// By default, performs semantic analysis when building the vector type.
685 /// Subclasses may override this routine to provide different behavior.
686 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
687 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000688
689 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000690 /// given the element type and number of elements.
691 ///
692 /// By default, performs semantic analysis when building the vector type.
693 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000694 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000695 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000696 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000697
Douglas Gregor577f75a2009-08-04 16:50:30 +0000698 /// \brief Build a new function type.
699 ///
700 /// By default, performs semantic analysis when building the function type.
701 /// Subclasses may override this routine to provide different behavior.
702 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000703 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000704 unsigned NumParamTypes,
Richard Smitheefb3d52012-02-10 09:58:53 +0000705 bool Variadic, bool HasTrailingReturn,
706 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000707 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000708 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000709
John McCalla2becad2009-10-21 00:40:46 +0000710 /// \brief Build a new unprototyped function type.
711 QualType RebuildFunctionNoProtoType(QualType ResultType);
712
John McCalled976492009-12-04 22:46:56 +0000713 /// \brief Rebuild an unresolved typename type, given the decl that
714 /// the UnresolvedUsingTypenameDecl was transformed to.
715 QualType RebuildUnresolvedUsingType(Decl *D);
716
Douglas Gregor577f75a2009-08-04 16:50:30 +0000717 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000718 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000719 return SemaRef.Context.getTypeDeclType(Typedef);
720 }
721
722 /// \brief Build a new class/struct/union type.
723 QualType RebuildRecordType(RecordDecl *Record) {
724 return SemaRef.Context.getTypeDeclType(Record);
725 }
726
727 /// \brief Build a new Enum type.
728 QualType RebuildEnumType(EnumDecl *Enum) {
729 return SemaRef.Context.getTypeDeclType(Enum);
730 }
John McCall7da24312009-09-05 00:15:47 +0000731
Mike Stump1eb44332009-09-09 15:08:12 +0000732 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000733 ///
734 /// By default, performs semantic analysis when building the typeof type.
735 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000736 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000737
Mike Stump1eb44332009-09-09 15:08:12 +0000738 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000739 ///
740 /// By default, builds a new TypeOfType with the given underlying type.
741 QualType RebuildTypeOfType(QualType Underlying);
742
Sean Huntca63c202011-05-24 22:41:36 +0000743 /// \brief Build a new unary transform type.
744 QualType RebuildUnaryTransformType(QualType BaseType,
745 UnaryTransformType::UTTKind UKind,
746 SourceLocation Loc);
747
Mike Stump1eb44332009-09-09 15:08:12 +0000748 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000749 ///
750 /// By default, performs semantic analysis when building the decltype type.
751 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000752 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000753
Richard Smith34b41d92011-02-20 03:19:35 +0000754 /// \brief Build a new C++0x auto type.
755 ///
756 /// By default, builds a new AutoType with the given deduced type.
757 QualType RebuildAutoType(QualType Deduced) {
758 return SemaRef.Context.getAutoType(Deduced);
759 }
760
Douglas Gregor577f75a2009-08-04 16:50:30 +0000761 /// \brief Build a new template specialization type.
762 ///
763 /// By default, performs semantic analysis when building the template
764 /// specialization type. Subclasses may override this routine to provide
765 /// different behavior.
766 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000767 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000768 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000769
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000770 /// \brief Build a new parenthesized type.
771 ///
772 /// By default, builds a new ParenType type from the inner type.
773 /// Subclasses may override this routine to provide different behavior.
774 QualType RebuildParenType(QualType InnerType) {
775 return SemaRef.Context.getParenType(InnerType);
776 }
777
Douglas Gregor577f75a2009-08-04 16:50:30 +0000778 /// \brief Build a new qualified name type.
779 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000780 /// By default, builds a new ElaboratedType type from the keyword,
781 /// the nested-name-specifier and the named type.
782 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000783 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
784 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000785 NestedNameSpecifierLoc QualifierLoc,
786 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000787 return SemaRef.Context.getElaboratedType(Keyword,
788 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000789 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000790 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000791
792 /// \brief Build a new typename type that refers to a template-id.
793 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000794 /// By default, builds a new DependentNameType type from the
795 /// nested-name-specifier and the given type. Subclasses may override
796 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000797 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000798 ElaboratedTypeKeyword Keyword,
799 NestedNameSpecifierLoc QualifierLoc,
800 const IdentifierInfo *Name,
801 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000802 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000803 // Rebuild the template name.
804 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000805 CXXScopeSpec SS;
806 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000807 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000808 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000809
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000810 if (InstName.isNull())
811 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000812
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000813 // If it's still dependent, make a dependent specialization.
814 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000815 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
816 QualifierLoc.getNestedNameSpecifier(),
817 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000818 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000819
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000820 // Otherwise, make an elaborated type wrapping a non-dependent
821 // specialization.
822 QualType T =
823 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
824 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000825
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000826 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
827 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000828
829 return SemaRef.Context.getElaboratedType(Keyword,
830 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000831 T);
832 }
833
Douglas Gregor577f75a2009-08-04 16:50:30 +0000834 /// \brief Build a new typename type that refers to an identifier.
835 ///
836 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000837 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000838 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000839 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000840 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000841 NestedNameSpecifierLoc QualifierLoc,
842 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000843 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000844 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000845 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000846
Douglas Gregor2494dd02011-03-01 01:34:45 +0000847 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000848 // If the name is still dependent, just build a new dependent name type.
849 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000850 return SemaRef.Context.getDependentNameType(Keyword,
851 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000852 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000853 }
854
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000855 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000856 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000857 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000858
859 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
860
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000861 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000862 // into a non-dependent elaborated-type-specifier. Find the tag we're
863 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000864 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000865 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
866 if (!DC)
867 return QualType();
868
John McCall56138762010-05-27 06:40:31 +0000869 if (SemaRef.RequireCompleteDeclContext(SS, DC))
870 return QualType();
871
Douglas Gregor40336422010-03-31 22:19:08 +0000872 TagDecl *Tag = 0;
873 SemaRef.LookupQualifiedName(Result, DC);
874 switch (Result.getResultKind()) {
875 case LookupResult::NotFound:
876 case LookupResult::NotFoundInCurrentInstantiation:
877 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000878
Douglas Gregor40336422010-03-31 22:19:08 +0000879 case LookupResult::Found:
880 Tag = Result.getAsSingle<TagDecl>();
881 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000882
Douglas Gregor40336422010-03-31 22:19:08 +0000883 case LookupResult::FoundOverloaded:
884 case LookupResult::FoundUnresolvedValue:
885 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000886
Douglas Gregor40336422010-03-31 22:19:08 +0000887 case LookupResult::Ambiguous:
888 // Let the LookupResult structure handle ambiguities.
889 return QualType();
890 }
891
892 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000893 // Check where the name exists but isn't a tag type and use that to emit
894 // better diagnostics.
895 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
896 SemaRef.LookupQualifiedName(Result, DC);
897 switch (Result.getResultKind()) {
898 case LookupResult::Found:
899 case LookupResult::FoundOverloaded:
900 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000901 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000902 unsigned Kind = 0;
903 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000904 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
905 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000906 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
907 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
908 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000909 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000910 default:
911 // FIXME: Would be nice to highlight just the source range.
912 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
913 << Kind << Id << DC;
914 break;
915 }
Douglas Gregor40336422010-03-31 22:19:08 +0000916 return QualType();
917 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000918
Richard Trieubbf34c02011-06-10 03:11:26 +0000919 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
920 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000921 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000922 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
923 return QualType();
924 }
925
926 // Build the elaborated-type-specifier type.
927 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000928 return SemaRef.Context.getElaboratedType(Keyword,
929 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000930 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000931 }
Mike Stump1eb44332009-09-09 15:08:12 +0000932
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000933 /// \brief Build a new pack expansion type.
934 ///
935 /// By default, builds a new PackExpansionType type from the given pattern.
936 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000937 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000938 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000939 SourceLocation EllipsisLoc,
940 llvm::Optional<unsigned> NumExpansions) {
941 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
942 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000943 }
944
Eli Friedmanb001de72011-10-06 23:00:33 +0000945 /// \brief Build a new atomic type given its value type.
946 ///
947 /// By default, performs semantic analysis when building the atomic type.
948 /// Subclasses may override this routine to provide different behavior.
949 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
950
Douglas Gregord1067e52009-08-06 06:41:21 +0000951 /// \brief Build a new template name given a nested name specifier, a flag
952 /// indicating whether the "template" keyword was provided, and the template
953 /// that the template name refers to.
954 ///
955 /// By default, builds the new template name directly. Subclasses may override
956 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000957 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000958 bool TemplateKW,
959 TemplateDecl *Template);
960
Douglas Gregord1067e52009-08-06 06:41:21 +0000961 /// \brief Build a new template name given a nested name specifier and the
962 /// name that is referred to as a template.
963 ///
964 /// By default, performs semantic analysis to determine whether the name can
965 /// be resolved to a specific template, then builds the appropriate kind of
966 /// template name. Subclasses may override this routine to provide different
967 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000968 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
969 const IdentifierInfo &Name,
970 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000971 QualType ObjectType,
972 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000973
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000974 /// \brief Build a new template name given a nested name specifier and the
975 /// overloaded operator name that is referred to as a template.
976 ///
977 /// By default, performs semantic analysis to determine whether the name can
978 /// be resolved to a specific template, then builds the appropriate kind of
979 /// template name. Subclasses may override this routine to provide different
980 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000981 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000982 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000983 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000984 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000985
986 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +0000987 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000988 ///
989 /// By default, performs semantic analysis to determine whether the name can
990 /// be resolved to a specific template, then builds the appropriate kind of
991 /// template name. Subclasses may override this routine to provide different
992 /// behavior.
993 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
994 const TemplateArgument &ArgPack) {
995 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
996 }
997
Douglas Gregor43959a92009-08-20 07:17:43 +0000998 /// \brief Build a new compound statement.
999 ///
1000 /// By default, performs semantic analysis to build the new statement.
1001 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001002 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001003 MultiStmtArg Statements,
1004 SourceLocation RBraceLoc,
1005 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001006 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001007 IsStmtExpr);
1008 }
1009
1010 /// \brief Build a new case statement.
1011 ///
1012 /// By default, performs semantic analysis to build the new statement.
1013 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001014 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001015 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001016 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001017 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001018 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001019 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001020 ColonLoc);
1021 }
Mike Stump1eb44332009-09-09 15:08:12 +00001022
Douglas Gregor43959a92009-08-20 07:17:43 +00001023 /// \brief Attach the body to a new case statement.
1024 ///
1025 /// By default, performs semantic analysis to build the new statement.
1026 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001027 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001028 getSema().ActOnCaseStmtBody(S, Body);
1029 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001030 }
Mike Stump1eb44332009-09-09 15:08:12 +00001031
Douglas Gregor43959a92009-08-20 07:17:43 +00001032 /// \brief Build a new default statement.
1033 ///
1034 /// By default, performs semantic analysis to build the new statement.
1035 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001036 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001037 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001038 Stmt *SubStmt) {
1039 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001040 /*CurScope=*/0);
1041 }
Mike Stump1eb44332009-09-09 15:08:12 +00001042
Douglas Gregor43959a92009-08-20 07:17:43 +00001043 /// \brief Build a new label statement.
1044 ///
1045 /// By default, performs semantic analysis to build the new statement.
1046 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001047 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1048 SourceLocation ColonLoc, Stmt *SubStmt) {
1049 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001050 }
Mike Stump1eb44332009-09-09 15:08:12 +00001051
Richard Smith534986f2012-04-14 00:33:13 +00001052 /// \brief Build a new label statement.
1053 ///
1054 /// By default, performs semantic analysis to build the new statement.
1055 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001056 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1057 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001058 Stmt *SubStmt) {
1059 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1060 }
1061
Douglas Gregor43959a92009-08-20 07:17:43 +00001062 /// \brief Build a new "if" statement.
1063 ///
1064 /// By default, performs semantic analysis to build the new statement.
1065 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001066 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001067 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001068 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001069 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001070 }
Mike Stump1eb44332009-09-09 15:08:12 +00001071
Douglas Gregor43959a92009-08-20 07:17:43 +00001072 /// \brief Start building a new switch statement.
1073 ///
1074 /// By default, performs semantic analysis to build the new statement.
1075 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001076 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001077 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001078 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001079 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001080 }
Mike Stump1eb44332009-09-09 15:08:12 +00001081
Douglas Gregor43959a92009-08-20 07:17:43 +00001082 /// \brief Attach the body to the switch statement.
1083 ///
1084 /// By default, performs semantic analysis to build the new statement.
1085 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001086 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001087 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001088 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001089 }
1090
1091 /// \brief Build a new while statement.
1092 ///
1093 /// By default, performs semantic analysis to build the new statement.
1094 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001095 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1096 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001097 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001098 }
Mike Stump1eb44332009-09-09 15:08:12 +00001099
Douglas Gregor43959a92009-08-20 07:17:43 +00001100 /// \brief Build a new do-while statement.
1101 ///
1102 /// By default, performs semantic analysis to build the new statement.
1103 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001104 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001105 SourceLocation WhileLoc, SourceLocation LParenLoc,
1106 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001107 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1108 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001109 }
1110
1111 /// \brief Build a new for statement.
1112 ///
1113 /// By default, performs semantic analysis to build the new statement.
1114 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001115 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001116 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001117 VarDecl *CondVar, Sema::FullExprArg Inc,
1118 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001119 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001120 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001121 }
Mike Stump1eb44332009-09-09 15:08:12 +00001122
Douglas Gregor43959a92009-08-20 07:17:43 +00001123 /// \brief Build a new goto statement.
1124 ///
1125 /// By default, performs semantic analysis to build the new statement.
1126 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001127 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1128 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001129 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001130 }
1131
1132 /// \brief Build a new indirect goto statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001136 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001137 SourceLocation StarLoc,
1138 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001139 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001140 }
Mike Stump1eb44332009-09-09 15:08:12 +00001141
Douglas Gregor43959a92009-08-20 07:17:43 +00001142 /// \brief Build a new return statement.
1143 ///
1144 /// By default, performs semantic analysis to build the new statement.
1145 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001146 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001147 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001148 }
Mike Stump1eb44332009-09-09 15:08:12 +00001149
Douglas Gregor43959a92009-08-20 07:17:43 +00001150 /// \brief Build a new declaration statement.
1151 ///
1152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001154 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001155 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001156 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001157 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1158 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001159 }
Mike Stump1eb44332009-09-09 15:08:12 +00001160
Anders Carlsson703e3942010-01-24 05:50:09 +00001161 /// \brief Build a new inline asm statement.
1162 ///
1163 /// By default, performs semantic analysis to build the new statement.
1164 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001165 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001166 bool IsSimple,
1167 bool IsVolatile,
1168 unsigned NumOutputs,
1169 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001170 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001171 MultiExprArg Constraints,
1172 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001173 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001174 MultiExprArg Clobbers,
Chad Rosierdf4ee102012-08-20 17:11:53 +00001175 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001176 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001177 NumInputs, Names, Constraints,
John McCall9ae2f072010-08-23 23:25:46 +00001178 Exprs, AsmString, Clobbers,
Chad Rosierdf4ee102012-08-20 17:11:53 +00001179 RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001180 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001181
Chad Rosier8cd64b42012-06-11 20:47:18 +00001182 /// \brief Build a new MS style inline asm statement.
1183 ///
1184 /// By default, performs semantic analysis to build the new statement.
1185 /// Subclasses may override this routine to provide different behavior.
1186 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc,
Chad Rosier7bd092b2012-08-15 16:53:30 +00001187 SourceLocation LBraceLoc,
Chad Rosier79efe242012-08-07 00:29:06 +00001188 ArrayRef<Token> AsmToks,
Chad Rosier8cd64b42012-06-11 20:47:18 +00001189 SourceLocation EndLoc) {
Chad Rosier7bd092b2012-08-15 16:53:30 +00001190 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001191 }
1192
James Dennett699c9042012-06-15 07:13:21 +00001193 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001194 ///
1195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001197 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001198 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001199 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001200 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001201 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001202 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001203 }
1204
Douglas Gregorbe270a02010-04-26 17:57:08 +00001205 /// \brief Rebuild an Objective-C exception declaration.
1206 ///
1207 /// By default, performs semantic analysis to build the new declaration.
1208 /// Subclasses may override this routine to provide different behavior.
1209 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1210 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001211 return getSema().BuildObjCExceptionDecl(TInfo, T,
1212 ExceptionDecl->getInnerLocStart(),
1213 ExceptionDecl->getLocation(),
1214 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001215 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001216
James Dennett699c9042012-06-15 07:13:21 +00001217 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001218 ///
1219 /// By default, performs semantic analysis to build the new statement.
1220 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001221 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001222 SourceLocation RParenLoc,
1223 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001224 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001225 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001226 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001227 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001228
James Dennett699c9042012-06-15 07:13:21 +00001229 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001230 ///
1231 /// By default, performs semantic analysis to build the new statement.
1232 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001233 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001234 Stmt *Body) {
1235 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001236 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001237
James Dennett699c9042012-06-15 07:13:21 +00001238 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001239 ///
1240 /// By default, performs semantic analysis to build the new statement.
1241 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001242 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001243 Expr *Operand) {
1244 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001245 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001246
James Dennett699c9042012-06-15 07:13:21 +00001247 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001248 ///
1249 /// By default, performs semantic analysis to build the new statement.
1250 /// Subclasses may override this routine to provide different behavior.
1251 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1252 Expr *object) {
1253 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1254 }
1255
James Dennett699c9042012-06-15 07:13:21 +00001256 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001257 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001258 /// By default, performs semantic analysis to build the new statement.
1259 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001260 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001261 Expr *Object, Stmt *Body) {
1262 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001263 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001264
James Dennett699c9042012-06-15 07:13:21 +00001265 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001266 ///
1267 /// By default, performs semantic analysis to build the new statement.
1268 /// Subclasses may override this routine to provide different behavior.
1269 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1270 Stmt *Body) {
1271 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1272 }
John McCall990567c2011-07-27 01:07:15 +00001273
Douglas Gregorc3203e72010-04-22 23:10:45 +00001274 /// \brief Build a new Objective-C fast enumeration statement.
1275 ///
1276 /// By default, performs semantic analysis to build the new statement.
1277 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001278 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001279 Stmt *Element,
1280 Expr *Collection,
1281 SourceLocation RParenLoc,
1282 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001283 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001284 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001285 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001286 RParenLoc);
1287 if (ForEachStmt.isInvalid())
1288 return StmtError();
1289
1290 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001291 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001292
Douglas Gregor43959a92009-08-20 07:17:43 +00001293 /// \brief Build a new C++ exception declaration.
1294 ///
1295 /// By default, performs semantic analysis to build the new decaration.
1296 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001297 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001298 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001299 SourceLocation StartLoc,
1300 SourceLocation IdLoc,
1301 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001302 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1303 StartLoc, IdLoc, Id);
1304 if (Var)
1305 getSema().CurContext->addDecl(Var);
1306 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001307 }
1308
1309 /// \brief Build a new C++ catch statement.
1310 ///
1311 /// By default, performs semantic analysis to build the new statement.
1312 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001313 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001314 VarDecl *ExceptionDecl,
1315 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001316 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1317 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001318 }
Mike Stump1eb44332009-09-09 15:08:12 +00001319
Douglas Gregor43959a92009-08-20 07:17:43 +00001320 /// \brief Build a new C++ try statement.
1321 ///
1322 /// By default, performs semantic analysis to build the new statement.
1323 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001324 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001325 Stmt *TryBlock,
1326 MultiStmtArg Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001327 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001328 }
Mike Stump1eb44332009-09-09 15:08:12 +00001329
Richard Smithad762fc2011-04-14 22:09:26 +00001330 /// \brief Build a new C++0x range-based for statement.
1331 ///
1332 /// By default, performs semantic analysis to build the new statement.
1333 /// Subclasses may override this routine to provide different behavior.
1334 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1335 SourceLocation ColonLoc,
1336 Stmt *Range, Stmt *BeginEnd,
1337 Expr *Cond, Expr *Inc,
1338 Stmt *LoopVar,
1339 SourceLocation RParenLoc) {
1340 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Sam Panzere1715b62012-08-21 00:52:01 +00001341 Cond, Inc, LoopVar, RParenLoc, false);
Richard Smithad762fc2011-04-14 22:09:26 +00001342 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001343
1344 /// \brief Build a new C++0x range-based for statement.
1345 ///
1346 /// By default, performs semantic analysis to build the new statement.
1347 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001348 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001349 bool IsIfExists,
1350 NestedNameSpecifierLoc QualifierLoc,
1351 DeclarationNameInfo NameInfo,
1352 Stmt *Nested) {
1353 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1354 QualifierLoc, NameInfo, Nested);
1355 }
1356
Richard Smithad762fc2011-04-14 22:09:26 +00001357 /// \brief Attach body to a C++0x range-based for statement.
1358 ///
1359 /// By default, performs semantic analysis to finish the new statement.
1360 /// Subclasses may override this routine to provide different behavior.
1361 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1362 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1363 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001364
John Wiegley28bbe4b2011-04-28 01:08:34 +00001365 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1366 SourceLocation TryLoc,
1367 Stmt *TryBlock,
1368 Stmt *Handler) {
1369 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1370 }
1371
1372 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1373 Expr *FilterExpr,
1374 Stmt *Block) {
1375 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1376 }
1377
1378 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1379 Stmt *Block) {
1380 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1381 }
1382
Douglas Gregorb98b1992009-08-11 05:31:07 +00001383 /// \brief Build a new expression that references a declaration.
1384 ///
1385 /// By default, performs semantic analysis to build the new expression.
1386 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001387 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001388 LookupResult &R,
1389 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001390 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1391 }
1392
1393
1394 /// \brief Build a new expression that references a declaration.
1395 ///
1396 /// By default, performs semantic analysis to build the new expression.
1397 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001398 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001399 ValueDecl *VD,
1400 const DeclarationNameInfo &NameInfo,
1401 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001402 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001403 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001404
1405 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001406
1407 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001408 }
Mike Stump1eb44332009-09-09 15:08:12 +00001409
Douglas Gregorb98b1992009-08-11 05:31:07 +00001410 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001411 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001412 /// By default, performs semantic analysis to build the new expression.
1413 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001414 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001416 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001417 }
1418
Douglas Gregora71d8192009-09-04 17:36:40 +00001419 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001420 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001421 /// By default, performs semantic analysis to build the new expression.
1422 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001423 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001424 SourceLocation OperatorLoc,
1425 bool isArrow,
1426 CXXScopeSpec &SS,
1427 TypeSourceInfo *ScopeType,
1428 SourceLocation CCLoc,
1429 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001430 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001431
Douglas Gregorb98b1992009-08-11 05:31:07 +00001432 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001433 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001434 /// By default, performs semantic analysis to build the new expression.
1435 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001436 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001437 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001438 Expr *SubExpr) {
1439 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001440 }
Mike Stump1eb44332009-09-09 15:08:12 +00001441
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001442 /// \brief Build a new builtin offsetof expression.
1443 ///
1444 /// By default, performs semantic analysis to build the new expression.
1445 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001446 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001447 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001448 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001449 unsigned NumComponents,
1450 SourceLocation RParenLoc) {
1451 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1452 NumComponents, RParenLoc);
1453 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001454
1455 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001456 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001457 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001458 /// By default, performs semantic analysis to build the new expression.
1459 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001460 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1461 SourceLocation OpLoc,
1462 UnaryExprOrTypeTrait ExprKind,
1463 SourceRange R) {
1464 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001465 }
1466
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001467 /// \brief Build a new sizeof, alignof or vec step expression with an
1468 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001469 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001470 /// By default, performs semantic analysis to build the new expression.
1471 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001472 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1473 UnaryExprOrTypeTrait ExprKind,
1474 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001475 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001476 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001477 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001478 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001479
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001480 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001481 }
Mike Stump1eb44332009-09-09 15:08:12 +00001482
Douglas Gregorb98b1992009-08-11 05:31:07 +00001483 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001484 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001485 /// By default, performs semantic analysis to build the new expression.
1486 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001487 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001488 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001489 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001491 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1492 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 RBracketLoc);
1494 }
1495
1496 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001497 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 /// By default, performs semantic analysis to build the new expression.
1499 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001500 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001501 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001502 SourceLocation RParenLoc,
1503 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001504 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001505 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001506 }
1507
1508 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001509 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001510 /// By default, performs semantic analysis to build the new expression.
1511 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001512 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001513 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001514 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001515 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001516 const DeclarationNameInfo &MemberNameInfo,
1517 ValueDecl *Member,
1518 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001519 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001520 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001521 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1522 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001523 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001524 // We have a reference to an unnamed field. This is always the
1525 // base of an anonymous struct/union member access, i.e. the
1526 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001527 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001528 assert(Member->getType()->isRecordType() &&
1529 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001530
Richard Smith9138b4e2011-10-26 19:06:56 +00001531 BaseResult =
1532 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001533 QualifierLoc.getNestedNameSpecifier(),
1534 FoundDecl, Member);
1535 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001536 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001537 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001538 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001539 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001540 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001541 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001542 cast<FieldDecl>(Member)->getType(),
1543 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001544 return getSema().Owned(ME);
1545 }
Mike Stump1eb44332009-09-09 15:08:12 +00001546
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001547 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001548 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001549
John Wiegley429bb272011-04-08 18:41:53 +00001550 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001551 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001552
John McCall6bb80172010-03-30 21:47:33 +00001553 // FIXME: this involves duplicating earlier analysis in a lot of
1554 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001555 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001556 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001557 R.resolveKind();
1558
John McCall9ae2f072010-08-23 23:25:46 +00001559 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001560 SS, TemplateKWLoc,
1561 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001562 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001563 }
Mike Stump1eb44332009-09-09 15:08:12 +00001564
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001566 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 /// By default, performs semantic analysis to build the new expression.
1568 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001569 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001570 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001571 Expr *LHS, Expr *RHS) {
1572 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001573 }
1574
1575 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001576 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001577 /// By default, performs semantic analysis to build the new expression.
1578 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001579 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001580 SourceLocation QuestionLoc,
1581 Expr *LHS,
1582 SourceLocation ColonLoc,
1583 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001584 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1585 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 }
1587
Douglas Gregorb98b1992009-08-11 05:31:07 +00001588 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001589 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 /// By default, performs semantic analysis to build the new expression.
1591 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001592 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001593 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001595 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001596 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001597 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001598 }
Mike Stump1eb44332009-09-09 15:08:12 +00001599
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001601 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 /// By default, performs semantic analysis to build the new expression.
1603 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001604 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001605 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001606 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001607 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001608 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001609 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001610 }
Mike Stump1eb44332009-09-09 15:08:12 +00001611
Douglas Gregorb98b1992009-08-11 05:31:07 +00001612 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001613 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 /// By default, performs semantic analysis to build the new expression.
1615 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001616 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001617 SourceLocation OpLoc,
1618 SourceLocation AccessorLoc,
1619 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001620
John McCall129e2df2009-11-30 22:42:35 +00001621 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001622 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001623 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001624 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001625 SS, SourceLocation(),
1626 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001627 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001628 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001629 }
Mike Stump1eb44332009-09-09 15:08:12 +00001630
Douglas Gregorb98b1992009-08-11 05:31:07 +00001631 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001632 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001633 /// By default, performs semantic analysis to build the new expression.
1634 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001635 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001636 MultiExprArg Inits,
1637 SourceLocation RBraceLoc,
1638 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001639 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001640 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001641 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001642 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001643
Douglas Gregore48319a2009-11-09 17:16:50 +00001644 // Patch in the result type we were given, which may have been computed
1645 // when the initial InitListExpr was built.
1646 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1647 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001648 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001649 }
Mike Stump1eb44332009-09-09 15:08:12 +00001650
Douglas Gregorb98b1992009-08-11 05:31:07 +00001651 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001652 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 /// By default, performs semantic analysis to build the new expression.
1654 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001655 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001656 MultiExprArg ArrayExprs,
1657 SourceLocation EqualOrColonLoc,
1658 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001659 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001660 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001662 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001664 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001665
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001666 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 }
Mike Stump1eb44332009-09-09 15:08:12 +00001668
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001670 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 /// By default, builds the implicit value initialization without performing
1672 /// any semantic analysis. Subclasses may override this routine to provide
1673 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001674 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001675 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1676 }
Mike Stump1eb44332009-09-09 15:08:12 +00001677
Douglas Gregorb98b1992009-08-11 05:31:07 +00001678 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001679 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001680 /// By default, performs semantic analysis to build the new expression.
1681 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001682 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001683 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001684 SourceLocation RParenLoc) {
1685 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001686 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001687 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001688 }
1689
1690 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001691 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001692 /// By default, performs semantic analysis to build the new expression.
1693 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001694 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001695 MultiExprArg SubExprs,
1696 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001697 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001698 }
Mike Stump1eb44332009-09-09 15:08:12 +00001699
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001701 ///
1702 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001703 /// rather than attempting to map the label statement itself.
1704 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001705 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001706 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001707 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 }
Mike Stump1eb44332009-09-09 15:08:12 +00001709
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001711 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 /// By default, performs semantic analysis to build the new expression.
1713 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001714 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001715 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001716 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001717 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 }
Mike Stump1eb44332009-09-09 15:08:12 +00001719
Douglas Gregorb98b1992009-08-11 05:31:07 +00001720 /// \brief Build a new __builtin_choose_expr expression.
1721 ///
1722 /// By default, performs semantic analysis to build the new expression.
1723 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001724 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001725 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001726 SourceLocation RParenLoc) {
1727 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001728 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001729 RParenLoc);
1730 }
Mike Stump1eb44332009-09-09 15:08:12 +00001731
Peter Collingbournef111d932011-04-15 00:35:48 +00001732 /// \brief Build a new generic selection expression.
1733 ///
1734 /// By default, performs semantic analysis to build the new expression.
1735 /// Subclasses may override this routine to provide different behavior.
1736 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1737 SourceLocation DefaultLoc,
1738 SourceLocation RParenLoc,
1739 Expr *ControllingExpr,
1740 TypeSourceInfo **Types,
1741 Expr **Exprs,
1742 unsigned NumAssocs) {
1743 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1744 ControllingExpr, Types, Exprs,
1745 NumAssocs);
1746 }
1747
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 /// \brief Build a new overloaded operator call expression.
1749 ///
1750 /// By default, performs semantic analysis to build the new expression.
1751 /// The semantic analysis provides the behavior of template instantiation,
1752 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001753 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001754 /// argument-dependent lookup, etc. Subclasses may override this routine to
1755 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001756 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001757 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001758 Expr *Callee,
1759 Expr *First,
1760 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001761
1762 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001763 /// reinterpret_cast.
1764 ///
1765 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001766 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001767 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001768 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001769 Stmt::StmtClass Class,
1770 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001771 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001772 SourceLocation RAngleLoc,
1773 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001774 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001775 SourceLocation RParenLoc) {
1776 switch (Class) {
1777 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001778 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001779 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001780 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781
1782 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001783 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001784 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001785 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001786
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001788 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001789 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001790 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001792
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001794 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001795 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001796 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001797
Douglas Gregorb98b1992009-08-11 05:31:07 +00001798 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001799 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 }
Mike Stump1eb44332009-09-09 15:08:12 +00001802
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 /// \brief Build a new C++ static_cast expression.
1804 ///
1805 /// By default, performs semantic analysis to build the new expression.
1806 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001807 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001808 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001809 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001810 SourceLocation RAngleLoc,
1811 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001812 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001813 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001814 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001815 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001816 SourceRange(LAngleLoc, RAngleLoc),
1817 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001818 }
1819
1820 /// \brief Build a new C++ dynamic_cast expression.
1821 ///
1822 /// By default, performs semantic analysis to build the new expression.
1823 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001824 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001825 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001826 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001827 SourceLocation RAngleLoc,
1828 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001829 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001830 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001831 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001832 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001833 SourceRange(LAngleLoc, RAngleLoc),
1834 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001835 }
1836
1837 /// \brief Build a new C++ reinterpret_cast expression.
1838 ///
1839 /// By default, performs semantic analysis to build the new expression.
1840 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001841 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001842 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001843 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001844 SourceLocation RAngleLoc,
1845 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001846 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001847 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001848 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001849 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001850 SourceRange(LAngleLoc, RAngleLoc),
1851 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001852 }
1853
1854 /// \brief Build a new C++ const_cast expression.
1855 ///
1856 /// By default, performs semantic analysis to build the new expression.
1857 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001858 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001859 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001860 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001861 SourceLocation RAngleLoc,
1862 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001863 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001864 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001865 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001866 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001867 SourceRange(LAngleLoc, RAngleLoc),
1868 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001869 }
Mike Stump1eb44332009-09-09 15:08:12 +00001870
Douglas Gregorb98b1992009-08-11 05:31:07 +00001871 /// \brief Build a new C++ functional-style cast expression.
1872 ///
1873 /// By default, performs semantic analysis to build the new expression.
1874 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001875 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1876 SourceLocation LParenLoc,
1877 Expr *Sub,
1878 SourceLocation RParenLoc) {
1879 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001880 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001881 RParenLoc);
1882 }
Mike Stump1eb44332009-09-09 15:08:12 +00001883
Douglas Gregorb98b1992009-08-11 05:31:07 +00001884 /// \brief Build a new C++ typeid(type) expression.
1885 ///
1886 /// By default, performs semantic analysis to build the new expression.
1887 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001888 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001889 SourceLocation TypeidLoc,
1890 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001891 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001892 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001893 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001894 }
Mike Stump1eb44332009-09-09 15:08:12 +00001895
Francois Pichet01b7c302010-09-08 12:20:18 +00001896
Douglas Gregorb98b1992009-08-11 05:31:07 +00001897 /// \brief Build a new C++ typeid(expr) expression.
1898 ///
1899 /// By default, performs semantic analysis to build the new expression.
1900 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001901 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001902 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001903 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001904 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001905 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001906 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001907 }
1908
Francois Pichet01b7c302010-09-08 12:20:18 +00001909 /// \brief Build a new C++ __uuidof(type) expression.
1910 ///
1911 /// By default, performs semantic analysis to build the new expression.
1912 /// Subclasses may override this routine to provide different behavior.
1913 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1914 SourceLocation TypeidLoc,
1915 TypeSourceInfo *Operand,
1916 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001917 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001918 RParenLoc);
1919 }
1920
1921 /// \brief Build a new C++ __uuidof(expr) expression.
1922 ///
1923 /// By default, performs semantic analysis to build the new expression.
1924 /// Subclasses may override this routine to provide different behavior.
1925 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1926 SourceLocation TypeidLoc,
1927 Expr *Operand,
1928 SourceLocation RParenLoc) {
1929 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1930 RParenLoc);
1931 }
1932
Douglas Gregorb98b1992009-08-11 05:31:07 +00001933 /// \brief Build a new C++ "this" expression.
1934 ///
1935 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001936 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001937 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001938 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001939 QualType ThisType,
1940 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001941 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001942 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001943 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1944 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001945 }
1946
1947 /// \brief Build a new C++ throw expression.
1948 ///
1949 /// By default, performs semantic analysis to build the new expression.
1950 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001951 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1952 bool IsThrownVariableInScope) {
1953 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001954 }
1955
1956 /// \brief Build a new C++ default-argument expression.
1957 ///
1958 /// By default, builds a new default-argument expression, which does not
1959 /// require any semantic analysis. Subclasses may override this routine to
1960 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001961 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001962 ParmVarDecl *Param) {
1963 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1964 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001965 }
1966
1967 /// \brief Build a new C++ zero-initialization expression.
1968 ///
1969 /// By default, performs semantic analysis to build the new expression.
1970 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001971 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1972 SourceLocation LParenLoc,
1973 SourceLocation RParenLoc) {
1974 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Benjamin Kramer5354e772012-08-23 23:38:35 +00001975 MultiExprArg(), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001976 }
Mike Stump1eb44332009-09-09 15:08:12 +00001977
Douglas Gregorb98b1992009-08-11 05:31:07 +00001978 /// \brief Build a new C++ "new" expression.
1979 ///
1980 /// By default, performs semantic analysis to build the new expression.
1981 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001982 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001983 bool UseGlobal,
1984 SourceLocation PlacementLParen,
1985 MultiExprArg PlacementArgs,
1986 SourceLocation PlacementRParen,
1987 SourceRange TypeIdParens,
1988 QualType AllocatedType,
1989 TypeSourceInfo *AllocatedTypeInfo,
1990 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001991 SourceRange DirectInitRange,
1992 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001993 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001994 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001995 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001996 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001997 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001998 AllocatedType,
1999 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002000 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002001 DirectInitRange,
2002 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002003 }
Mike Stump1eb44332009-09-09 15:08:12 +00002004
Douglas Gregorb98b1992009-08-11 05:31:07 +00002005 /// \brief Build a new C++ "delete" expression.
2006 ///
2007 /// By default, performs semantic analysis to build the new expression.
2008 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002009 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002010 bool IsGlobalDelete,
2011 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002012 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002013 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002014 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002015 }
Mike Stump1eb44332009-09-09 15:08:12 +00002016
Douglas Gregorb98b1992009-08-11 05:31:07 +00002017 /// \brief Build a new unary type trait expression.
2018 ///
2019 /// By default, performs semantic analysis to build the new expression.
2020 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002021 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002022 SourceLocation StartLoc,
2023 TypeSourceInfo *T,
2024 SourceLocation RParenLoc) {
2025 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002026 }
2027
Francois Pichet6ad6f282010-12-07 00:08:36 +00002028 /// \brief Build a new binary type trait expression.
2029 ///
2030 /// By default, performs semantic analysis to build the new expression.
2031 /// Subclasses may override this routine to provide different behavior.
2032 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2033 SourceLocation StartLoc,
2034 TypeSourceInfo *LhsT,
2035 TypeSourceInfo *RhsT,
2036 SourceLocation RParenLoc) {
2037 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2038 }
2039
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002040 /// \brief Build a new type trait expression.
2041 ///
2042 /// By default, performs semantic analysis to build the new expression.
2043 /// Subclasses may override this routine to provide different behavior.
2044 ExprResult RebuildTypeTrait(TypeTrait Trait,
2045 SourceLocation StartLoc,
2046 ArrayRef<TypeSourceInfo *> Args,
2047 SourceLocation RParenLoc) {
2048 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2049 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002050
John Wiegley21ff2e52011-04-28 00:16:57 +00002051 /// \brief Build a new array type trait expression.
2052 ///
2053 /// By default, performs semantic analysis to build the new expression.
2054 /// Subclasses may override this routine to provide different behavior.
2055 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2056 SourceLocation StartLoc,
2057 TypeSourceInfo *TSInfo,
2058 Expr *DimExpr,
2059 SourceLocation RParenLoc) {
2060 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2061 }
2062
John Wiegley55262202011-04-25 06:54:41 +00002063 /// \brief Build a new expression trait expression.
2064 ///
2065 /// By default, performs semantic analysis to build the new expression.
2066 /// Subclasses may override this routine to provide different behavior.
2067 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2068 SourceLocation StartLoc,
2069 Expr *Queried,
2070 SourceLocation RParenLoc) {
2071 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2072 }
2073
Mike Stump1eb44332009-09-09 15:08:12 +00002074 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002075 /// expression.
2076 ///
2077 /// By default, performs semantic analysis to build the new expression.
2078 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002079 ExprResult RebuildDependentScopeDeclRefExpr(
2080 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002081 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002082 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002083 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002084 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002085 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002086
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002087 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002088 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002089 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002090
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002091 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002092 }
2093
2094 /// \brief Build a new template-id expression.
2095 ///
2096 /// By default, performs semantic analysis to build the new expression.
2097 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002098 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002099 SourceLocation TemplateKWLoc,
2100 LookupResult &R,
2101 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002102 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002103 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2104 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002105 }
2106
2107 /// \brief Build a new object-construction expression.
2108 ///
2109 /// By default, performs semantic analysis to build the new expression.
2110 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002111 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002112 SourceLocation Loc,
2113 CXXConstructorDecl *Constructor,
2114 bool IsElidable,
2115 MultiExprArg Args,
2116 bool HadMultipleCandidates,
2117 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002118 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002119 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002120 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002121 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002122 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002123 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002124
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002125 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002126 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002127 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002128 RequiresZeroInit, ConstructKind,
2129 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002130 }
2131
2132 /// \brief Build a new object-construction expression.
2133 ///
2134 /// By default, performs semantic analysis to build the new expression.
2135 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002136 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2137 SourceLocation LParenLoc,
2138 MultiExprArg Args,
2139 SourceLocation RParenLoc) {
2140 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002141 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002142 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002143 RParenLoc);
2144 }
2145
2146 /// \brief Build a new object-construction expression.
2147 ///
2148 /// By default, performs semantic analysis to build the new expression.
2149 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002150 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2151 SourceLocation LParenLoc,
2152 MultiExprArg Args,
2153 SourceLocation RParenLoc) {
2154 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002155 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002156 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002157 RParenLoc);
2158 }
Mike Stump1eb44332009-09-09 15:08:12 +00002159
Douglas Gregorb98b1992009-08-11 05:31:07 +00002160 /// \brief Build a new member reference expression.
2161 ///
2162 /// By default, performs semantic analysis to build the new expression.
2163 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002164 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002165 QualType BaseType,
2166 bool IsArrow,
2167 SourceLocation OperatorLoc,
2168 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002169 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002170 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002171 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002172 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002173 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002174 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002175
John McCall9ae2f072010-08-23 23:25:46 +00002176 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002177 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002178 SS, TemplateKWLoc,
2179 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002180 MemberNameInfo,
2181 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002182 }
2183
John McCall129e2df2009-11-30 22:42:35 +00002184 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002185 ///
2186 /// By default, performs semantic analysis to build the new expression.
2187 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002188 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2189 SourceLocation OperatorLoc,
2190 bool IsArrow,
2191 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002192 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002193 NamedDecl *FirstQualifierInScope,
2194 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002195 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002196 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002197 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002198
John McCall9ae2f072010-08-23 23:25:46 +00002199 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002200 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002201 SS, TemplateKWLoc,
2202 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002203 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002204 }
Mike Stump1eb44332009-09-09 15:08:12 +00002205
Sebastian Redl2e156222010-09-10 20:55:43 +00002206 /// \brief Build a new noexcept expression.
2207 ///
2208 /// By default, performs semantic analysis to build the new expression.
2209 /// Subclasses may override this routine to provide different behavior.
2210 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2211 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2212 }
2213
Douglas Gregoree8aff02011-01-04 17:33:58 +00002214 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002215 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2216 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002217 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002218 llvm::Optional<unsigned> Length) {
2219 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002220 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2221 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002222 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002223
2224 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2225 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002226 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002227 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002228
Patrick Beardeb382ec2012-04-19 00:25:12 +00002229 /// \brief Build a new Objective-C boxed expression.
2230 ///
2231 /// By default, performs semantic analysis to build the new expression.
2232 /// Subclasses may override this routine to provide different behavior.
2233 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2234 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2235 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002236
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002237 /// \brief Build a new Objective-C array literal.
2238 ///
2239 /// By default, performs semantic analysis to build the new expression.
2240 /// Subclasses may override this routine to provide different behavior.
2241 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2242 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002243 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002244 MultiExprArg(Elements, NumElements));
2245 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002246
2247 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002248 Expr *Base, Expr *Key,
2249 ObjCMethodDecl *getterMethod,
2250 ObjCMethodDecl *setterMethod) {
2251 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2252 getterMethod, setterMethod);
2253 }
2254
2255 /// \brief Build a new Objective-C dictionary literal.
2256 ///
2257 /// By default, performs semantic analysis to build the new expression.
2258 /// Subclasses may override this routine to provide different behavior.
2259 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2260 ObjCDictionaryElement *Elements,
2261 unsigned NumElements) {
2262 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2263 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002264
James Dennett699c9042012-06-15 07:13:21 +00002265 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002266 ///
2267 /// By default, performs semantic analysis to build the new expression.
2268 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002269 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002270 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002271 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002272 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002273 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002274 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002275
Douglas Gregor92e986e2010-04-22 16:44:27 +00002276 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002277 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002278 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002279 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002280 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002281 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002282 MultiExprArg Args,
2283 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002284 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2285 ReceiverTypeInfo->getType(),
2286 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002287 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002288 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002289 }
2290
2291 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002292 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002293 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002294 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002295 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002296 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002297 MultiExprArg Args,
2298 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002299 return SemaRef.BuildInstanceMessage(Receiver,
2300 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002301 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002302 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002303 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002304 }
2305
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002306 /// \brief Build a new Objective-C ivar reference expression.
2307 ///
2308 /// By default, performs semantic analysis to build the new expression.
2309 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002310 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002311 SourceLocation IvarLoc,
2312 bool IsArrow, bool IsFreeIvar) {
2313 // FIXME: We lose track of the IsFreeIvar bit.
2314 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002315 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002316 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2317 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002318 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002319 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002320 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002321 false);
John Wiegley429bb272011-04-08 18:41:53 +00002322 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002323 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002324
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002325 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002326 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002327
John Wiegley429bb272011-04-08 18:41:53 +00002328 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002329 /*FIXME:*/IvarLoc, IsArrow,
2330 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002331 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002332 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002333 /*TemplateArgs=*/0);
2334 }
Douglas Gregore3303542010-04-26 20:47:02 +00002335
2336 /// \brief Build a new Objective-C property reference expression.
2337 ///
2338 /// By default, performs semantic analysis to build the new expression.
2339 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002340 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002341 ObjCPropertyDecl *Property,
2342 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002343 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002344 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002345 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2346 Sema::LookupMemberName);
2347 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002348 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002349 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002350 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002351 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002352 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002353
Douglas Gregore3303542010-04-26 20:47:02 +00002354 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002355 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002356
John Wiegley429bb272011-04-08 18:41:53 +00002357 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002358 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002359 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002360 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002361 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002362 /*TemplateArgs=*/0);
2363 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002364
John McCall12f78a62010-12-02 01:19:52 +00002365 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002366 ///
2367 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002368 /// Subclasses may override this routine to provide different behavior.
2369 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2370 ObjCMethodDecl *Getter,
2371 ObjCMethodDecl *Setter,
2372 SourceLocation PropertyLoc) {
2373 // Since these expressions can only be value-dependent, we do not
2374 // need to perform semantic analysis again.
2375 return Owned(
2376 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2377 VK_LValue, OK_ObjCProperty,
2378 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002379 }
2380
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002381 /// \brief Build a new Objective-C "isa" expression.
2382 ///
2383 /// By default, performs semantic analysis to build the new expression.
2384 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002385 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002386 bool IsArrow) {
2387 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002388 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002389 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2390 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002391 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002392 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002393 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002394 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002395 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002396
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002397 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002398 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002399
John Wiegley429bb272011-04-08 18:41:53 +00002400 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002401 /*FIXME:*/IsaLoc, IsArrow,
2402 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002403 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002404 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002405 /*TemplateArgs=*/0);
2406 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002407
Douglas Gregorb98b1992009-08-11 05:31:07 +00002408 /// \brief Build a new shuffle vector expression.
2409 ///
2410 /// By default, performs semantic analysis to build the new expression.
2411 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002412 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002413 MultiExprArg SubExprs,
2414 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002415 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002416 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002417 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2418 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2419 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2420 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002421
Douglas Gregorb98b1992009-08-11 05:31:07 +00002422 // Build a reference to the __builtin_shufflevector builtin
2423 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002424 ExprResult Callee
John McCallf4b88a42012-03-10 09:33:50 +00002425 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false,
2426 Builtin->getType(),
John Wiegley429bb272011-04-08 18:41:53 +00002427 VK_LValue, BuiltinLoc));
2428 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2429 if (Callee.isInvalid())
2430 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002431
2432 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002433 unsigned NumSubExprs = SubExprs.size();
Benjamin Kramer5354e772012-08-23 23:38:35 +00002434 Expr **Subs = SubExprs.data();
John Wiegley429bb272011-04-08 18:41:53 +00002435 ExprResult TheCall = SemaRef.Owned(
2436 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002437 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002438 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002439 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002440 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002441
Douglas Gregorb98b1992009-08-11 05:31:07 +00002442 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002443 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002444 }
John McCall43fed0d2010-11-12 08:19:04 +00002445
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002446 /// \brief Build a new template argument pack expansion.
2447 ///
2448 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002449 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002450 /// different behavior.
2451 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002452 SourceLocation EllipsisLoc,
2453 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002454 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002455 case TemplateArgument::Expression: {
2456 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002457 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2458 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002459 if (Result.isInvalid())
2460 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002461
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002462 return TemplateArgumentLoc(Result.get(), Result.get());
2463 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002464
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002465 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002466 return TemplateArgumentLoc(TemplateArgument(
2467 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002468 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002469 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002470 Pattern.getTemplateNameLoc(),
2471 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002472
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002473 case TemplateArgument::Null:
2474 case TemplateArgument::Integral:
2475 case TemplateArgument::Declaration:
2476 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002477 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002478 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002479
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002480 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002481 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002482 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002483 EllipsisLoc,
2484 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002485 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2486 Expansion);
2487 break;
2488 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002489
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002490 return TemplateArgumentLoc();
2491 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002492
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002493 /// \brief Build a new expression pack expansion.
2494 ///
2495 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002496 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002497 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002498 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2499 llvm::Optional<unsigned> NumExpansions) {
2500 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002501 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002502
2503 /// \brief Build a new atomic operation expression.
2504 ///
2505 /// By default, performs semantic analysis to build the new expression.
2506 /// Subclasses may override this routine to provide different behavior.
2507 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2508 MultiExprArg SubExprs,
2509 QualType RetTy,
2510 AtomicExpr::AtomicOp Op,
2511 SourceLocation RParenLoc) {
2512 // Just create the expression; there is not any interesting semantic
2513 // analysis here because we can't actually build an AtomicExpr until
2514 // we are sure it is semantically sound.
2515 unsigned NumSubExprs = SubExprs.size();
Benjamin Kramer5354e772012-08-23 23:38:35 +00002516 Expr **Subs = SubExprs.data();
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002517 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2518 NumSubExprs, RetTy, Op,
2519 RParenLoc);
2520 }
2521
John McCall43fed0d2010-11-12 08:19:04 +00002522private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002523 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2524 QualType ObjectType,
2525 NamedDecl *FirstQualifierInScope,
2526 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002527
2528 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2529 QualType ObjectType,
2530 NamedDecl *FirstQualifierInScope,
2531 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002532};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002533
Douglas Gregor43959a92009-08-20 07:17:43 +00002534template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002535StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002536 if (!S)
2537 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002538
Douglas Gregor43959a92009-08-20 07:17:43 +00002539 switch (S->getStmtClass()) {
2540 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002541
Douglas Gregor43959a92009-08-20 07:17:43 +00002542 // Transform individual statement nodes
2543#define STMT(Node, Parent) \
2544 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002545#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002546#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002547#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002548
Douglas Gregor43959a92009-08-20 07:17:43 +00002549 // Transform expressions by calling TransformExpr.
2550#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002551#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002552#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002553#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002554 {
John McCall60d7b3a2010-08-24 06:29:42 +00002555 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002556 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002557 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002558
John McCall9ae2f072010-08-23 23:25:46 +00002559 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002560 }
Mike Stump1eb44332009-09-09 15:08:12 +00002561 }
2562
John McCall3fa5cae2010-10-26 07:05:15 +00002563 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002564}
Mike Stump1eb44332009-09-09 15:08:12 +00002565
2566
Douglas Gregor670444e2009-08-04 22:27:00 +00002567template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002568ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002569 if (!E)
2570 return SemaRef.Owned(E);
2571
2572 switch (E->getStmtClass()) {
2573 case Stmt::NoStmtClass: break;
2574#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002575#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002576#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002577 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002578#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002579 }
2580
John McCall3fa5cae2010-10-26 07:05:15 +00002581 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002582}
2583
2584template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002585bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2586 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002587 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002588 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002589 bool *ArgChanged) {
2590 for (unsigned I = 0; I != NumInputs; ++I) {
2591 // If requested, drop call arguments that need to be dropped.
2592 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2593 if (ArgChanged)
2594 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002595
Douglas Gregoraa165f82011-01-03 19:04:46 +00002596 break;
2597 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002598
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002599 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2600 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002601
Chris Lattner686775d2011-07-20 06:58:45 +00002602 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002603 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2604 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002605
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002606 // Determine whether the set of unexpanded parameter packs can and should
2607 // be expanded.
2608 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002609 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002610 llvm::Optional<unsigned> OrigNumExpansions
2611 = Expansion->getNumExpansions();
2612 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002613 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2614 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002615 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002616 Expand, RetainExpansion,
2617 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002618 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002619
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002620 if (!Expand) {
2621 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002622 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002623 // expansion.
2624 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2625 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2626 if (OutPattern.isInvalid())
2627 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002628
2629 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002630 Expansion->getEllipsisLoc(),
2631 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002632 if (Out.isInvalid())
2633 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002634
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002635 if (ArgChanged)
2636 *ArgChanged = true;
2637 Outputs.push_back(Out.get());
2638 continue;
2639 }
John McCallc8fc90a2011-07-06 07:30:07 +00002640
2641 // Record right away that the argument was changed. This needs
2642 // to happen even if the array expands to nothing.
2643 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002644
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002645 // The transform has determined that we should perform an elementwise
2646 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002647 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002648 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2649 ExprResult Out = getDerived().TransformExpr(Pattern);
2650 if (Out.isInvalid())
2651 return true;
2652
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002653 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002654 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2655 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002656 if (Out.isInvalid())
2657 return true;
2658 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002659
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002660 Outputs.push_back(Out.get());
2661 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002662
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002663 continue;
2664 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002665
Douglas Gregoraa165f82011-01-03 19:04:46 +00002666 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2667 if (Result.isInvalid())
2668 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002669
Douglas Gregoraa165f82011-01-03 19:04:46 +00002670 if (Result.get() != Inputs[I] && ArgChanged)
2671 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002672
2673 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002674 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002675
Douglas Gregoraa165f82011-01-03 19:04:46 +00002676 return false;
2677}
2678
2679template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002680NestedNameSpecifierLoc
2681TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2682 NestedNameSpecifierLoc NNS,
2683 QualType ObjectType,
2684 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002685 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002686 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002687 Qualifier = Qualifier.getPrefix())
2688 Qualifiers.push_back(Qualifier);
2689
2690 CXXScopeSpec SS;
2691 while (!Qualifiers.empty()) {
2692 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2693 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002694
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002695 switch (QNNS->getKind()) {
2696 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002697 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002698 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002699 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002700 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002701 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002702 FirstQualifierInScope, false))
2703 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002704
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002705 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002706
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002707 case NestedNameSpecifier::Namespace: {
2708 NamespaceDecl *NS
2709 = cast_or_null<NamespaceDecl>(
2710 getDerived().TransformDecl(
2711 Q.getLocalBeginLoc(),
2712 QNNS->getAsNamespace()));
2713 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2714 break;
2715 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002716
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002717 case NestedNameSpecifier::NamespaceAlias: {
2718 NamespaceAliasDecl *Alias
2719 = cast_or_null<NamespaceAliasDecl>(
2720 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2721 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002722 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002723 Q.getLocalEndLoc());
2724 break;
2725 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002726
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002727 case NestedNameSpecifier::Global:
2728 // There is no meaningful transformation that one could perform on the
2729 // global scope.
2730 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2731 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002732
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002733 case NestedNameSpecifier::TypeSpecWithTemplate:
2734 case NestedNameSpecifier::TypeSpec: {
2735 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2736 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002737
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002738 if (!TL)
2739 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002740
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002741 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00002742 (SemaRef.getLangOpts().CPlusPlus0x &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002743 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002744 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002745 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002746 if (TL.getType()->isEnumeralType())
2747 SemaRef.Diag(TL.getBeginLoc(),
2748 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002749 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2750 Q.getLocalEndLoc());
2751 break;
2752 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002753 // If the nested-name-specifier is an invalid type def, don't emit an
2754 // error because a previous error should have already been emitted.
2755 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2756 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002757 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002758 << TL.getType() << SS.getRange();
2759 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002760 return NestedNameSpecifierLoc();
2761 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002762 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002763
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002764 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002765 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002766 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002767 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002768
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002769 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002770 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002771 !getDerived().AlwaysRebuild())
2772 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002773
2774 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002775 // nested-name-specifier, do so.
2776 if (SS.location_size() == NNS.getDataLength() &&
2777 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2778 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2779
2780 // Allocate new nested-name-specifier location information.
2781 return SS.getWithLocInContext(SemaRef.Context);
2782}
2783
2784template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002785DeclarationNameInfo
2786TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002787::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002788 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002789 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002790 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002791
2792 switch (Name.getNameKind()) {
2793 case DeclarationName::Identifier:
2794 case DeclarationName::ObjCZeroArgSelector:
2795 case DeclarationName::ObjCOneArgSelector:
2796 case DeclarationName::ObjCMultiArgSelector:
2797 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002798 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002799 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002800 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002801
Douglas Gregor81499bb2009-09-03 22:13:48 +00002802 case DeclarationName::CXXConstructorName:
2803 case DeclarationName::CXXDestructorName:
2804 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002805 TypeSourceInfo *NewTInfo;
2806 CanQualType NewCanTy;
2807 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002808 NewTInfo = getDerived().TransformType(OldTInfo);
2809 if (!NewTInfo)
2810 return DeclarationNameInfo();
2811 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002812 }
2813 else {
2814 NewTInfo = 0;
2815 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002816 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002817 if (NewT.isNull())
2818 return DeclarationNameInfo();
2819 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2820 }
Mike Stump1eb44332009-09-09 15:08:12 +00002821
Abramo Bagnara25777432010-08-11 22:01:17 +00002822 DeclarationName NewName
2823 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2824 NewCanTy);
2825 DeclarationNameInfo NewNameInfo(NameInfo);
2826 NewNameInfo.setName(NewName);
2827 NewNameInfo.setNamedTypeInfo(NewTInfo);
2828 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002829 }
Mike Stump1eb44332009-09-09 15:08:12 +00002830 }
2831
David Blaikieb219cfc2011-09-23 05:06:16 +00002832 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002833}
2834
2835template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002836TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002837TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2838 TemplateName Name,
2839 SourceLocation NameLoc,
2840 QualType ObjectType,
2841 NamedDecl *FirstQualifierInScope) {
2842 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2843 TemplateDecl *Template = QTN->getTemplateDecl();
2844 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002845
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002846 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002847 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002848 Template));
2849 if (!TransTemplate)
2850 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002851
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002852 if (!getDerived().AlwaysRebuild() &&
2853 SS.getScopeRep() == QTN->getQualifier() &&
2854 TransTemplate == Template)
2855 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002856
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002857 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2858 TransTemplate);
2859 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002860
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002861 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2862 if (SS.getScopeRep()) {
2863 // These apply to the scope specifier, not the template.
2864 ObjectType = QualType();
2865 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002866 }
2867
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002868 if (!getDerived().AlwaysRebuild() &&
2869 SS.getScopeRep() == DTN->getQualifier() &&
2870 ObjectType.isNull())
2871 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002872
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002873 if (DTN->isIdentifier()) {
2874 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002875 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002876 NameLoc,
2877 ObjectType,
2878 FirstQualifierInScope);
2879 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002880
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002881 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2882 ObjectType);
2883 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002884
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002885 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2886 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002887 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002888 Template));
2889 if (!TransTemplate)
2890 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002891
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002892 if (!getDerived().AlwaysRebuild() &&
2893 TransTemplate == Template)
2894 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002895
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002896 return TemplateName(TransTemplate);
2897 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002898
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002899 if (SubstTemplateTemplateParmPackStorage *SubstPack
2900 = Name.getAsSubstTemplateTemplateParmPack()) {
2901 TemplateTemplateParmDecl *TransParam
2902 = cast_or_null<TemplateTemplateParmDecl>(
2903 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2904 if (!TransParam)
2905 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002906
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002907 if (!getDerived().AlwaysRebuild() &&
2908 TransParam == SubstPack->getParameterPack())
2909 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002910
2911 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002912 SubstPack->getArgumentPack());
2913 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002914
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002915 // These should be getting filtered out before they reach the AST.
2916 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002917}
2918
2919template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002920void TreeTransform<Derived>::InventTemplateArgumentLoc(
2921 const TemplateArgument &Arg,
2922 TemplateArgumentLoc &Output) {
2923 SourceLocation Loc = getDerived().getBaseLocation();
2924 switch (Arg.getKind()) {
2925 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002926 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002927 break;
2928
2929 case TemplateArgument::Type:
2930 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002931 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002932
John McCall833ca992009-10-29 08:12:44 +00002933 break;
2934
Douglas Gregor788cd062009-11-11 01:00:40 +00002935 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002936 case TemplateArgument::TemplateExpansion: {
2937 NestedNameSpecifierLocBuilder Builder;
2938 TemplateName Template = Arg.getAsTemplate();
2939 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2940 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2941 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2942 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002943
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002944 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002945 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002946 Builder.getWithLocInContext(SemaRef.Context),
2947 Loc);
2948 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00002949 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002950 Builder.getWithLocInContext(SemaRef.Context),
2951 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002952
Douglas Gregor788cd062009-11-11 01:00:40 +00002953 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002954 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002955
John McCall833ca992009-10-29 08:12:44 +00002956 case TemplateArgument::Expression:
2957 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2958 break;
2959
2960 case TemplateArgument::Declaration:
2961 case TemplateArgument::Integral:
2962 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002963 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002964 break;
2965 }
2966}
2967
2968template<typename Derived>
2969bool TreeTransform<Derived>::TransformTemplateArgument(
2970 const TemplateArgumentLoc &Input,
2971 TemplateArgumentLoc &Output) {
2972 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002973 switch (Arg.getKind()) {
2974 case TemplateArgument::Null:
2975 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002976 Output = Input;
2977 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002978
Douglas Gregor670444e2009-08-04 22:27:00 +00002979 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002980 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002981 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002982 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002983
2984 DI = getDerived().TransformType(DI);
2985 if (!DI) return true;
2986
2987 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2988 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002989 }
Mike Stump1eb44332009-09-09 15:08:12 +00002990
Douglas Gregor670444e2009-08-04 22:27:00 +00002991 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002992 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002993 DeclarationName Name;
2994 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2995 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002996 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002997 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002998 if (!D) return true;
2999
John McCall828bff22009-10-29 18:45:58 +00003000 Expr *SourceExpr = Input.getSourceDeclExpression();
3001 if (SourceExpr) {
3002 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003003 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00003004 ExprResult E = getDerived().TransformExpr(SourceExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003005 E = SemaRef.ActOnConstantExpression(E);
John McCall9ae2f072010-08-23 23:25:46 +00003006 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00003007 }
3008
3009 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00003010 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003011 }
Mike Stump1eb44332009-09-09 15:08:12 +00003012
Douglas Gregor788cd062009-11-11 01:00:40 +00003013 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003014 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3015 if (QualifierLoc) {
3016 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3017 if (!QualifierLoc)
3018 return true;
3019 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003020
Douglas Gregor1d752d72011-03-02 18:46:51 +00003021 CXXScopeSpec SS;
3022 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003023 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003024 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3025 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003026 if (Template.isNull())
3027 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003028
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003029 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003030 Input.getTemplateNameLoc());
3031 return false;
3032 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003033
3034 case TemplateArgument::TemplateExpansion:
3035 llvm_unreachable("Caller should expand pack expansions");
3036
Douglas Gregor670444e2009-08-04 22:27:00 +00003037 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003038 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003039 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003040 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003041
John McCall833ca992009-10-29 08:12:44 +00003042 Expr *InputExpr = Input.getSourceExpression();
3043 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3044
Chris Lattner223de242011-04-25 20:37:58 +00003045 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003046 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003047 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003048 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003049 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003050 }
Mike Stump1eb44332009-09-09 15:08:12 +00003051
Douglas Gregor670444e2009-08-04 22:27:00 +00003052 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00003053 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00003054 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00003055 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00003056 AEnd = Arg.pack_end();
3057 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00003058
John McCall833ca992009-10-29 08:12:44 +00003059 // FIXME: preserve source information here when we start
3060 // caring about parameter packs.
3061
John McCall828bff22009-10-29 18:45:58 +00003062 TemplateArgumentLoc InputArg;
3063 TemplateArgumentLoc OutputArg;
3064 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3065 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00003066 return true;
3067
John McCall828bff22009-10-29 18:45:58 +00003068 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00003069 }
Douglas Gregor910f8002010-11-07 23:05:16 +00003070
3071 TemplateArgument *TransformedArgsPtr
3072 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3073 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3074 TransformedArgsPtr);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003075 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3076 TransformedArgs.size()),
Douglas Gregor910f8002010-11-07 23:05:16 +00003077 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003078 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003079 }
3080 }
Mike Stump1eb44332009-09-09 15:08:12 +00003081
Douglas Gregor670444e2009-08-04 22:27:00 +00003082 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003083 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003084}
3085
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003086/// \brief Iterator adaptor that invents template argument location information
3087/// for each of the template arguments in its underlying iterator.
3088template<typename Derived, typename InputIterator>
3089class TemplateArgumentLocInventIterator {
3090 TreeTransform<Derived> &Self;
3091 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003092
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003093public:
3094 typedef TemplateArgumentLoc value_type;
3095 typedef TemplateArgumentLoc reference;
3096 typedef typename std::iterator_traits<InputIterator>::difference_type
3097 difference_type;
3098 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003099
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003100 class pointer {
3101 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003102
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003103 public:
3104 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003105
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003106 const TemplateArgumentLoc *operator->() const { return &Arg; }
3107 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003108
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003109 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003110
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003111 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3112 InputIterator Iter)
3113 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003114
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003115 TemplateArgumentLocInventIterator &operator++() {
3116 ++Iter;
3117 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003118 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003119
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003120 TemplateArgumentLocInventIterator operator++(int) {
3121 TemplateArgumentLocInventIterator Old(*this);
3122 ++(*this);
3123 return Old;
3124 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003125
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003126 reference operator*() const {
3127 TemplateArgumentLoc Result;
3128 Self.InventTemplateArgumentLoc(*Iter, Result);
3129 return Result;
3130 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003131
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003132 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003133
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003134 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3135 const TemplateArgumentLocInventIterator &Y) {
3136 return X.Iter == Y.Iter;
3137 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003138
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003139 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3140 const TemplateArgumentLocInventIterator &Y) {
3141 return X.Iter != Y.Iter;
3142 }
3143};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003144
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003145template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003146template<typename InputIterator>
3147bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3148 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003149 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003150 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003151 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003152 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003153
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003154 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3155 // Unpack argument packs, which we translate them into separate
3156 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003157 // FIXME: We could do much better if we could guarantee that the
3158 // TemplateArgumentLocInfo for the pack expansion would be usable for
3159 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003160 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003161 TemplateArgument::pack_iterator>
3162 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003163 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003164 In.getArgument().pack_begin()),
3165 PackLocIterator(*this,
3166 In.getArgument().pack_end()),
3167 Outputs))
3168 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003169
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003170 continue;
3171 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003172
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003173 if (In.getArgument().isPackExpansion()) {
3174 // We have a pack expansion, for which we will be substituting into
3175 // the pattern.
3176 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003177 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003178 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003179 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003180 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003181
Chris Lattner686775d2011-07-20 06:58:45 +00003182 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003183 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3184 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003185
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003186 // Determine whether the set of unexpanded parameter packs can and should
3187 // be expanded.
3188 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003189 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003190 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003191 if (getDerived().TryExpandParameterPacks(Ellipsis,
3192 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003193 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003194 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003195 RetainExpansion,
3196 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003197 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003198
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003199 if (!Expand) {
3200 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003201 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003202 // expansion.
3203 TemplateArgumentLoc OutPattern;
3204 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3205 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3206 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003207
Douglas Gregorcded4f62011-01-14 17:04:44 +00003208 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3209 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003210 if (Out.getArgument().isNull())
3211 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003212
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003213 Outputs.addArgument(Out);
3214 continue;
3215 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003216
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003217 // The transform has determined that we should perform an elementwise
3218 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003219 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003220 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3221
3222 if (getDerived().TransformTemplateArgument(Pattern, Out))
3223 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003224
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003225 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003226 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3227 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003228 if (Out.getArgument().isNull())
3229 return true;
3230 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003231
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003232 Outputs.addArgument(Out);
3233 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003234
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003235 // If we're supposed to retain a pack expansion, do so by temporarily
3236 // forgetting the partially-substituted parameter pack.
3237 if (RetainExpansion) {
3238 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003239
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003240 if (getDerived().TransformTemplateArgument(Pattern, Out))
3241 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003242
Douglas Gregorcded4f62011-01-14 17:04:44 +00003243 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3244 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003245 if (Out.getArgument().isNull())
3246 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003247
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003248 Outputs.addArgument(Out);
3249 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003250
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003251 continue;
3252 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003253
3254 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003255 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003256 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003257
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003258 Outputs.addArgument(Out);
3259 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003260
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003261 return false;
3262
3263}
3264
Douglas Gregor577f75a2009-08-04 16:50:30 +00003265//===----------------------------------------------------------------------===//
3266// Type transformation
3267//===----------------------------------------------------------------------===//
3268
3269template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003270QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003271 if (getDerived().AlreadyTransformed(T))
3272 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003273
John McCalla2becad2009-10-21 00:40:46 +00003274 // Temporary workaround. All of these transformations should
3275 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003276 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3277 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003278
John McCall43fed0d2010-11-12 08:19:04 +00003279 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003280
John McCalla2becad2009-10-21 00:40:46 +00003281 if (!NewDI)
3282 return QualType();
3283
3284 return NewDI->getType();
3285}
3286
3287template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003288TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003289 // Refine the base location to the type's location.
3290 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3291 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003292 if (getDerived().AlreadyTransformed(DI->getType()))
3293 return DI;
3294
3295 TypeLocBuilder TLB;
3296
3297 TypeLoc TL = DI->getTypeLoc();
3298 TLB.reserve(TL.getFullDataSize());
3299
John McCall43fed0d2010-11-12 08:19:04 +00003300 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003301 if (Result.isNull())
3302 return 0;
3303
John McCalla93c9342009-12-07 02:54:59 +00003304 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003305}
3306
3307template<typename Derived>
3308QualType
John McCall43fed0d2010-11-12 08:19:04 +00003309TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003310 switch (T.getTypeLocClass()) {
3311#define ABSTRACT_TYPELOC(CLASS, PARENT)
3312#define TYPELOC(CLASS, PARENT) \
3313 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003314 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003315#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003316 }
Mike Stump1eb44332009-09-09 15:08:12 +00003317
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003318 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003319}
3320
3321/// FIXME: By default, this routine adds type qualifiers only to types
3322/// that can have qualifiers, and silently suppresses those qualifiers
3323/// that are not permitted (e.g., qualifiers on reference or function
3324/// types). This is the right thing for template instantiation, but
3325/// probably not for other clients.
3326template<typename Derived>
3327QualType
3328TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003329 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003330 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003331
John McCall43fed0d2010-11-12 08:19:04 +00003332 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003333 if (Result.isNull())
3334 return QualType();
3335
3336 // Silently suppress qualifiers if the result type can't be qualified.
3337 // FIXME: this is the right thing for template instantiation, but
3338 // probably not for other clients.
3339 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003340 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003341
John McCallf85e1932011-06-15 23:02:42 +00003342 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003343 // resulting type.
3344 if (Quals.hasObjCLifetime()) {
3345 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3346 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003347 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003348 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003349 // A lifetime qualifier applied to a substituted template parameter
3350 // overrides the lifetime qualifier from the template argument.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003351 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003352 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3353 QualType Replacement = SubstTypeParam->getReplacementType();
3354 Qualifiers Qs = Replacement.getQualifiers();
3355 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003356 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003357 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3358 Qs);
3359 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003360 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003361 Replacement);
3362 TLB.TypeWasModifiedSafely(Result);
3363 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003364 // Otherwise, complain about the addition of a qualifier to an
3365 // already-qualified type.
3366 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003367 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003368 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003369
Douglas Gregore559ca12011-06-17 22:11:49 +00003370 Quals.removeObjCLifetime();
3371 }
3372 }
3373 }
John McCall28654742010-06-05 06:41:15 +00003374 if (!Quals.empty()) {
3375 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3376 TLB.push<QualifiedTypeLoc>(Result);
3377 // No location information to preserve.
3378 }
John McCalla2becad2009-10-21 00:40:46 +00003379
3380 return Result;
3381}
3382
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003383template<typename Derived>
3384TypeLoc
3385TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3386 QualType ObjectType,
3387 NamedDecl *UnqualLookup,
3388 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003389 QualType T = TL.getType();
3390 if (getDerived().AlreadyTransformed(T))
3391 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003392
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003393 TypeLocBuilder TLB;
3394 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003395
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003396 if (isa<TemplateSpecializationType>(T)) {
3397 TemplateSpecializationTypeLoc SpecTL
3398 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003399
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003400 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003401 getDerived().TransformTemplateName(SS,
3402 SpecTL.getTypePtr()->getTemplateName(),
3403 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003404 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003405 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003406 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003407
3408 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003409 Template);
3410 } else if (isa<DependentTemplateSpecializationType>(T)) {
3411 DependentTemplateSpecializationTypeLoc SpecTL
3412 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003413
Douglas Gregora88f09f2011-02-28 17:23:35 +00003414 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003415 = getDerived().RebuildTemplateName(SS,
3416 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003417 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003418 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003419 if (Template.isNull())
3420 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003421
3422 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003423 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003424 Template,
3425 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003426 } else {
3427 // Nothing special needs to be done for these.
3428 Result = getDerived().TransformType(TLB, TL);
3429 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003430
3431 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003432 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003433
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003434 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3435}
3436
Douglas Gregorb71d8212011-03-02 18:32:08 +00003437template<typename Derived>
3438TypeSourceInfo *
3439TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3440 QualType ObjectType,
3441 NamedDecl *UnqualLookup,
3442 CXXScopeSpec &SS) {
3443 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003444
Douglas Gregorb71d8212011-03-02 18:32:08 +00003445 QualType T = TSInfo->getType();
3446 if (getDerived().AlreadyTransformed(T))
3447 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003448
Douglas Gregorb71d8212011-03-02 18:32:08 +00003449 TypeLocBuilder TLB;
3450 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003451
Douglas Gregorb71d8212011-03-02 18:32:08 +00003452 TypeLoc TL = TSInfo->getTypeLoc();
3453 if (isa<TemplateSpecializationType>(T)) {
3454 TemplateSpecializationTypeLoc SpecTL
3455 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003456
Douglas Gregorb71d8212011-03-02 18:32:08 +00003457 TemplateName Template
3458 = getDerived().TransformTemplateName(SS,
3459 SpecTL.getTypePtr()->getTemplateName(),
3460 SpecTL.getTemplateNameLoc(),
3461 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003462 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003463 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003464
3465 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003466 Template);
3467 } else if (isa<DependentTemplateSpecializationType>(T)) {
3468 DependentTemplateSpecializationTypeLoc SpecTL
3469 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003470
Douglas Gregorb71d8212011-03-02 18:32:08 +00003471 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003472 = getDerived().RebuildTemplateName(SS,
3473 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003474 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003475 ObjectType, UnqualLookup);
3476 if (Template.isNull())
3477 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003478
3479 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003480 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003481 Template,
3482 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003483 } else {
3484 // Nothing special needs to be done for these.
3485 Result = getDerived().TransformType(TLB, TL);
3486 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003487
3488 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003489 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003490
Douglas Gregorb71d8212011-03-02 18:32:08 +00003491 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3492}
3493
John McCalla2becad2009-10-21 00:40:46 +00003494template <class TyLoc> static inline
3495QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3496 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3497 NewT.setNameLoc(T.getNameLoc());
3498 return T.getType();
3499}
3500
John McCalla2becad2009-10-21 00:40:46 +00003501template<typename Derived>
3502QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003503 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003504 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3505 NewT.setBuiltinLoc(T.getBuiltinLoc());
3506 if (T.needsExtraLocalData())
3507 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3508 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003509}
Mike Stump1eb44332009-09-09 15:08:12 +00003510
Douglas Gregor577f75a2009-08-04 16:50:30 +00003511template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003512QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003513 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003514 // FIXME: recurse?
3515 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003516}
Mike Stump1eb44332009-09-09 15:08:12 +00003517
Douglas Gregor577f75a2009-08-04 16:50:30 +00003518template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003519QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003520 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003521 QualType PointeeType
3522 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003523 if (PointeeType.isNull())
3524 return QualType();
3525
3526 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003527 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003528 // A dependent pointer type 'T *' has is being transformed such
3529 // that an Objective-C class type is being replaced for 'T'. The
3530 // resulting pointer type is an ObjCObjectPointerType, not a
3531 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003532 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003533
John McCallc12c5bb2010-05-15 11:32:37 +00003534 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3535 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003536 return Result;
3537 }
John McCall43fed0d2010-11-12 08:19:04 +00003538
Douglas Gregor92e986e2010-04-22 16:44:27 +00003539 if (getDerived().AlwaysRebuild() ||
3540 PointeeType != TL.getPointeeLoc().getType()) {
3541 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3542 if (Result.isNull())
3543 return QualType();
3544 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003545
John McCallf85e1932011-06-15 23:02:42 +00003546 // Objective-C ARC can add lifetime qualifiers to the type that we're
3547 // pointing to.
3548 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003549
Douglas Gregor92e986e2010-04-22 16:44:27 +00003550 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3551 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003552 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003553}
Mike Stump1eb44332009-09-09 15:08:12 +00003554
3555template<typename Derived>
3556QualType
John McCalla2becad2009-10-21 00:40:46 +00003557TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003558 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003559 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003560 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3561 if (PointeeType.isNull())
3562 return QualType();
3563
3564 QualType Result = TL.getType();
3565 if (getDerived().AlwaysRebuild() ||
3566 PointeeType != TL.getPointeeLoc().getType()) {
3567 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003568 TL.getSigilLoc());
3569 if (Result.isNull())
3570 return QualType();
3571 }
3572
Douglas Gregor39968ad2010-04-22 16:50:51 +00003573 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003574 NewT.setSigilLoc(TL.getSigilLoc());
3575 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003576}
3577
John McCall85737a72009-10-30 00:06:24 +00003578/// Transforms a reference type. Note that somewhat paradoxically we
3579/// don't care whether the type itself is an l-value type or an r-value
3580/// type; we only care if the type was *written* as an l-value type
3581/// or an r-value type.
3582template<typename Derived>
3583QualType
3584TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003585 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003586 const ReferenceType *T = TL.getTypePtr();
3587
3588 // Note that this works with the pointee-as-written.
3589 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3590 if (PointeeType.isNull())
3591 return QualType();
3592
3593 QualType Result = TL.getType();
3594 if (getDerived().AlwaysRebuild() ||
3595 PointeeType != T->getPointeeTypeAsWritten()) {
3596 Result = getDerived().RebuildReferenceType(PointeeType,
3597 T->isSpelledAsLValue(),
3598 TL.getSigilLoc());
3599 if (Result.isNull())
3600 return QualType();
3601 }
3602
John McCallf85e1932011-06-15 23:02:42 +00003603 // Objective-C ARC can add lifetime qualifiers to the type that we're
3604 // referring to.
3605 TLB.TypeWasModifiedSafely(
3606 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3607
John McCall85737a72009-10-30 00:06:24 +00003608 // r-value references can be rebuilt as l-value references.
3609 ReferenceTypeLoc NewTL;
3610 if (isa<LValueReferenceType>(Result))
3611 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3612 else
3613 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3614 NewTL.setSigilLoc(TL.getSigilLoc());
3615
3616 return Result;
3617}
3618
Mike Stump1eb44332009-09-09 15:08:12 +00003619template<typename Derived>
3620QualType
John McCalla2becad2009-10-21 00:40:46 +00003621TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003622 LValueReferenceTypeLoc TL) {
3623 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003624}
3625
Mike Stump1eb44332009-09-09 15:08:12 +00003626template<typename Derived>
3627QualType
John McCalla2becad2009-10-21 00:40:46 +00003628TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003629 RValueReferenceTypeLoc TL) {
3630 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003631}
Mike Stump1eb44332009-09-09 15:08:12 +00003632
Douglas Gregor577f75a2009-08-04 16:50:30 +00003633template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003634QualType
John McCalla2becad2009-10-21 00:40:46 +00003635TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003636 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003637 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003638 if (PointeeType.isNull())
3639 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003640
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003641 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3642 TypeSourceInfo* NewClsTInfo = 0;
3643 if (OldClsTInfo) {
3644 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3645 if (!NewClsTInfo)
3646 return QualType();
3647 }
3648
3649 const MemberPointerType *T = TL.getTypePtr();
3650 QualType OldClsType = QualType(T->getClass(), 0);
3651 QualType NewClsType;
3652 if (NewClsTInfo)
3653 NewClsType = NewClsTInfo->getType();
3654 else {
3655 NewClsType = getDerived().TransformType(OldClsType);
3656 if (NewClsType.isNull())
3657 return QualType();
3658 }
Mike Stump1eb44332009-09-09 15:08:12 +00003659
John McCalla2becad2009-10-21 00:40:46 +00003660 QualType Result = TL.getType();
3661 if (getDerived().AlwaysRebuild() ||
3662 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003663 NewClsType != OldClsType) {
3664 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003665 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003666 if (Result.isNull())
3667 return QualType();
3668 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003669
John McCalla2becad2009-10-21 00:40:46 +00003670 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3671 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003672 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003673
3674 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003675}
3676
Mike Stump1eb44332009-09-09 15:08:12 +00003677template<typename Derived>
3678QualType
John McCalla2becad2009-10-21 00:40:46 +00003679TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003680 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003681 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003682 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003683 if (ElementType.isNull())
3684 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003685
John McCalla2becad2009-10-21 00:40:46 +00003686 QualType Result = TL.getType();
3687 if (getDerived().AlwaysRebuild() ||
3688 ElementType != T->getElementType()) {
3689 Result = getDerived().RebuildConstantArrayType(ElementType,
3690 T->getSizeModifier(),
3691 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003692 T->getIndexTypeCVRQualifiers(),
3693 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003694 if (Result.isNull())
3695 return QualType();
3696 }
Eli Friedman457a3772012-01-25 22:19:07 +00003697
3698 // We might have either a ConstantArrayType or a VariableArrayType now:
3699 // a ConstantArrayType is allowed to have an element type which is a
3700 // VariableArrayType if the type is dependent. Fortunately, all array
3701 // types have the same location layout.
3702 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003703 NewTL.setLBracketLoc(TL.getLBracketLoc());
3704 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003705
John McCalla2becad2009-10-21 00:40:46 +00003706 Expr *Size = TL.getSizeExpr();
3707 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003708 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3709 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003710 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003711 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003712 }
3713 NewTL.setSizeExpr(Size);
3714
3715 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003716}
Mike Stump1eb44332009-09-09 15:08:12 +00003717
Douglas Gregor577f75a2009-08-04 16:50:30 +00003718template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003719QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003720 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003721 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003722 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003723 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003724 if (ElementType.isNull())
3725 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003726
John McCalla2becad2009-10-21 00:40:46 +00003727 QualType Result = TL.getType();
3728 if (getDerived().AlwaysRebuild() ||
3729 ElementType != T->getElementType()) {
3730 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003731 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003732 T->getIndexTypeCVRQualifiers(),
3733 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003734 if (Result.isNull())
3735 return QualType();
3736 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003737
John McCalla2becad2009-10-21 00:40:46 +00003738 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3739 NewTL.setLBracketLoc(TL.getLBracketLoc());
3740 NewTL.setRBracketLoc(TL.getRBracketLoc());
3741 NewTL.setSizeExpr(0);
3742
3743 return Result;
3744}
3745
3746template<typename Derived>
3747QualType
3748TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003749 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003750 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003751 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3752 if (ElementType.isNull())
3753 return QualType();
3754
John McCall60d7b3a2010-08-24 06:29:42 +00003755 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003756 = getDerived().TransformExpr(T->getSizeExpr());
3757 if (SizeResult.isInvalid())
3758 return QualType();
3759
John McCall9ae2f072010-08-23 23:25:46 +00003760 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003761
3762 QualType Result = TL.getType();
3763 if (getDerived().AlwaysRebuild() ||
3764 ElementType != T->getElementType() ||
3765 Size != T->getSizeExpr()) {
3766 Result = getDerived().RebuildVariableArrayType(ElementType,
3767 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003768 Size,
John McCalla2becad2009-10-21 00:40:46 +00003769 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003770 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003771 if (Result.isNull())
3772 return QualType();
3773 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003774
John McCalla2becad2009-10-21 00:40:46 +00003775 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3776 NewTL.setLBracketLoc(TL.getLBracketLoc());
3777 NewTL.setRBracketLoc(TL.getRBracketLoc());
3778 NewTL.setSizeExpr(Size);
3779
3780 return Result;
3781}
3782
3783template<typename Derived>
3784QualType
3785TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003786 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003787 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003788 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3789 if (ElementType.isNull())
3790 return QualType();
3791
Richard Smithf6702a32011-12-20 02:08:33 +00003792 // Array bounds are constant expressions.
3793 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3794 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003795
John McCall3b657512011-01-19 10:06:00 +00003796 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3797 Expr *origSize = TL.getSizeExpr();
3798 if (!origSize) origSize = T->getSizeExpr();
3799
3800 ExprResult sizeResult
3801 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003802 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003803 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003804 return QualType();
3805
John McCall3b657512011-01-19 10:06:00 +00003806 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003807
3808 QualType Result = TL.getType();
3809 if (getDerived().AlwaysRebuild() ||
3810 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003811 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003812 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3813 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003814 size,
John McCalla2becad2009-10-21 00:40:46 +00003815 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003816 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003817 if (Result.isNull())
3818 return QualType();
3819 }
John McCalla2becad2009-10-21 00:40:46 +00003820
3821 // We might have any sort of array type now, but fortunately they
3822 // all have the same location layout.
3823 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3824 NewTL.setLBracketLoc(TL.getLBracketLoc());
3825 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003826 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003827
3828 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003829}
Mike Stump1eb44332009-09-09 15:08:12 +00003830
3831template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003832QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003833 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003834 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003835 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003836
3837 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003838 QualType ElementType = getDerived().TransformType(T->getElementType());
3839 if (ElementType.isNull())
3840 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003841
Richard Smithf6702a32011-12-20 02:08:33 +00003842 // Vector sizes are constant expressions.
3843 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3844 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003845
John McCall60d7b3a2010-08-24 06:29:42 +00003846 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003847 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003848 if (Size.isInvalid())
3849 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003850
John McCalla2becad2009-10-21 00:40:46 +00003851 QualType Result = TL.getType();
3852 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003853 ElementType != T->getElementType() ||
3854 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003855 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003856 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003857 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003858 if (Result.isNull())
3859 return QualType();
3860 }
John McCalla2becad2009-10-21 00:40:46 +00003861
3862 // Result might be dependent or not.
3863 if (isa<DependentSizedExtVectorType>(Result)) {
3864 DependentSizedExtVectorTypeLoc NewTL
3865 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3866 NewTL.setNameLoc(TL.getNameLoc());
3867 } else {
3868 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3869 NewTL.setNameLoc(TL.getNameLoc());
3870 }
3871
3872 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003873}
Mike Stump1eb44332009-09-09 15:08:12 +00003874
3875template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003876QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003877 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003878 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003879 QualType ElementType = getDerived().TransformType(T->getElementType());
3880 if (ElementType.isNull())
3881 return QualType();
3882
John McCalla2becad2009-10-21 00:40:46 +00003883 QualType Result = TL.getType();
3884 if (getDerived().AlwaysRebuild() ||
3885 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003886 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003887 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003888 if (Result.isNull())
3889 return QualType();
3890 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003891
John McCalla2becad2009-10-21 00:40:46 +00003892 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3893 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003894
John McCalla2becad2009-10-21 00:40:46 +00003895 return Result;
3896}
3897
3898template<typename Derived>
3899QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003900 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003901 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003902 QualType ElementType = getDerived().TransformType(T->getElementType());
3903 if (ElementType.isNull())
3904 return QualType();
3905
3906 QualType Result = TL.getType();
3907 if (getDerived().AlwaysRebuild() ||
3908 ElementType != T->getElementType()) {
3909 Result = getDerived().RebuildExtVectorType(ElementType,
3910 T->getNumElements(),
3911 /*FIXME*/ SourceLocation());
3912 if (Result.isNull())
3913 return QualType();
3914 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003915
John McCalla2becad2009-10-21 00:40:46 +00003916 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3917 NewTL.setNameLoc(TL.getNameLoc());
3918
3919 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003920}
Mike Stump1eb44332009-09-09 15:08:12 +00003921
3922template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003923ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003924TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003925 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003926 llvm::Optional<unsigned> NumExpansions,
3927 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003928 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003929 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003930
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003931 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003932 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003933 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003934 TypeLoc OldTL = OldDI->getTypeLoc();
3935 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003936
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003937 TypeLocBuilder TLB;
3938 TypeLoc NewTL = OldDI->getTypeLoc();
3939 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003940
3941 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003942 OldExpansionTL.getPatternLoc());
3943 if (Result.isNull())
3944 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003945
3946 Result = RebuildPackExpansionType(Result,
3947 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003948 OldExpansionTL.getEllipsisLoc(),
3949 NumExpansions);
3950 if (Result.isNull())
3951 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003952
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003953 PackExpansionTypeLoc NewExpansionTL
3954 = TLB.push<PackExpansionTypeLoc>(Result);
3955 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3956 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3957 } else
3958 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003959 if (!NewDI)
3960 return 0;
3961
John McCallfb44de92011-05-01 22:35:37 +00003962 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003963 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003964
3965 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3966 OldParm->getDeclContext(),
3967 OldParm->getInnerLocStart(),
3968 OldParm->getLocation(),
3969 OldParm->getIdentifier(),
3970 NewDI->getType(),
3971 NewDI,
3972 OldParm->getStorageClass(),
3973 OldParm->getStorageClassAsWritten(),
3974 /* DefArg */ NULL);
3975 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3976 OldParm->getFunctionScopeIndex() + indexAdjustment);
3977 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003978}
3979
3980template<typename Derived>
3981bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003982 TransformFunctionTypeParams(SourceLocation Loc,
3983 ParmVarDecl **Params, unsigned NumParams,
3984 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003985 SmallVectorImpl<QualType> &OutParamTypes,
3986 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003987 int indexAdjustment = 0;
3988
Douglas Gregora009b592011-01-07 00:20:55 +00003989 for (unsigned i = 0; i != NumParams; ++i) {
3990 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003991 assert(OldParm->getFunctionScopeIndex() == i);
3992
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003993 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003994 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003995 if (OldParm->isParameterPack()) {
3996 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003997 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003998
Douglas Gregor603cfb42011-01-05 23:12:31 +00003999 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004000 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4001 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
4002 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4003 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004004 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4005
Douglas Gregor603cfb42011-01-05 23:12:31 +00004006 // Determine whether we should expand the parameter packs.
4007 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004008 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004009 llvm::Optional<unsigned> OrigNumExpansions
4010 = ExpansionTL.getTypePtr()->getNumExpansions();
4011 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004012 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4013 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004014 Unexpanded,
4015 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004016 RetainExpansion,
4017 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004018 return true;
4019 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004020
Douglas Gregor603cfb42011-01-05 23:12:31 +00004021 if (ShouldExpand) {
4022 // Expand the function parameter pack into multiple, separate
4023 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004024 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004025 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004026 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004027 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004028 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004029 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004030 OrigNumExpansions,
4031 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004032 if (!NewParm)
4033 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004034
Douglas Gregora009b592011-01-07 00:20:55 +00004035 OutParamTypes.push_back(NewParm->getType());
4036 if (PVars)
4037 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004038 }
Douglas Gregord3731192011-01-10 07:32:04 +00004039
4040 // If we're supposed to retain a pack expansion, do so by temporarily
4041 // forgetting the partially-substituted parameter pack.
4042 if (RetainExpansion) {
4043 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004044 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004045 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004046 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004047 OrigNumExpansions,
4048 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004049 if (!NewParm)
4050 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004051
Douglas Gregord3731192011-01-10 07:32:04 +00004052 OutParamTypes.push_back(NewParm->getType());
4053 if (PVars)
4054 PVars->push_back(NewParm);
4055 }
4056
John McCallfb44de92011-05-01 22:35:37 +00004057 // The next parameter should have the same adjustment as the
4058 // last thing we pushed, but we post-incremented indexAdjustment
4059 // on every push. Also, if we push nothing, the adjustment should
4060 // go down by one.
4061 indexAdjustment--;
4062
Douglas Gregor603cfb42011-01-05 23:12:31 +00004063 // We're done with the pack expansion.
4064 continue;
4065 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004066
4067 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004068 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004069 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4070 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004071 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004072 NumExpansions,
4073 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004074 } else {
4075 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004076 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004077 llvm::Optional<unsigned>(),
4078 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004079 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004080
John McCall21ef0fa2010-03-11 09:03:00 +00004081 if (!NewParm)
4082 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004083
Douglas Gregora009b592011-01-07 00:20:55 +00004084 OutParamTypes.push_back(NewParm->getType());
4085 if (PVars)
4086 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004087 continue;
4088 }
John McCall21ef0fa2010-03-11 09:03:00 +00004089
4090 // Deal with the possibility that we don't have a parameter
4091 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004092 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004093 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004094 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004095 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004096 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004097 = dyn_cast<PackExpansionType>(OldType)) {
4098 // We have a function parameter pack that may need to be expanded.
4099 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004100 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004101 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004102
Douglas Gregor603cfb42011-01-05 23:12:31 +00004103 // Determine whether we should expand the parameter packs.
4104 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004105 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004106 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004107 Unexpanded,
4108 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004109 RetainExpansion,
4110 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004111 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004112 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004113
Douglas Gregor603cfb42011-01-05 23:12:31 +00004114 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004115 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004116 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004117 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004118 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4119 QualType NewType = getDerived().TransformType(Pattern);
4120 if (NewType.isNull())
4121 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004122
Douglas Gregora009b592011-01-07 00:20:55 +00004123 OutParamTypes.push_back(NewType);
4124 if (PVars)
4125 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004126 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004127
Douglas Gregor603cfb42011-01-05 23:12:31 +00004128 // We're done with the pack expansion.
4129 continue;
4130 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004131
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004132 // If we're supposed to retain a pack expansion, do so by temporarily
4133 // forgetting the partially-substituted parameter pack.
4134 if (RetainExpansion) {
4135 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4136 QualType NewType = getDerived().TransformType(Pattern);
4137 if (NewType.isNull())
4138 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004139
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004140 OutParamTypes.push_back(NewType);
4141 if (PVars)
4142 PVars->push_back(0);
4143 }
Douglas Gregord3731192011-01-10 07:32:04 +00004144
Chad Rosier4a9d7952012-08-08 18:46:20 +00004145 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004146 // expansion.
4147 OldType = Expansion->getPattern();
4148 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004149 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4150 NewType = getDerived().TransformType(OldType);
4151 } else {
4152 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004153 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004154
Douglas Gregor603cfb42011-01-05 23:12:31 +00004155 if (NewType.isNull())
4156 return true;
4157
4158 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004159 NewType = getSema().Context.getPackExpansionType(NewType,
4160 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004161
Douglas Gregora009b592011-01-07 00:20:55 +00004162 OutParamTypes.push_back(NewType);
4163 if (PVars)
4164 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004165 }
4166
John McCallfb44de92011-05-01 22:35:37 +00004167#ifndef NDEBUG
4168 if (PVars) {
4169 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4170 if (ParmVarDecl *parm = (*PVars)[i])
4171 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004172 }
John McCallfb44de92011-05-01 22:35:37 +00004173#endif
4174
4175 return false;
4176}
John McCall21ef0fa2010-03-11 09:03:00 +00004177
4178template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004179QualType
John McCalla2becad2009-10-21 00:40:46 +00004180TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004181 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004182 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4183}
4184
4185template<typename Derived>
4186QualType
4187TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4188 FunctionProtoTypeLoc TL,
4189 CXXRecordDecl *ThisContext,
4190 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004191 // Transform the parameters and return type.
4192 //
Richard Smithe6975e92012-04-17 00:58:00 +00004193 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004194 // When the function has a trailing return type, we instantiate the
4195 // parameters before the return type, since the return type can then refer
4196 // to the parameters themselves (via decltype, sizeof, etc.).
4197 //
Chris Lattner686775d2011-07-20 06:58:45 +00004198 SmallVector<QualType, 4> ParamTypes;
4199 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004200 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004201
Douglas Gregordab60ad2010-10-01 18:44:50 +00004202 QualType ResultType;
4203
Richard Smith9fbf3272012-08-14 22:51:13 +00004204 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004205 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004206 TL.getParmArray(),
4207 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004208 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004209 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004210 return QualType();
4211
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004212 {
4213 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004214 // If a declaration declares a member function or member function
4215 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004216 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004217 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004218 // declarator.
4219 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004220
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004221 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4222 if (ResultType.isNull())
4223 return QualType();
4224 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004225 }
4226 else {
4227 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4228 if (ResultType.isNull())
4229 return QualType();
4230
Chad Rosier4a9d7952012-08-08 18:46:20 +00004231 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004232 TL.getParmArray(),
4233 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004234 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004235 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004236 return QualType();
4237 }
4238
Richard Smithe6975e92012-04-17 00:58:00 +00004239 // FIXME: Need to transform the exception-specification too.
4240
John McCalla2becad2009-10-21 00:40:46 +00004241 QualType Result = TL.getType();
4242 if (getDerived().AlwaysRebuild() ||
4243 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004244 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004245 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4246 Result = getDerived().RebuildFunctionProtoType(ResultType,
4247 ParamTypes.data(),
4248 ParamTypes.size(),
4249 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004250 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004251 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004252 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004253 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004254 if (Result.isNull())
4255 return QualType();
4256 }
Mike Stump1eb44332009-09-09 15:08:12 +00004257
John McCalla2becad2009-10-21 00:40:46 +00004258 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004259 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4260 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004261 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4262 NewTL.setArg(i, ParamDecls[i]);
4263
4264 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004265}
Mike Stump1eb44332009-09-09 15:08:12 +00004266
Douglas Gregor577f75a2009-08-04 16:50:30 +00004267template<typename Derived>
4268QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004269 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004270 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004271 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004272 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4273 if (ResultType.isNull())
4274 return QualType();
4275
4276 QualType Result = TL.getType();
4277 if (getDerived().AlwaysRebuild() ||
4278 ResultType != T->getResultType())
4279 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4280
4281 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004282 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4283 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004284
4285 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004286}
Mike Stump1eb44332009-09-09 15:08:12 +00004287
John McCalled976492009-12-04 22:46:56 +00004288template<typename Derived> QualType
4289TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004290 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004291 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004292 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004293 if (!D)
4294 return QualType();
4295
4296 QualType Result = TL.getType();
4297 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4298 Result = getDerived().RebuildUnresolvedUsingType(D);
4299 if (Result.isNull())
4300 return QualType();
4301 }
4302
4303 // We might get an arbitrary type spec type back. We should at
4304 // least always get a type spec type, though.
4305 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4306 NewTL.setNameLoc(TL.getNameLoc());
4307
4308 return Result;
4309}
4310
Douglas Gregor577f75a2009-08-04 16:50:30 +00004311template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004312QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004313 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004314 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004315 TypedefNameDecl *Typedef
4316 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4317 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004318 if (!Typedef)
4319 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004320
John McCalla2becad2009-10-21 00:40:46 +00004321 QualType Result = TL.getType();
4322 if (getDerived().AlwaysRebuild() ||
4323 Typedef != T->getDecl()) {
4324 Result = getDerived().RebuildTypedefType(Typedef);
4325 if (Result.isNull())
4326 return QualType();
4327 }
Mike Stump1eb44332009-09-09 15:08:12 +00004328
John McCalla2becad2009-10-21 00:40:46 +00004329 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4330 NewTL.setNameLoc(TL.getNameLoc());
4331
4332 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004333}
Mike Stump1eb44332009-09-09 15:08:12 +00004334
Douglas Gregor577f75a2009-08-04 16:50:30 +00004335template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004336QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004337 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004338 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004339 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004340
John McCall60d7b3a2010-08-24 06:29:42 +00004341 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004342 if (E.isInvalid())
4343 return QualType();
4344
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004345 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4346 if (E.isInvalid())
4347 return QualType();
4348
John McCalla2becad2009-10-21 00:40:46 +00004349 QualType Result = TL.getType();
4350 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004351 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004352 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004353 if (Result.isNull())
4354 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004355 }
John McCalla2becad2009-10-21 00:40:46 +00004356 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004357
John McCalla2becad2009-10-21 00:40:46 +00004358 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004359 NewTL.setTypeofLoc(TL.getTypeofLoc());
4360 NewTL.setLParenLoc(TL.getLParenLoc());
4361 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004362
4363 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004364}
Mike Stump1eb44332009-09-09 15:08:12 +00004365
4366template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004367QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004368 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004369 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4370 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4371 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004372 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004373
John McCalla2becad2009-10-21 00:40:46 +00004374 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004375 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4376 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004377 if (Result.isNull())
4378 return QualType();
4379 }
Mike Stump1eb44332009-09-09 15:08:12 +00004380
John McCalla2becad2009-10-21 00:40:46 +00004381 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004382 NewTL.setTypeofLoc(TL.getTypeofLoc());
4383 NewTL.setLParenLoc(TL.getLParenLoc());
4384 NewTL.setRParenLoc(TL.getRParenLoc());
4385 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004386
4387 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004388}
Mike Stump1eb44332009-09-09 15:08:12 +00004389
4390template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004391QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004392 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004393 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004394
Douglas Gregor670444e2009-08-04 22:27:00 +00004395 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004396 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4397 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004398
John McCall60d7b3a2010-08-24 06:29:42 +00004399 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004400 if (E.isInvalid())
4401 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004402
Richard Smith76f3f692012-02-22 02:04:18 +00004403 E = getSema().ActOnDecltypeExpression(E.take());
4404 if (E.isInvalid())
4405 return QualType();
4406
John McCalla2becad2009-10-21 00:40:46 +00004407 QualType Result = TL.getType();
4408 if (getDerived().AlwaysRebuild() ||
4409 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004410 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004411 if (Result.isNull())
4412 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004413 }
John McCalla2becad2009-10-21 00:40:46 +00004414 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004415
John McCalla2becad2009-10-21 00:40:46 +00004416 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4417 NewTL.setNameLoc(TL.getNameLoc());
4418
4419 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004420}
4421
4422template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004423QualType TreeTransform<Derived>::TransformUnaryTransformType(
4424 TypeLocBuilder &TLB,
4425 UnaryTransformTypeLoc TL) {
4426 QualType Result = TL.getType();
4427 if (Result->isDependentType()) {
4428 const UnaryTransformType *T = TL.getTypePtr();
4429 QualType NewBase =
4430 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4431 Result = getDerived().RebuildUnaryTransformType(NewBase,
4432 T->getUTTKind(),
4433 TL.getKWLoc());
4434 if (Result.isNull())
4435 return QualType();
4436 }
4437
4438 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4439 NewTL.setKWLoc(TL.getKWLoc());
4440 NewTL.setParensRange(TL.getParensRange());
4441 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4442 return Result;
4443}
4444
4445template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004446QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4447 AutoTypeLoc TL) {
4448 const AutoType *T = TL.getTypePtr();
4449 QualType OldDeduced = T->getDeducedType();
4450 QualType NewDeduced;
4451 if (!OldDeduced.isNull()) {
4452 NewDeduced = getDerived().TransformType(OldDeduced);
4453 if (NewDeduced.isNull())
4454 return QualType();
4455 }
4456
4457 QualType Result = TL.getType();
4458 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4459 Result = getDerived().RebuildAutoType(NewDeduced);
4460 if (Result.isNull())
4461 return QualType();
4462 }
4463
4464 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4465 NewTL.setNameLoc(TL.getNameLoc());
4466
4467 return Result;
4468}
4469
4470template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004471QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004472 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004473 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004474 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004475 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4476 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004477 if (!Record)
4478 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004479
John McCalla2becad2009-10-21 00:40:46 +00004480 QualType Result = TL.getType();
4481 if (getDerived().AlwaysRebuild() ||
4482 Record != T->getDecl()) {
4483 Result = getDerived().RebuildRecordType(Record);
4484 if (Result.isNull())
4485 return QualType();
4486 }
Mike Stump1eb44332009-09-09 15:08:12 +00004487
John McCalla2becad2009-10-21 00:40:46 +00004488 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4489 NewTL.setNameLoc(TL.getNameLoc());
4490
4491 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004492}
Mike Stump1eb44332009-09-09 15:08:12 +00004493
4494template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004495QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004496 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004497 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004498 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004499 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4500 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004501 if (!Enum)
4502 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004503
John McCalla2becad2009-10-21 00:40:46 +00004504 QualType Result = TL.getType();
4505 if (getDerived().AlwaysRebuild() ||
4506 Enum != T->getDecl()) {
4507 Result = getDerived().RebuildEnumType(Enum);
4508 if (Result.isNull())
4509 return QualType();
4510 }
Mike Stump1eb44332009-09-09 15:08:12 +00004511
John McCalla2becad2009-10-21 00:40:46 +00004512 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4513 NewTL.setNameLoc(TL.getNameLoc());
4514
4515 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004516}
John McCall7da24312009-09-05 00:15:47 +00004517
John McCall3cb0ebd2010-03-10 03:28:59 +00004518template<typename Derived>
4519QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4520 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004521 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004522 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4523 TL.getTypePtr()->getDecl());
4524 if (!D) return QualType();
4525
4526 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4527 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4528 return T;
4529}
4530
Douglas Gregor577f75a2009-08-04 16:50:30 +00004531template<typename Derived>
4532QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004533 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004534 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004535 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004536}
4537
Mike Stump1eb44332009-09-09 15:08:12 +00004538template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004539QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004540 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004541 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004542 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004543
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004544 // Substitute into the replacement type, which itself might involve something
4545 // that needs to be transformed. This only tends to occur with default
4546 // template arguments of template template parameters.
4547 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4548 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4549 if (Replacement.isNull())
4550 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004551
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004552 // Always canonicalize the replacement type.
4553 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4554 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004555 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004556 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004557
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004558 // Propagate type-source information.
4559 SubstTemplateTypeParmTypeLoc NewTL
4560 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4561 NewTL.setNameLoc(TL.getNameLoc());
4562 return Result;
4563
John McCall49a832b2009-10-18 09:09:24 +00004564}
4565
4566template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004567QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4568 TypeLocBuilder &TLB,
4569 SubstTemplateTypeParmPackTypeLoc TL) {
4570 return TransformTypeSpecType(TLB, TL);
4571}
4572
4573template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004574QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004575 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004576 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004577 const TemplateSpecializationType *T = TL.getTypePtr();
4578
Douglas Gregor1d752d72011-03-02 18:46:51 +00004579 // The nested-name-specifier never matters in a TemplateSpecializationType,
4580 // because we can't have a dependent nested-name-specifier anyway.
4581 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004582 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004583 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4584 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004585 if (Template.isNull())
4586 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004587
John McCall43fed0d2010-11-12 08:19:04 +00004588 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4589}
4590
Eli Friedmanb001de72011-10-06 23:00:33 +00004591template<typename Derived>
4592QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4593 AtomicTypeLoc TL) {
4594 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4595 if (ValueType.isNull())
4596 return QualType();
4597
4598 QualType Result = TL.getType();
4599 if (getDerived().AlwaysRebuild() ||
4600 ValueType != TL.getValueLoc().getType()) {
4601 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4602 if (Result.isNull())
4603 return QualType();
4604 }
4605
4606 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4607 NewTL.setKWLoc(TL.getKWLoc());
4608 NewTL.setLParenLoc(TL.getLParenLoc());
4609 NewTL.setRParenLoc(TL.getRParenLoc());
4610
4611 return Result;
4612}
4613
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004614namespace {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004615 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004616 /// container that provides a \c getArgLoc() member function.
4617 ///
4618 /// This iterator is intended to be used with the iterator form of
4619 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4620 template<typename ArgLocContainer>
4621 class TemplateArgumentLocContainerIterator {
4622 ArgLocContainer *Container;
4623 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004624
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004625 public:
4626 typedef TemplateArgumentLoc value_type;
4627 typedef TemplateArgumentLoc reference;
4628 typedef int difference_type;
4629 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004630
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004631 class pointer {
4632 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004633
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004634 public:
4635 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004636
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004637 const TemplateArgumentLoc *operator->() const {
4638 return &Arg;
4639 }
4640 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004641
4642
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004643 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004644
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004645 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4646 unsigned Index)
4647 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004648
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004649 TemplateArgumentLocContainerIterator &operator++() {
4650 ++Index;
4651 return *this;
4652 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004653
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004654 TemplateArgumentLocContainerIterator operator++(int) {
4655 TemplateArgumentLocContainerIterator Old(*this);
4656 ++(*this);
4657 return Old;
4658 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004659
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004660 TemplateArgumentLoc operator*() const {
4661 return Container->getArgLoc(Index);
4662 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004663
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004664 pointer operator->() const {
4665 return pointer(Container->getArgLoc(Index));
4666 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004667
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004668 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004669 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004670 return X.Container == Y.Container && X.Index == Y.Index;
4671 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004672
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004673 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004674 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004675 return !(X == Y);
4676 }
4677 };
4678}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004679
4680
John McCall43fed0d2010-11-12 08:19:04 +00004681template <typename Derived>
4682QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4683 TypeLocBuilder &TLB,
4684 TemplateSpecializationTypeLoc TL,
4685 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004686 TemplateArgumentListInfo NewTemplateArgs;
4687 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4688 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004689 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4690 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004691 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004692 ArgIterator(TL, TL.getNumArgs()),
4693 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004694 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004695
John McCall833ca992009-10-29 08:12:44 +00004696 // FIXME: maybe don't rebuild if all the template arguments are the same.
4697
4698 QualType Result =
4699 getDerived().RebuildTemplateSpecializationType(Template,
4700 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004701 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004702
4703 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004704 // Specializations of template template parameters are represented as
4705 // TemplateSpecializationTypes, and substitution of type alias templates
4706 // within a dependent context can transform them into
4707 // DependentTemplateSpecializationTypes.
4708 if (isa<DependentTemplateSpecializationType>(Result)) {
4709 DependentTemplateSpecializationTypeLoc NewTL
4710 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004711 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004712 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004713 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004714 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004715 NewTL.setLAngleLoc(TL.getLAngleLoc());
4716 NewTL.setRAngleLoc(TL.getRAngleLoc());
4717 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4718 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4719 return Result;
4720 }
4721
John McCall833ca992009-10-29 08:12:44 +00004722 TemplateSpecializationTypeLoc NewTL
4723 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004724 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004725 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4726 NewTL.setLAngleLoc(TL.getLAngleLoc());
4727 NewTL.setRAngleLoc(TL.getRAngleLoc());
4728 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4729 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004730 }
Mike Stump1eb44332009-09-09 15:08:12 +00004731
John McCall833ca992009-10-29 08:12:44 +00004732 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004733}
Mike Stump1eb44332009-09-09 15:08:12 +00004734
Douglas Gregora88f09f2011-02-28 17:23:35 +00004735template <typename Derived>
4736QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4737 TypeLocBuilder &TLB,
4738 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004739 TemplateName Template,
4740 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004741 TemplateArgumentListInfo NewTemplateArgs;
4742 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4743 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4744 typedef TemplateArgumentLocContainerIterator<
4745 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004746 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004747 ArgIterator(TL, TL.getNumArgs()),
4748 NewTemplateArgs))
4749 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004750
Douglas Gregora88f09f2011-02-28 17:23:35 +00004751 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004752
Douglas Gregora88f09f2011-02-28 17:23:35 +00004753 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4754 QualType Result
4755 = getSema().Context.getDependentTemplateSpecializationType(
4756 TL.getTypePtr()->getKeyword(),
4757 DTN->getQualifier(),
4758 DTN->getIdentifier(),
4759 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004760
Douglas Gregora88f09f2011-02-28 17:23:35 +00004761 DependentTemplateSpecializationTypeLoc NewTL
4762 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004763 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004764 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004765 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004766 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004767 NewTL.setLAngleLoc(TL.getLAngleLoc());
4768 NewTL.setRAngleLoc(TL.getRAngleLoc());
4769 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4770 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4771 return Result;
4772 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004773
4774 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004775 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004776 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004777 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004778
Douglas Gregora88f09f2011-02-28 17:23:35 +00004779 if (!Result.isNull()) {
4780 /// FIXME: Wrap this in an elaborated-type-specifier?
4781 TemplateSpecializationTypeLoc NewTL
4782 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004783 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004784 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004785 NewTL.setLAngleLoc(TL.getLAngleLoc());
4786 NewTL.setRAngleLoc(TL.getRAngleLoc());
4787 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4788 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4789 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004790
Douglas Gregora88f09f2011-02-28 17:23:35 +00004791 return Result;
4792}
4793
Mike Stump1eb44332009-09-09 15:08:12 +00004794template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004795QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004796TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004797 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004798 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004799
Douglas Gregor9e876872011-03-01 18:12:44 +00004800 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004801 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004802 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004803 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004804 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4805 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004806 return QualType();
4807 }
Mike Stump1eb44332009-09-09 15:08:12 +00004808
John McCall43fed0d2010-11-12 08:19:04 +00004809 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4810 if (NamedT.isNull())
4811 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004812
Richard Smith3e4c6c42011-05-05 21:57:07 +00004813 // C++0x [dcl.type.elab]p2:
4814 // If the identifier resolves to a typedef-name or the simple-template-id
4815 // resolves to an alias template specialization, the
4816 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004817 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4818 if (const TemplateSpecializationType *TST =
4819 NamedT->getAs<TemplateSpecializationType>()) {
4820 TemplateName Template = TST->getTemplateName();
4821 if (TypeAliasTemplateDecl *TAT =
4822 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4823 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4824 diag::err_tag_reference_non_tag) << 4;
4825 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4826 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004827 }
4828 }
4829
John McCalla2becad2009-10-21 00:40:46 +00004830 QualType Result = TL.getType();
4831 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004832 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004833 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004834 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004835 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004836 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004837 if (Result.isNull())
4838 return QualType();
4839 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004840
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004841 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004842 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004843 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004844 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004845}
Mike Stump1eb44332009-09-09 15:08:12 +00004846
4847template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004848QualType TreeTransform<Derived>::TransformAttributedType(
4849 TypeLocBuilder &TLB,
4850 AttributedTypeLoc TL) {
4851 const AttributedType *oldType = TL.getTypePtr();
4852 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4853 if (modifiedType.isNull())
4854 return QualType();
4855
4856 QualType result = TL.getType();
4857
4858 // FIXME: dependent operand expressions?
4859 if (getDerived().AlwaysRebuild() ||
4860 modifiedType != oldType->getModifiedType()) {
4861 // TODO: this is really lame; we should really be rebuilding the
4862 // equivalent type from first principles.
4863 QualType equivalentType
4864 = getDerived().TransformType(oldType->getEquivalentType());
4865 if (equivalentType.isNull())
4866 return QualType();
4867 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4868 modifiedType,
4869 equivalentType);
4870 }
4871
4872 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4873 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4874 if (TL.hasAttrOperand())
4875 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4876 if (TL.hasAttrExprOperand())
4877 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4878 else if (TL.hasAttrEnumOperand())
4879 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4880
4881 return result;
4882}
4883
4884template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004885QualType
4886TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4887 ParenTypeLoc TL) {
4888 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4889 if (Inner.isNull())
4890 return QualType();
4891
4892 QualType Result = TL.getType();
4893 if (getDerived().AlwaysRebuild() ||
4894 Inner != TL.getInnerLoc().getType()) {
4895 Result = getDerived().RebuildParenType(Inner);
4896 if (Result.isNull())
4897 return QualType();
4898 }
4899
4900 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4901 NewTL.setLParenLoc(TL.getLParenLoc());
4902 NewTL.setRParenLoc(TL.getRParenLoc());
4903 return Result;
4904}
4905
4906template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004907QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004908 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004909 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004910
Douglas Gregor2494dd02011-03-01 01:34:45 +00004911 NestedNameSpecifierLoc QualifierLoc
4912 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4913 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004914 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004915
John McCall33500952010-06-11 00:33:02 +00004916 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004917 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004918 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004919 QualifierLoc,
4920 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004921 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004922 if (Result.isNull())
4923 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004924
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004925 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4926 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004927 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4928
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004929 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004930 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004931 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004932 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004933 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004934 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004935 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004936 NewTL.setNameLoc(TL.getNameLoc());
4937 }
John McCalla2becad2009-10-21 00:40:46 +00004938 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004939}
Mike Stump1eb44332009-09-09 15:08:12 +00004940
Douglas Gregor577f75a2009-08-04 16:50:30 +00004941template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004942QualType TreeTransform<Derived>::
4943 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004944 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004945 NestedNameSpecifierLoc QualifierLoc;
4946 if (TL.getQualifierLoc()) {
4947 QualifierLoc
4948 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4949 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004950 return QualType();
4951 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004952
John McCall43fed0d2010-11-12 08:19:04 +00004953 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004954 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004955}
4956
4957template<typename Derived>
4958QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004959TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4960 DependentTemplateSpecializationTypeLoc TL,
4961 NestedNameSpecifierLoc QualifierLoc) {
4962 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004963
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004964 TemplateArgumentListInfo NewTemplateArgs;
4965 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4966 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004967
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004968 typedef TemplateArgumentLocContainerIterator<
4969 DependentTemplateSpecializationTypeLoc> ArgIterator;
4970 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4971 ArgIterator(TL, TL.getNumArgs()),
4972 NewTemplateArgs))
4973 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004974
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004975 QualType Result
4976 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4977 QualifierLoc,
4978 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004979 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004980 NewTemplateArgs);
4981 if (Result.isNull())
4982 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004983
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004984 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4985 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004986
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004987 // Copy information relevant to the template specialization.
4988 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004989 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004990 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004991 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004992 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4993 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004994 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004995 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004996
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004997 // Copy information relevant to the elaborated type.
4998 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004999 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005000 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005001 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5002 DependentTemplateSpecializationTypeLoc SpecTL
5003 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005004 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005005 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005006 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005007 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005008 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5009 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005010 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005011 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005012 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005013 TemplateSpecializationTypeLoc SpecTL
5014 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005015 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005016 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005017 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5018 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005019 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005020 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005021 }
5022 return Result;
5023}
5024
5025template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005026QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5027 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005028 QualType Pattern
5029 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005030 if (Pattern.isNull())
5031 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005032
5033 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005034 if (getDerived().AlwaysRebuild() ||
5035 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005036 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005037 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005038 TL.getEllipsisLoc(),
5039 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005040 if (Result.isNull())
5041 return QualType();
5042 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005043
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005044 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5045 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5046 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005047}
5048
5049template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005050QualType
5051TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005052 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005053 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005054 TLB.pushFullCopy(TL);
5055 return TL.getType();
5056}
5057
5058template<typename Derived>
5059QualType
5060TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005061 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005062 // ObjCObjectType is never dependent.
5063 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005064 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005065}
Mike Stump1eb44332009-09-09 15:08:12 +00005066
5067template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005068QualType
5069TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005070 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005071 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005072 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005073 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005074}
5075
Douglas Gregor577f75a2009-08-04 16:50:30 +00005076//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005077// Statement transformation
5078//===----------------------------------------------------------------------===//
5079template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005080StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005081TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005082 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005083}
5084
5085template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005086StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005087TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5088 return getDerived().TransformCompoundStmt(S, false);
5089}
5090
5091template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005092StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005093TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005094 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005095 Sema::CompoundScopeRAII CompoundScope(getSema());
5096
John McCall7114cba2010-08-27 19:56:05 +00005097 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005098 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005099 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005100 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5101 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005102 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005103 if (Result.isInvalid()) {
5104 // Immediately fail if this was a DeclStmt, since it's very
5105 // likely that this will cause problems for future statements.
5106 if (isa<DeclStmt>(*B))
5107 return StmtError();
5108
5109 // Otherwise, just keep processing substatements and fail later.
5110 SubStmtInvalid = true;
5111 continue;
5112 }
Mike Stump1eb44332009-09-09 15:08:12 +00005113
Douglas Gregor43959a92009-08-20 07:17:43 +00005114 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5115 Statements.push_back(Result.takeAs<Stmt>());
5116 }
Mike Stump1eb44332009-09-09 15:08:12 +00005117
John McCall7114cba2010-08-27 19:56:05 +00005118 if (SubStmtInvalid)
5119 return StmtError();
5120
Douglas Gregor43959a92009-08-20 07:17:43 +00005121 if (!getDerived().AlwaysRebuild() &&
5122 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005123 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005124
5125 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005126 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005127 S->getRBracLoc(),
5128 IsStmtExpr);
5129}
Mike Stump1eb44332009-09-09 15:08:12 +00005130
Douglas Gregor43959a92009-08-20 07:17:43 +00005131template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005132StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005133TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005134 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005135 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005136 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5137 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005138
Eli Friedman264c1f82009-11-19 03:14:00 +00005139 // Transform the left-hand case value.
5140 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005141 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005142 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005143 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005144
Eli Friedman264c1f82009-11-19 03:14:00 +00005145 // Transform the right-hand case value (for the GNU case-range extension).
5146 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005147 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005148 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005149 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005150 }
Mike Stump1eb44332009-09-09 15:08:12 +00005151
Douglas Gregor43959a92009-08-20 07:17:43 +00005152 // Build the case statement.
5153 // Case statements are always rebuilt so that they will attached to their
5154 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005155 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005156 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005157 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005158 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005159 S->getColonLoc());
5160 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005161 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005162
Douglas Gregor43959a92009-08-20 07:17:43 +00005163 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005164 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005165 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005166 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005167
Douglas Gregor43959a92009-08-20 07:17:43 +00005168 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005169 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005170}
5171
5172template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005173StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005174TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005175 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005176 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005177 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005178 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005179
Douglas Gregor43959a92009-08-20 07:17:43 +00005180 // Default statements are always rebuilt
5181 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005182 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005183}
Mike Stump1eb44332009-09-09 15:08:12 +00005184
Douglas Gregor43959a92009-08-20 07:17:43 +00005185template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005186StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005187TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005188 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005189 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005190 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005191
Chris Lattner57ad3782011-02-17 20:34:02 +00005192 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5193 S->getDecl());
5194 if (!LD)
5195 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005196
5197
Douglas Gregor43959a92009-08-20 07:17:43 +00005198 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005199 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005200 cast<LabelDecl>(LD), SourceLocation(),
5201 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005202}
Mike Stump1eb44332009-09-09 15:08:12 +00005203
Douglas Gregor43959a92009-08-20 07:17:43 +00005204template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005205StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005206TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5207 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5208 if (SubStmt.isInvalid())
5209 return StmtError();
5210
5211 // TODO: transform attributes
5212 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5213 return S;
5214
5215 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5216 S->getAttrs(),
5217 SubStmt.get());
5218}
5219
5220template<typename Derived>
5221StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005222TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005223 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005224 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005225 VarDecl *ConditionVar = 0;
5226 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005227 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005228 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005229 getDerived().TransformDefinition(
5230 S->getConditionVariable()->getLocation(),
5231 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005232 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005233 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005234 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005235 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005236
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005237 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005238 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005239
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005240 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005241 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005242 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005243 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005244 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005245 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005246
John McCall9ae2f072010-08-23 23:25:46 +00005247 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005248 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005249 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005250
John McCall9ae2f072010-08-23 23:25:46 +00005251 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5252 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005253 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005254
Douglas Gregor43959a92009-08-20 07:17:43 +00005255 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005256 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005257 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005258 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005259
Douglas Gregor43959a92009-08-20 07:17:43 +00005260 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005261 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005262 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005263 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005264
Douglas Gregor43959a92009-08-20 07:17:43 +00005265 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005266 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005267 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005268 Then.get() == S->getThen() &&
5269 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005270 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005271
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005272 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005273 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005274 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005275}
5276
5277template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005278StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005279TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005280 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005281 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005282 VarDecl *ConditionVar = 0;
5283 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005284 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005285 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005286 getDerived().TransformDefinition(
5287 S->getConditionVariable()->getLocation(),
5288 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005289 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005290 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005291 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005292 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005293
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005294 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005295 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005296 }
Mike Stump1eb44332009-09-09 15:08:12 +00005297
Douglas Gregor43959a92009-08-20 07:17:43 +00005298 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005299 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005300 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005301 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005302 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005303 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005304
Douglas Gregor43959a92009-08-20 07:17:43 +00005305 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005306 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005307 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005308 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005309
Douglas Gregor43959a92009-08-20 07:17:43 +00005310 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005311 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5312 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005313}
Mike Stump1eb44332009-09-09 15:08:12 +00005314
Douglas Gregor43959a92009-08-20 07:17:43 +00005315template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005316StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005317TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005318 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005319 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005320 VarDecl *ConditionVar = 0;
5321 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005322 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005323 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005324 getDerived().TransformDefinition(
5325 S->getConditionVariable()->getLocation(),
5326 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005327 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005328 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005329 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005330 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005331
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005332 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005333 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005334
5335 if (S->getCond()) {
5336 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005337 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005338 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005339 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005340 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005341 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005342 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005343 }
Mike Stump1eb44332009-09-09 15:08:12 +00005344
John McCall9ae2f072010-08-23 23:25:46 +00005345 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5346 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005347 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005348
Douglas Gregor43959a92009-08-20 07:17:43 +00005349 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005350 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005351 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005352 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005353
Douglas Gregor43959a92009-08-20 07:17:43 +00005354 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005355 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005356 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005357 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005358 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005359
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005360 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005361 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005362}
Mike Stump1eb44332009-09-09 15:08:12 +00005363
Douglas Gregor43959a92009-08-20 07:17:43 +00005364template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005365StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005366TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005367 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005368 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005369 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005370 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005371
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005372 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005373 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005374 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005375 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005376
Douglas Gregor43959a92009-08-20 07:17:43 +00005377 if (!getDerived().AlwaysRebuild() &&
5378 Cond.get() == S->getCond() &&
5379 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005380 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005381
John McCall9ae2f072010-08-23 23:25:46 +00005382 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5383 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005384 S->getRParenLoc());
5385}
Mike Stump1eb44332009-09-09 15:08:12 +00005386
Douglas Gregor43959a92009-08-20 07:17:43 +00005387template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005388StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005389TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005390 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005391 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005392 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005393 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005394
Douglas Gregor43959a92009-08-20 07:17:43 +00005395 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005396 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005397 VarDecl *ConditionVar = 0;
5398 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005399 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005400 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005401 getDerived().TransformDefinition(
5402 S->getConditionVariable()->getLocation(),
5403 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005404 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005405 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005406 } else {
5407 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005408
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005409 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005410 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005411
5412 if (S->getCond()) {
5413 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005414 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005415 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005416 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005417 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005418
John McCall9ae2f072010-08-23 23:25:46 +00005419 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005420 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005421 }
Mike Stump1eb44332009-09-09 15:08:12 +00005422
Chad Rosier4a9d7952012-08-08 18:46:20 +00005423 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005424 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005425 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005426
Douglas Gregor43959a92009-08-20 07:17:43 +00005427 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005428 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005429 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005430 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005431
John McCall9ae2f072010-08-23 23:25:46 +00005432 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5433 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005434 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005435
Douglas Gregor43959a92009-08-20 07:17:43 +00005436 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005437 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005438 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005439 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005440
Douglas Gregor43959a92009-08-20 07:17:43 +00005441 if (!getDerived().AlwaysRebuild() &&
5442 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005443 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005444 Inc.get() == S->getInc() &&
5445 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005446 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005447
Douglas Gregor43959a92009-08-20 07:17:43 +00005448 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005449 Init.get(), FullCond, ConditionVar,
5450 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005451}
5452
5453template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005454StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005455TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005456 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5457 S->getLabel());
5458 if (!LD)
5459 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005460
Douglas Gregor43959a92009-08-20 07:17:43 +00005461 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005462 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005463 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005464}
5465
5466template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005467StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005468TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005469 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005470 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005471 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005472 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005473
Douglas Gregor43959a92009-08-20 07:17:43 +00005474 if (!getDerived().AlwaysRebuild() &&
5475 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005476 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005477
5478 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005479 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005480}
5481
5482template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005483StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005484TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005485 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005486}
Mike Stump1eb44332009-09-09 15:08:12 +00005487
Douglas Gregor43959a92009-08-20 07:17:43 +00005488template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005489StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005490TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005491 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005492}
Mike Stump1eb44332009-09-09 15:08:12 +00005493
Douglas Gregor43959a92009-08-20 07:17:43 +00005494template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005495StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005496TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005497 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005498 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005499 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005500
Mike Stump1eb44332009-09-09 15:08:12 +00005501 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005502 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005503 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005504}
Mike Stump1eb44332009-09-09 15:08:12 +00005505
Douglas Gregor43959a92009-08-20 07:17:43 +00005506template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005507StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005508TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005509 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005510 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005511 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5512 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005513 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5514 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005515 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005516 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005517
Douglas Gregor43959a92009-08-20 07:17:43 +00005518 if (Transformed != *D)
5519 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005520
Douglas Gregor43959a92009-08-20 07:17:43 +00005521 Decls.push_back(Transformed);
5522 }
Mike Stump1eb44332009-09-09 15:08:12 +00005523
Douglas Gregor43959a92009-08-20 07:17:43 +00005524 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005525 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005526
5527 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005528 S->getStartLoc(), S->getEndLoc());
5529}
Mike Stump1eb44332009-09-09 15:08:12 +00005530
Douglas Gregor43959a92009-08-20 07:17:43 +00005531template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005532StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005533TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005534
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005535 SmallVector<Expr*, 8> Constraints;
5536 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005537 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005538
John McCall60d7b3a2010-08-24 06:29:42 +00005539 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005540 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005541
5542 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005543
Anders Carlsson703e3942010-01-24 05:50:09 +00005544 // Go through the outputs.
5545 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005546 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005547
Anders Carlsson703e3942010-01-24 05:50:09 +00005548 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005549 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005550
Anders Carlsson703e3942010-01-24 05:50:09 +00005551 // Transform the output expr.
5552 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005553 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005554 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005555 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005556
Anders Carlsson703e3942010-01-24 05:50:09 +00005557 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005558
John McCall9ae2f072010-08-23 23:25:46 +00005559 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005560 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005561
Anders Carlsson703e3942010-01-24 05:50:09 +00005562 // Go through the inputs.
5563 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005564 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005565
Anders Carlsson703e3942010-01-24 05:50:09 +00005566 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005567 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005568
Anders Carlsson703e3942010-01-24 05:50:09 +00005569 // Transform the input expr.
5570 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005571 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005572 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005573 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005574
Anders Carlsson703e3942010-01-24 05:50:09 +00005575 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005576
John McCall9ae2f072010-08-23 23:25:46 +00005577 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005578 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005579
Anders Carlsson703e3942010-01-24 05:50:09 +00005580 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005581 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005582
5583 // Go through the clobbers.
5584 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005585 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005586
5587 // No need to transform the asm string literal.
5588 AsmString = SemaRef.Owned(S->getAsmString());
5589
5590 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5591 S->isSimple(),
5592 S->isVolatile(),
5593 S->getNumOutputs(),
5594 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005595 Names.data(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005596 Constraints,
5597 Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00005598 AsmString.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005599 Clobbers,
Chad Rosierdf4ee102012-08-20 17:11:53 +00005600 S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005601}
5602
Chad Rosier8cd64b42012-06-11 20:47:18 +00005603template<typename Derived>
5604StmtResult
5605TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005606 ArrayRef<Token> AsmToks =
5607 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005608
Chad Rosier7bd092b2012-08-15 16:53:30 +00005609 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5610 AsmToks, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005611}
Douglas Gregor43959a92009-08-20 07:17:43 +00005612
5613template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005614StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005615TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005616 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005617 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005618 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005619 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005620
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005621 // Transform the @catch statements (if present).
5622 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005623 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005624 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005625 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005626 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005627 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005628 if (Catch.get() != S->getCatchStmt(I))
5629 AnyCatchChanged = true;
5630 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005631 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005632
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005633 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005634 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005635 if (S->getFinallyStmt()) {
5636 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5637 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005638 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005639 }
5640
5641 // If nothing changed, just retain this statement.
5642 if (!getDerived().AlwaysRebuild() &&
5643 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005644 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005645 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005646 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005647
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005648 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005649 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005650 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005651}
Mike Stump1eb44332009-09-09 15:08:12 +00005652
Douglas Gregor43959a92009-08-20 07:17:43 +00005653template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005654StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005655TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005656 // Transform the @catch parameter, if there is one.
5657 VarDecl *Var = 0;
5658 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5659 TypeSourceInfo *TSInfo = 0;
5660 if (FromVar->getTypeSourceInfo()) {
5661 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5662 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005663 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005664 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005665
Douglas Gregorbe270a02010-04-26 17:57:08 +00005666 QualType T;
5667 if (TSInfo)
5668 T = TSInfo->getType();
5669 else {
5670 T = getDerived().TransformType(FromVar->getType());
5671 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005672 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005673 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005674
Douglas Gregorbe270a02010-04-26 17:57:08 +00005675 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5676 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005677 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005678 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005679
John McCall60d7b3a2010-08-24 06:29:42 +00005680 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005681 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005682 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005683
5684 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005685 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005686 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005687}
Mike Stump1eb44332009-09-09 15:08:12 +00005688
Douglas Gregor43959a92009-08-20 07:17:43 +00005689template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005690StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005691TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005692 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005693 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005694 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005695 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005696
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005697 // If nothing changed, just retain this statement.
5698 if (!getDerived().AlwaysRebuild() &&
5699 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005700 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005701
5702 // Build a new statement.
5703 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005704 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005705}
Mike Stump1eb44332009-09-09 15:08:12 +00005706
Douglas Gregor43959a92009-08-20 07:17:43 +00005707template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005708StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005709TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005710 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005711 if (S->getThrowExpr()) {
5712 Operand = getDerived().TransformExpr(S->getThrowExpr());
5713 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005714 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005715 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005716
Douglas Gregord1377b22010-04-22 21:44:01 +00005717 if (!getDerived().AlwaysRebuild() &&
5718 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005719 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005720
John McCall9ae2f072010-08-23 23:25:46 +00005721 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005722}
Mike Stump1eb44332009-09-09 15:08:12 +00005723
Douglas Gregor43959a92009-08-20 07:17:43 +00005724template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005725StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005726TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005727 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005728 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005729 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005730 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005731 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005732 Object =
5733 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5734 Object.get());
5735 if (Object.isInvalid())
5736 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005737
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005738 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005739 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005740 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005741 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005742
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005743 // If nothing change, just retain the current statement.
5744 if (!getDerived().AlwaysRebuild() &&
5745 Object.get() == S->getSynchExpr() &&
5746 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005747 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005748
5749 // Build a new statement.
5750 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005751 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005752}
5753
5754template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005755StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005756TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5757 ObjCAutoreleasePoolStmt *S) {
5758 // Transform the body.
5759 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5760 if (Body.isInvalid())
5761 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005762
John McCallf85e1932011-06-15 23:02:42 +00005763 // If nothing changed, just retain this statement.
5764 if (!getDerived().AlwaysRebuild() &&
5765 Body.get() == S->getSubStmt())
5766 return SemaRef.Owned(S);
5767
5768 // Build a new statement.
5769 return getDerived().RebuildObjCAutoreleasePoolStmt(
5770 S->getAtLoc(), Body.get());
5771}
5772
5773template<typename Derived>
5774StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005775TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005776 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005777 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005778 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005779 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005780 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005781
Douglas Gregorc3203e72010-04-22 23:10:45 +00005782 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005783 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005784 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005785 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005786
Douglas Gregorc3203e72010-04-22 23:10:45 +00005787 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005788 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005789 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005790 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005791
Douglas Gregorc3203e72010-04-22 23:10:45 +00005792 // If nothing changed, just retain this statement.
5793 if (!getDerived().AlwaysRebuild() &&
5794 Element.get() == S->getElement() &&
5795 Collection.get() == S->getCollection() &&
5796 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005797 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005798
Douglas Gregorc3203e72010-04-22 23:10:45 +00005799 // Build a new statement.
5800 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005801 Element.get(),
5802 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005803 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005804 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005805}
5806
5807
5808template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005809StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005810TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5811 // Transform the exception declaration, if any.
5812 VarDecl *Var = 0;
5813 if (S->getExceptionDecl()) {
5814 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005815 TypeSourceInfo *T = getDerived().TransformType(
5816 ExceptionDecl->getTypeSourceInfo());
5817 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005818 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005819
Douglas Gregor83cb9422010-09-09 17:09:21 +00005820 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005821 ExceptionDecl->getInnerLocStart(),
5822 ExceptionDecl->getLocation(),
5823 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005824 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005825 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005826 }
Mike Stump1eb44332009-09-09 15:08:12 +00005827
Douglas Gregor43959a92009-08-20 07:17:43 +00005828 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005829 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005830 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005831 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005832
Douglas Gregor43959a92009-08-20 07:17:43 +00005833 if (!getDerived().AlwaysRebuild() &&
5834 !Var &&
5835 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005836 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005837
5838 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5839 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005840 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005841}
Mike Stump1eb44332009-09-09 15:08:12 +00005842
Douglas Gregor43959a92009-08-20 07:17:43 +00005843template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005844StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005845TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5846 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005847 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005848 = getDerived().TransformCompoundStmt(S->getTryBlock());
5849 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005850 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005851
Douglas Gregor43959a92009-08-20 07:17:43 +00005852 // Transform the handlers.
5853 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005854 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005855 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005856 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005857 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5858 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005859 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005860
Douglas Gregor43959a92009-08-20 07:17:43 +00005861 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5862 Handlers.push_back(Handler.takeAs<Stmt>());
5863 }
Mike Stump1eb44332009-09-09 15:08:12 +00005864
Douglas Gregor43959a92009-08-20 07:17:43 +00005865 if (!getDerived().AlwaysRebuild() &&
5866 TryBlock.get() == S->getTryBlock() &&
5867 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005868 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005869
John McCall9ae2f072010-08-23 23:25:46 +00005870 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005871 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005872}
Mike Stump1eb44332009-09-09 15:08:12 +00005873
Richard Smithad762fc2011-04-14 22:09:26 +00005874template<typename Derived>
5875StmtResult
5876TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5877 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5878 if (Range.isInvalid())
5879 return StmtError();
5880
5881 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5882 if (BeginEnd.isInvalid())
5883 return StmtError();
5884
5885 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5886 if (Cond.isInvalid())
5887 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005888 if (Cond.get())
5889 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5890 if (Cond.isInvalid())
5891 return StmtError();
5892 if (Cond.get())
5893 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005894
5895 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5896 if (Inc.isInvalid())
5897 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005898 if (Inc.get())
5899 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005900
5901 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5902 if (LoopVar.isInvalid())
5903 return StmtError();
5904
5905 StmtResult NewStmt = S;
5906 if (getDerived().AlwaysRebuild() ||
5907 Range.get() != S->getRangeStmt() ||
5908 BeginEnd.get() != S->getBeginEndStmt() ||
5909 Cond.get() != S->getCond() ||
5910 Inc.get() != S->getInc() ||
5911 LoopVar.get() != S->getLoopVarStmt())
5912 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5913 S->getColonLoc(), Range.get(),
5914 BeginEnd.get(), Cond.get(),
5915 Inc.get(), LoopVar.get(),
5916 S->getRParenLoc());
5917
5918 StmtResult Body = getDerived().TransformStmt(S->getBody());
5919 if (Body.isInvalid())
5920 return StmtError();
5921
5922 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5923 // it now so we have a new statement to attach the body to.
5924 if (Body.get() != S->getBody() && NewStmt.get() == S)
5925 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5926 S->getColonLoc(), Range.get(),
5927 BeginEnd.get(), Cond.get(),
5928 Inc.get(), LoopVar.get(),
5929 S->getRParenLoc());
5930
5931 if (NewStmt.get() == S)
5932 return SemaRef.Owned(S);
5933
5934 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5935}
5936
John Wiegley28bbe4b2011-04-28 01:08:34 +00005937template<typename Derived>
5938StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005939TreeTransform<Derived>::TransformMSDependentExistsStmt(
5940 MSDependentExistsStmt *S) {
5941 // Transform the nested-name-specifier, if any.
5942 NestedNameSpecifierLoc QualifierLoc;
5943 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005944 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005945 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5946 if (!QualifierLoc)
5947 return StmtError();
5948 }
5949
5950 // Transform the declaration name.
5951 DeclarationNameInfo NameInfo = S->getNameInfo();
5952 if (NameInfo.getName()) {
5953 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5954 if (!NameInfo.getName())
5955 return StmtError();
5956 }
5957
5958 // Check whether anything changed.
5959 if (!getDerived().AlwaysRebuild() &&
5960 QualifierLoc == S->getQualifierLoc() &&
5961 NameInfo.getName() == S->getNameInfo().getName())
5962 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005963
Douglas Gregorba0513d2011-10-25 01:33:02 +00005964 // Determine whether this name exists, if we can.
5965 CXXScopeSpec SS;
5966 SS.Adopt(QualifierLoc);
5967 bool Dependent = false;
5968 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5969 case Sema::IER_Exists:
5970 if (S->isIfExists())
5971 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005972
Douglas Gregorba0513d2011-10-25 01:33:02 +00005973 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5974
5975 case Sema::IER_DoesNotExist:
5976 if (S->isIfNotExists())
5977 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005978
Douglas Gregorba0513d2011-10-25 01:33:02 +00005979 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005980
Douglas Gregorba0513d2011-10-25 01:33:02 +00005981 case Sema::IER_Dependent:
5982 Dependent = true;
5983 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005984
Douglas Gregor65019ac2011-10-25 03:44:56 +00005985 case Sema::IER_Error:
5986 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005987 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005988
Douglas Gregorba0513d2011-10-25 01:33:02 +00005989 // We need to continue with the instantiation, so do so now.
5990 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5991 if (SubStmt.isInvalid())
5992 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005993
Douglas Gregorba0513d2011-10-25 01:33:02 +00005994 // If we have resolved the name, just transform to the substatement.
5995 if (!Dependent)
5996 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005997
Douglas Gregorba0513d2011-10-25 01:33:02 +00005998 // The name is still dependent, so build a dependent expression again.
5999 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6000 S->isIfExists(),
6001 QualifierLoc,
6002 NameInfo,
6003 SubStmt.get());
6004}
6005
6006template<typename Derived>
6007StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006008TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6009 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6010 if(TryBlock.isInvalid()) return StmtError();
6011
6012 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6013 if(!getDerived().AlwaysRebuild() &&
6014 TryBlock.get() == S->getTryBlock() &&
6015 Handler.get() == S->getHandler())
6016 return SemaRef.Owned(S);
6017
6018 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6019 S->getTryLoc(),
6020 TryBlock.take(),
6021 Handler.take());
6022}
6023
6024template<typename Derived>
6025StmtResult
6026TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6027 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6028 if(Block.isInvalid()) return StmtError();
6029
6030 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6031 Block.take());
6032}
6033
6034template<typename Derived>
6035StmtResult
6036TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6037 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6038 if(FilterExpr.isInvalid()) return StmtError();
6039
6040 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6041 if(Block.isInvalid()) return StmtError();
6042
6043 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6044 FilterExpr.take(),
6045 Block.take());
6046}
6047
6048template<typename Derived>
6049StmtResult
6050TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6051 if(isa<SEHFinallyStmt>(Handler))
6052 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6053 else
6054 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6055}
6056
Douglas Gregor43959a92009-08-20 07:17:43 +00006057//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006058// Expression transformation
6059//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006060template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006061ExprResult
John McCall454feb92009-12-08 09:21:05 +00006062TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006063 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006064}
Mike Stump1eb44332009-09-09 15:08:12 +00006065
6066template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006067ExprResult
John McCall454feb92009-12-08 09:21:05 +00006068TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006069 NestedNameSpecifierLoc QualifierLoc;
6070 if (E->getQualifierLoc()) {
6071 QualifierLoc
6072 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6073 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006074 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006075 }
John McCalldbd872f2009-12-08 09:08:17 +00006076
6077 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006078 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6079 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006080 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006081 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006082
John McCallec8045d2010-08-17 21:27:17 +00006083 DeclarationNameInfo NameInfo = E->getNameInfo();
6084 if (NameInfo.getName()) {
6085 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6086 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006087 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006088 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006089
6090 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006091 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006092 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006093 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006094 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006095
6096 // Mark it referenced in the new context regardless.
6097 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006098 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006099
John McCall3fa5cae2010-10-26 07:05:15 +00006100 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006101 }
John McCalldbd872f2009-12-08 09:08:17 +00006102
6103 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006104 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006105 TemplateArgs = &TransArgs;
6106 TransArgs.setLAngleLoc(E->getLAngleLoc());
6107 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006108 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6109 E->getNumTemplateArgs(),
6110 TransArgs))
6111 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006112 }
6113
Chad Rosier4a9d7952012-08-08 18:46:20 +00006114 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006115 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006116}
Mike Stump1eb44332009-09-09 15:08:12 +00006117
Douglas Gregorb98b1992009-08-11 05:31:07 +00006118template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006119ExprResult
John McCall454feb92009-12-08 09:21:05 +00006120TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006121 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006122}
Mike Stump1eb44332009-09-09 15:08:12 +00006123
Douglas Gregorb98b1992009-08-11 05:31:07 +00006124template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006125ExprResult
John McCall454feb92009-12-08 09:21:05 +00006126TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006127 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006128}
Mike Stump1eb44332009-09-09 15:08:12 +00006129
Douglas Gregorb98b1992009-08-11 05:31:07 +00006130template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006131ExprResult
John McCall454feb92009-12-08 09:21:05 +00006132TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006133 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006134}
Mike Stump1eb44332009-09-09 15:08:12 +00006135
Douglas Gregorb98b1992009-08-11 05:31:07 +00006136template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006137ExprResult
John McCall454feb92009-12-08 09:21:05 +00006138TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006139 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006140}
Mike Stump1eb44332009-09-09 15:08:12 +00006141
Douglas Gregorb98b1992009-08-11 05:31:07 +00006142template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006143ExprResult
John McCall454feb92009-12-08 09:21:05 +00006144TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006145 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006146}
6147
6148template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006149ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006150TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6151 return SemaRef.MaybeBindToTemporary(E);
6152}
6153
6154template<typename Derived>
6155ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006156TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6157 ExprResult ControllingExpr =
6158 getDerived().TransformExpr(E->getControllingExpr());
6159 if (ControllingExpr.isInvalid())
6160 return ExprError();
6161
Chris Lattner686775d2011-07-20 06:58:45 +00006162 SmallVector<Expr *, 4> AssocExprs;
6163 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006164 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6165 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6166 if (TS) {
6167 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6168 if (!AssocType)
6169 return ExprError();
6170 AssocTypes.push_back(AssocType);
6171 } else {
6172 AssocTypes.push_back(0);
6173 }
6174
6175 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6176 if (AssocExpr.isInvalid())
6177 return ExprError();
6178 AssocExprs.push_back(AssocExpr.release());
6179 }
6180
6181 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6182 E->getDefaultLoc(),
6183 E->getRParenLoc(),
6184 ControllingExpr.release(),
6185 AssocTypes.data(),
6186 AssocExprs.data(),
6187 E->getNumAssocs());
6188}
6189
6190template<typename Derived>
6191ExprResult
John McCall454feb92009-12-08 09:21:05 +00006192TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006193 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006194 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006195 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006196
Douglas Gregorb98b1992009-08-11 05:31:07 +00006197 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006198 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006199
John McCall9ae2f072010-08-23 23:25:46 +00006200 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006201 E->getRParen());
6202}
6203
Mike Stump1eb44332009-09-09 15:08:12 +00006204template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006205ExprResult
John McCall454feb92009-12-08 09:21:05 +00006206TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006207 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006208 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006209 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006210
Douglas Gregorb98b1992009-08-11 05:31:07 +00006211 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006212 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006213
Douglas Gregorb98b1992009-08-11 05:31:07 +00006214 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6215 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006216 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006217}
Mike Stump1eb44332009-09-09 15:08:12 +00006218
Douglas Gregorb98b1992009-08-11 05:31:07 +00006219template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006220ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006221TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6222 // Transform the type.
6223 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6224 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006225 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006226
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006227 // Transform all of the components into components similar to what the
6228 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006229 // FIXME: It would be slightly more efficient in the non-dependent case to
6230 // just map FieldDecls, rather than requiring the rebuilder to look for
6231 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006232 // template code that we don't care.
6233 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006234 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006235 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006236 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006237 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6238 const Node &ON = E->getComponent(I);
6239 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006240 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006241 Comp.LocStart = ON.getSourceRange().getBegin();
6242 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006243 switch (ON.getKind()) {
6244 case Node::Array: {
6245 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006246 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006247 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006248 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006249
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006250 ExprChanged = ExprChanged || Index.get() != FromIndex;
6251 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006252 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006253 break;
6254 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006255
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006256 case Node::Field:
6257 case Node::Identifier:
6258 Comp.isBrackets = false;
6259 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006260 if (!Comp.U.IdentInfo)
6261 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006262
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006263 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006264
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006265 case Node::Base:
6266 // Will be recomputed during the rebuild.
6267 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006268 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006269
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006270 Components.push_back(Comp);
6271 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006272
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006273 // If nothing changed, retain the existing expression.
6274 if (!getDerived().AlwaysRebuild() &&
6275 Type == E->getTypeSourceInfo() &&
6276 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006277 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006278
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006279 // Build a new offsetof expression.
6280 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6281 Components.data(), Components.size(),
6282 E->getRParenLoc());
6283}
6284
6285template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006286ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006287TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6288 assert(getDerived().AlreadyTransformed(E->getType()) &&
6289 "opaque value expression requires transformation");
6290 return SemaRef.Owned(E);
6291}
6292
6293template<typename Derived>
6294ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006295TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006296 // Rebuild the syntactic form. The original syntactic form has
6297 // opaque-value expressions in it, so strip those away and rebuild
6298 // the result. This is a really awful way of doing this, but the
6299 // better solution (rebuilding the semantic expressions and
6300 // rebinding OVEs as necessary) doesn't work; we'd need
6301 // TreeTransform to not strip away implicit conversions.
6302 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6303 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006304 if (result.isInvalid()) return ExprError();
6305
6306 // If that gives us a pseudo-object result back, the pseudo-object
6307 // expression must have been an lvalue-to-rvalue conversion which we
6308 // should reapply.
6309 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6310 result = SemaRef.checkPseudoObjectRValue(result.take());
6311
6312 return result;
6313}
6314
6315template<typename Derived>
6316ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006317TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6318 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006319 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006320 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006321
John McCalla93c9342009-12-07 02:54:59 +00006322 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006323 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006324 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006325
John McCall5ab75172009-11-04 07:28:41 +00006326 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006327 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006328
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006329 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6330 E->getKind(),
6331 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006332 }
Mike Stump1eb44332009-09-09 15:08:12 +00006333
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006334 // C++0x [expr.sizeof]p1:
6335 // The operand is either an expression, which is an unevaluated operand
6336 // [...]
6337 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006338
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006339 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6340 if (SubExpr.isInvalid())
6341 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006342
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006343 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6344 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006345
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006346 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6347 E->getOperatorLoc(),
6348 E->getKind(),
6349 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006350}
Mike Stump1eb44332009-09-09 15:08:12 +00006351
Douglas Gregorb98b1992009-08-11 05:31:07 +00006352template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006353ExprResult
John McCall454feb92009-12-08 09:21:05 +00006354TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006355 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006356 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006357 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006358
John McCall60d7b3a2010-08-24 06:29:42 +00006359 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006360 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006361 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006362
6363
Douglas Gregorb98b1992009-08-11 05:31:07 +00006364 if (!getDerived().AlwaysRebuild() &&
6365 LHS.get() == E->getLHS() &&
6366 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006367 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006368
John McCall9ae2f072010-08-23 23:25:46 +00006369 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006370 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006371 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006372 E->getRBracketLoc());
6373}
Mike Stump1eb44332009-09-09 15:08:12 +00006374
6375template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006376ExprResult
John McCall454feb92009-12-08 09:21:05 +00006377TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006378 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006379 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006380 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006381 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006382
6383 // Transform arguments.
6384 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006385 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006386 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006387 &ArgChanged))
6388 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006389
Douglas Gregorb98b1992009-08-11 05:31:07 +00006390 if (!getDerived().AlwaysRebuild() &&
6391 Callee.get() == E->getCallee() &&
6392 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006393 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006394
Douglas Gregorb98b1992009-08-11 05:31:07 +00006395 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006396 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006397 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006398 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006399 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006400 E->getRParenLoc());
6401}
Mike Stump1eb44332009-09-09 15:08:12 +00006402
6403template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006404ExprResult
John McCall454feb92009-12-08 09:21:05 +00006405TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006406 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006407 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006408 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006409
Douglas Gregor40d96a62011-02-28 21:54:11 +00006410 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006411 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006412 QualifierLoc
6413 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006414
Douglas Gregor40d96a62011-02-28 21:54:11 +00006415 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006416 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006417 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006418 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006419
Eli Friedmanf595cc42009-12-04 06:40:45 +00006420 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006421 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6422 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006423 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006424 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006425
John McCall6bb80172010-03-30 21:47:33 +00006426 NamedDecl *FoundDecl = E->getFoundDecl();
6427 if (FoundDecl == E->getMemberDecl()) {
6428 FoundDecl = Member;
6429 } else {
6430 FoundDecl = cast_or_null<NamedDecl>(
6431 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6432 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006433 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006434 }
6435
Douglas Gregorb98b1992009-08-11 05:31:07 +00006436 if (!getDerived().AlwaysRebuild() &&
6437 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006438 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006439 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006440 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006441 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006442
Anders Carlsson1f240322009-12-22 05:24:09 +00006443 // Mark it referenced in the new context regardless.
6444 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006445 SemaRef.MarkMemberReferenced(E);
6446
John McCall3fa5cae2010-10-26 07:05:15 +00006447 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006448 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006449
John McCalld5532b62009-11-23 01:53:49 +00006450 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006451 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006452 TransArgs.setLAngleLoc(E->getLAngleLoc());
6453 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006454 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6455 E->getNumTemplateArgs(),
6456 TransArgs))
6457 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006458 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006459
Douglas Gregorb98b1992009-08-11 05:31:07 +00006460 // FIXME: Bogus source location for the operator
6461 SourceLocation FakeOperatorLoc
6462 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6463
John McCallc2233c52010-01-15 08:34:02 +00006464 // FIXME: to do this check properly, we will need to preserve the
6465 // first-qualifier-in-scope here, just in case we had a dependent
6466 // base (and therefore couldn't do the check) and a
6467 // nested-name-qualifier (and therefore could do the lookup).
6468 NamedDecl *FirstQualifierInScope = 0;
6469
John McCall9ae2f072010-08-23 23:25:46 +00006470 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006471 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006472 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006473 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006474 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006475 Member,
John McCall6bb80172010-03-30 21:47:33 +00006476 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006477 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006478 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006479 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006480}
Mike Stump1eb44332009-09-09 15:08:12 +00006481
Douglas Gregorb98b1992009-08-11 05:31:07 +00006482template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006483ExprResult
John McCall454feb92009-12-08 09:21:05 +00006484TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006485 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006486 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006487 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006488
John McCall60d7b3a2010-08-24 06:29:42 +00006489 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006490 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006491 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006492
Douglas Gregorb98b1992009-08-11 05:31:07 +00006493 if (!getDerived().AlwaysRebuild() &&
6494 LHS.get() == E->getLHS() &&
6495 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006496 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006497
Douglas Gregorb98b1992009-08-11 05:31:07 +00006498 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006499 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006500}
6501
Mike Stump1eb44332009-09-09 15:08:12 +00006502template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006503ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006504TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006505 CompoundAssignOperator *E) {
6506 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006507}
Mike Stump1eb44332009-09-09 15:08:12 +00006508
Douglas Gregorb98b1992009-08-11 05:31:07 +00006509template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006510ExprResult TreeTransform<Derived>::
6511TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6512 // Just rebuild the common and RHS expressions and see whether we
6513 // get any changes.
6514
6515 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6516 if (commonExpr.isInvalid())
6517 return ExprError();
6518
6519 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6520 if (rhs.isInvalid())
6521 return ExprError();
6522
6523 if (!getDerived().AlwaysRebuild() &&
6524 commonExpr.get() == e->getCommon() &&
6525 rhs.get() == e->getFalseExpr())
6526 return SemaRef.Owned(e);
6527
6528 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6529 e->getQuestionLoc(),
6530 0,
6531 e->getColonLoc(),
6532 rhs.get());
6533}
6534
6535template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006536ExprResult
John McCall454feb92009-12-08 09:21:05 +00006537TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006538 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006539 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006540 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006541
John McCall60d7b3a2010-08-24 06:29:42 +00006542 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006543 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006544 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006545
John McCall60d7b3a2010-08-24 06:29:42 +00006546 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006547 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006548 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006549
Douglas Gregorb98b1992009-08-11 05:31:07 +00006550 if (!getDerived().AlwaysRebuild() &&
6551 Cond.get() == E->getCond() &&
6552 LHS.get() == E->getLHS() &&
6553 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006554 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006555
John McCall9ae2f072010-08-23 23:25:46 +00006556 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006557 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006558 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006559 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006560 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006561}
Mike Stump1eb44332009-09-09 15:08:12 +00006562
6563template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006564ExprResult
John McCall454feb92009-12-08 09:21:05 +00006565TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006566 // Implicit casts are eliminated during transformation, since they
6567 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006568 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006569}
Mike Stump1eb44332009-09-09 15:08:12 +00006570
Douglas Gregorb98b1992009-08-11 05:31:07 +00006571template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006572ExprResult
John McCall454feb92009-12-08 09:21:05 +00006573TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006574 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6575 if (!Type)
6576 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006577
John McCall60d7b3a2010-08-24 06:29:42 +00006578 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006579 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006580 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006581 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006582
Douglas Gregorb98b1992009-08-11 05:31:07 +00006583 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006584 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006585 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006586 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006587
John McCall9d125032010-01-15 18:39:57 +00006588 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006589 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006590 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006591 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006592}
Mike Stump1eb44332009-09-09 15:08:12 +00006593
Douglas Gregorb98b1992009-08-11 05:31:07 +00006594template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006595ExprResult
John McCall454feb92009-12-08 09:21:05 +00006596TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006597 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6598 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6599 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006600 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006601
John McCall60d7b3a2010-08-24 06:29:42 +00006602 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006603 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006604 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006605
Douglas Gregorb98b1992009-08-11 05:31:07 +00006606 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006607 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006608 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006609 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006610
John McCall1d7d8d62010-01-19 22:33:45 +00006611 // Note: the expression type doesn't necessarily match the
6612 // type-as-written, but that's okay, because it should always be
6613 // derivable from the initializer.
6614
John McCall42f56b52010-01-18 19:35:47 +00006615 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006616 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006617 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006618}
Mike Stump1eb44332009-09-09 15:08:12 +00006619
Douglas Gregorb98b1992009-08-11 05:31:07 +00006620template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006621ExprResult
John McCall454feb92009-12-08 09:21:05 +00006622TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006623 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006624 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006625 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006626
Douglas Gregorb98b1992009-08-11 05:31:07 +00006627 if (!getDerived().AlwaysRebuild() &&
6628 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006629 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006630
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006632 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006634 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635 E->getAccessorLoc(),
6636 E->getAccessor());
6637}
Mike Stump1eb44332009-09-09 15:08:12 +00006638
Douglas Gregorb98b1992009-08-11 05:31:07 +00006639template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006640ExprResult
John McCall454feb92009-12-08 09:21:05 +00006641TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006642 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006643
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006644 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006645 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006646 Inits, &InitChanged))
6647 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006648
Douglas Gregorb98b1992009-08-11 05:31:07 +00006649 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006650 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006651
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006652 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006653 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654}
Mike Stump1eb44332009-09-09 15:08:12 +00006655
Douglas Gregorb98b1992009-08-11 05:31:07 +00006656template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006657ExprResult
John McCall454feb92009-12-08 09:21:05 +00006658TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006659 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006660
Douglas Gregor43959a92009-08-20 07:17:43 +00006661 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006662 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006663 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006664 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006665
Douglas Gregor43959a92009-08-20 07:17:43 +00006666 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006667 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006668 bool ExprChanged = false;
6669 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6670 DEnd = E->designators_end();
6671 D != DEnd; ++D) {
6672 if (D->isFieldDesignator()) {
6673 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6674 D->getDotLoc(),
6675 D->getFieldLoc()));
6676 continue;
6677 }
Mike Stump1eb44332009-09-09 15:08:12 +00006678
Douglas Gregorb98b1992009-08-11 05:31:07 +00006679 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006680 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006681 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006682 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006683
6684 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006685 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006686
Douglas Gregorb98b1992009-08-11 05:31:07 +00006687 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6688 ArrayExprs.push_back(Index.release());
6689 continue;
6690 }
Mike Stump1eb44332009-09-09 15:08:12 +00006691
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006693 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006694 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6695 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006696 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006697
John McCall60d7b3a2010-08-24 06:29:42 +00006698 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006699 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006700 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006701
6702 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006703 End.get(),
6704 D->getLBracketLoc(),
6705 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006706
Douglas Gregorb98b1992009-08-11 05:31:07 +00006707 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6708 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006709
Douglas Gregorb98b1992009-08-11 05:31:07 +00006710 ArrayExprs.push_back(Start.release());
6711 ArrayExprs.push_back(End.release());
6712 }
Mike Stump1eb44332009-09-09 15:08:12 +00006713
Douglas Gregorb98b1992009-08-11 05:31:07 +00006714 if (!getDerived().AlwaysRebuild() &&
6715 Init.get() == E->getInit() &&
6716 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006717 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006718
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006719 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006720 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006721 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006722}
Mike Stump1eb44332009-09-09 15:08:12 +00006723
Douglas Gregorb98b1992009-08-11 05:31:07 +00006724template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006725ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006727 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006728 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006729
Douglas Gregor5557b252009-10-28 00:29:27 +00006730 // FIXME: Will we ever have proper type location here? Will we actually
6731 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006732 QualType T = getDerived().TransformType(E->getType());
6733 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006734 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006735
Douglas Gregorb98b1992009-08-11 05:31:07 +00006736 if (!getDerived().AlwaysRebuild() &&
6737 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006738 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006739
Douglas Gregorb98b1992009-08-11 05:31:07 +00006740 return getDerived().RebuildImplicitValueInitExpr(T);
6741}
Mike Stump1eb44332009-09-09 15:08:12 +00006742
Douglas Gregorb98b1992009-08-11 05:31:07 +00006743template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006744ExprResult
John McCall454feb92009-12-08 09:21:05 +00006745TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006746 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6747 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006748 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006749
John McCall60d7b3a2010-08-24 06:29:42 +00006750 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006751 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006752 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006753
Douglas Gregorb98b1992009-08-11 05:31:07 +00006754 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006755 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006757 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006758
John McCall9ae2f072010-08-23 23:25:46 +00006759 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006760 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006761}
6762
6763template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006764ExprResult
John McCall454feb92009-12-08 09:21:05 +00006765TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006766 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006767 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006768 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6769 &ArgumentChanged))
6770 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006771
Douglas Gregorb98b1992009-08-11 05:31:07 +00006772 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006773 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006774 E->getRParenLoc());
6775}
Mike Stump1eb44332009-09-09 15:08:12 +00006776
Douglas Gregorb98b1992009-08-11 05:31:07 +00006777/// \brief Transform an address-of-label expression.
6778///
6779/// By default, the transformation of an address-of-label expression always
6780/// rebuilds the expression, so that the label identifier can be resolved to
6781/// the corresponding label statement by semantic analysis.
6782template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006783ExprResult
John McCall454feb92009-12-08 09:21:05 +00006784TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006785 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6786 E->getLabel());
6787 if (!LD)
6788 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006789
Douglas Gregorb98b1992009-08-11 05:31:07 +00006790 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006791 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006792}
Mike Stump1eb44332009-09-09 15:08:12 +00006793
6794template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006795ExprResult
John McCall454feb92009-12-08 09:21:05 +00006796TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006797 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006798 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006799 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006800 if (SubStmt.isInvalid()) {
6801 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006802 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006803 }
Mike Stump1eb44332009-09-09 15:08:12 +00006804
Douglas Gregorb98b1992009-08-11 05:31:07 +00006805 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006806 SubStmt.get() == E->getSubStmt()) {
6807 // Calling this an 'error' is unintuitive, but it does the right thing.
6808 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006809 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006810 }
Mike Stump1eb44332009-09-09 15:08:12 +00006811
6812 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006813 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006814 E->getRParenLoc());
6815}
Mike Stump1eb44332009-09-09 15:08:12 +00006816
Douglas Gregorb98b1992009-08-11 05:31:07 +00006817template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006818ExprResult
John McCall454feb92009-12-08 09:21:05 +00006819TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006820 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006821 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006822 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006823
John McCall60d7b3a2010-08-24 06:29:42 +00006824 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006825 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006826 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006827
John McCall60d7b3a2010-08-24 06:29:42 +00006828 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006829 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006830 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006831
Douglas Gregorb98b1992009-08-11 05:31:07 +00006832 if (!getDerived().AlwaysRebuild() &&
6833 Cond.get() == E->getCond() &&
6834 LHS.get() == E->getLHS() &&
6835 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006836 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006837
Douglas Gregorb98b1992009-08-11 05:31:07 +00006838 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006839 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006840 E->getRParenLoc());
6841}
Mike Stump1eb44332009-09-09 15:08:12 +00006842
Douglas Gregorb98b1992009-08-11 05:31:07 +00006843template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006844ExprResult
John McCall454feb92009-12-08 09:21:05 +00006845TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006846 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006847}
6848
6849template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006850ExprResult
John McCall454feb92009-12-08 09:21:05 +00006851TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006852 switch (E->getOperator()) {
6853 case OO_New:
6854 case OO_Delete:
6855 case OO_Array_New:
6856 case OO_Array_Delete:
6857 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006858
Douglas Gregor668d6d92009-12-13 20:44:55 +00006859 case OO_Call: {
6860 // This is a call to an object's operator().
6861 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6862
6863 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006864 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006865 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006866 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006867
6868 // FIXME: Poor location information
6869 SourceLocation FakeLParenLoc
6870 = SemaRef.PP.getLocForEndOfToken(
6871 static_cast<Expr *>(Object.get())->getLocEnd());
6872
6873 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006874 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006875 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006876 Args))
6877 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006878
John McCall9ae2f072010-08-23 23:25:46 +00006879 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006880 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006881 E->getLocEnd());
6882 }
6883
6884#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6885 case OO_##Name:
6886#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6887#include "clang/Basic/OperatorKinds.def"
6888 case OO_Subscript:
6889 // Handled below.
6890 break;
6891
6892 case OO_Conditional:
6893 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006894
6895 case OO_None:
6896 case NUM_OVERLOADED_OPERATORS:
6897 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006898 }
6899
John McCall60d7b3a2010-08-24 06:29:42 +00006900 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006901 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006902 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006903
John McCall60d7b3a2010-08-24 06:29:42 +00006904 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006905 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006906 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006907
John McCall60d7b3a2010-08-24 06:29:42 +00006908 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006909 if (E->getNumArgs() == 2) {
6910 Second = getDerived().TransformExpr(E->getArg(1));
6911 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006912 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006913 }
Mike Stump1eb44332009-09-09 15:08:12 +00006914
Douglas Gregorb98b1992009-08-11 05:31:07 +00006915 if (!getDerived().AlwaysRebuild() &&
6916 Callee.get() == E->getCallee() &&
6917 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006918 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006919 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006920
Douglas Gregorb98b1992009-08-11 05:31:07 +00006921 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6922 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006923 Callee.get(),
6924 First.get(),
6925 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006926}
Mike Stump1eb44332009-09-09 15:08:12 +00006927
Douglas Gregorb98b1992009-08-11 05:31:07 +00006928template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006929ExprResult
John McCall454feb92009-12-08 09:21:05 +00006930TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6931 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006932}
Mike Stump1eb44332009-09-09 15:08:12 +00006933
Douglas Gregorb98b1992009-08-11 05:31:07 +00006934template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006935ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006936TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6937 // Transform the callee.
6938 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6939 if (Callee.isInvalid())
6940 return ExprError();
6941
6942 // Transform exec config.
6943 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6944 if (EC.isInvalid())
6945 return ExprError();
6946
6947 // Transform arguments.
6948 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006949 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006950 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006951 &ArgChanged))
6952 return ExprError();
6953
6954 if (!getDerived().AlwaysRebuild() &&
6955 Callee.get() == E->getCallee() &&
6956 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006957 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006958
6959 // FIXME: Wrong source location information for the '('.
6960 SourceLocation FakeLParenLoc
6961 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6962 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006963 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006964 E->getRParenLoc(), EC.get());
6965}
6966
6967template<typename Derived>
6968ExprResult
John McCall454feb92009-12-08 09:21:05 +00006969TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006970 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6971 if (!Type)
6972 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006973
John McCall60d7b3a2010-08-24 06:29:42 +00006974 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006975 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006976 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006977 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006978
Douglas Gregorb98b1992009-08-11 05:31:07 +00006979 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006980 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006981 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006982 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006983
Douglas Gregorb98b1992009-08-11 05:31:07 +00006984 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006985 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006986 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6987 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6988 SourceLocation FakeRParenLoc
6989 = SemaRef.PP.getLocForEndOfToken(
6990 E->getSubExpr()->getSourceRange().getEnd());
6991 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006992 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006993 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006994 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006995 FakeRAngleLoc,
6996 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006997 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006998 FakeRParenLoc);
6999}
Mike Stump1eb44332009-09-09 15:08:12 +00007000
Douglas Gregorb98b1992009-08-11 05:31:07 +00007001template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007002ExprResult
John McCall454feb92009-12-08 09:21:05 +00007003TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7004 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007005}
Mike Stump1eb44332009-09-09 15:08:12 +00007006
7007template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007008ExprResult
John McCall454feb92009-12-08 09:21:05 +00007009TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7010 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007011}
7012
Douglas Gregorb98b1992009-08-11 05:31:07 +00007013template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007014ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007015TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007016 CXXReinterpretCastExpr *E) {
7017 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007018}
Mike Stump1eb44332009-09-09 15:08:12 +00007019
Douglas Gregorb98b1992009-08-11 05:31:07 +00007020template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007021ExprResult
John McCall454feb92009-12-08 09:21:05 +00007022TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7023 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007024}
Mike Stump1eb44332009-09-09 15:08:12 +00007025
Douglas Gregorb98b1992009-08-11 05:31:07 +00007026template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007027ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007028TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007029 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007030 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7031 if (!Type)
7032 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007033
John McCall60d7b3a2010-08-24 06:29:42 +00007034 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007035 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007036 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007037 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007038
Douglas Gregorb98b1992009-08-11 05:31:07 +00007039 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007040 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007041 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007042 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007043
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007044 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007045 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007046 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007047 E->getRParenLoc());
7048}
Mike Stump1eb44332009-09-09 15:08:12 +00007049
Douglas Gregorb98b1992009-08-11 05:31:07 +00007050template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007051ExprResult
John McCall454feb92009-12-08 09:21:05 +00007052TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007053 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007054 TypeSourceInfo *TInfo
7055 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7056 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007057 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007058
Douglas Gregorb98b1992009-08-11 05:31:07 +00007059 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007060 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007061 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007062
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007063 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7064 E->getLocStart(),
7065 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007066 E->getLocEnd());
7067 }
Mike Stump1eb44332009-09-09 15:08:12 +00007068
Eli Friedmanef331b72012-01-20 01:26:23 +00007069 // We don't know whether the subexpression is potentially evaluated until
7070 // after we perform semantic analysis. We speculatively assume it is
7071 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007072 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00007073 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00007074
John McCall60d7b3a2010-08-24 06:29:42 +00007075 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007076 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007077 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007078
Douglas Gregorb98b1992009-08-11 05:31:07 +00007079 if (!getDerived().AlwaysRebuild() &&
7080 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007081 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007082
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007083 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7084 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007085 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007086 E->getLocEnd());
7087}
7088
7089template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007090ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007091TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7092 if (E->isTypeOperand()) {
7093 TypeSourceInfo *TInfo
7094 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7095 if (!TInfo)
7096 return ExprError();
7097
7098 if (!getDerived().AlwaysRebuild() &&
7099 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007100 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007101
Douglas Gregor3c52a212011-03-06 17:40:41 +00007102 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007103 E->getLocStart(),
7104 TInfo,
7105 E->getLocEnd());
7106 }
7107
Francois Pichet01b7c302010-09-08 12:20:18 +00007108 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7109
7110 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7111 if (SubExpr.isInvalid())
7112 return ExprError();
7113
7114 if (!getDerived().AlwaysRebuild() &&
7115 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007116 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007117
7118 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7119 E->getLocStart(),
7120 SubExpr.get(),
7121 E->getLocEnd());
7122}
7123
7124template<typename Derived>
7125ExprResult
John McCall454feb92009-12-08 09:21:05 +00007126TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007127 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007128}
Mike Stump1eb44332009-09-09 15:08:12 +00007129
Douglas Gregorb98b1992009-08-11 05:31:07 +00007130template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007131ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007132TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007133 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007134 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007135}
Mike Stump1eb44332009-09-09 15:08:12 +00007136
Douglas Gregorb98b1992009-08-11 05:31:07 +00007137template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007138ExprResult
John McCall454feb92009-12-08 09:21:05 +00007139TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007140 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007141 QualType T;
7142 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7143 T = MD->getThisType(getSema().Context);
7144 else
7145 T = getSema().Context.getPointerType(
7146 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007147
Douglas Gregorec79d872012-02-24 17:41:38 +00007148 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7149 // Make sure that we capture 'this'.
7150 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007151 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007152 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007153
Douglas Gregor828a1972010-01-07 23:12:05 +00007154 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007155}
Mike Stump1eb44332009-09-09 15:08:12 +00007156
Douglas Gregorb98b1992009-08-11 05:31:07 +00007157template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007158ExprResult
John McCall454feb92009-12-08 09:21:05 +00007159TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007160 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007161 if (SubExpr.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 if (!getDerived().AlwaysRebuild() &&
7165 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007166 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007167
Douglas Gregorbca01b42011-07-06 22:04:06 +00007168 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7169 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007170}
Mike Stump1eb44332009-09-09 15:08:12 +00007171
Douglas Gregorb98b1992009-08-11 05:31:07 +00007172template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007173ExprResult
John McCall454feb92009-12-08 09:21:05 +00007174TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007175 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007176 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7177 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007178 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007179 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007180
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007181 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007182 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007183 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007184
Douglas Gregor036aed12009-12-23 23:03:06 +00007185 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007186}
Mike Stump1eb44332009-09-09 15:08:12 +00007187
Douglas Gregorb98b1992009-08-11 05:31:07 +00007188template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007189ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007190TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7191 CXXScalarValueInitExpr *E) {
7192 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7193 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007194 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007195
Douglas Gregorb98b1992009-08-11 05:31:07 +00007196 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007197 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007198 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007199
Chad Rosier4a9d7952012-08-08 18:46:20 +00007200 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007201 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007202 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007203}
Mike Stump1eb44332009-09-09 15:08:12 +00007204
Douglas Gregorb98b1992009-08-11 05:31:07 +00007205template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007206ExprResult
John McCall454feb92009-12-08 09:21:05 +00007207TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007208 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007209 TypeSourceInfo *AllocTypeInfo
7210 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7211 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007212 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007213
Douglas Gregorb98b1992009-08-11 05:31:07 +00007214 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007215 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007216 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007217 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007218
Douglas Gregorb98b1992009-08-11 05:31:07 +00007219 // Transform the placement arguments (if any).
7220 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007221 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007222 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007223 E->getNumPlacementArgs(), true,
7224 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007225 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007226
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007227 // Transform the initializer (if any).
7228 Expr *OldInit = E->getInitializer();
7229 ExprResult NewInit;
7230 if (OldInit)
7231 NewInit = getDerived().TransformExpr(OldInit);
7232 if (NewInit.isInvalid())
7233 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007234
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007235 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007236 FunctionDecl *OperatorNew = 0;
7237 if (E->getOperatorNew()) {
7238 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007239 getDerived().TransformDecl(E->getLocStart(),
7240 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007241 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007242 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007243 }
7244
7245 FunctionDecl *OperatorDelete = 0;
7246 if (E->getOperatorDelete()) {
7247 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007248 getDerived().TransformDecl(E->getLocStart(),
7249 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007250 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007251 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007252 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007253
Douglas Gregorb98b1992009-08-11 05:31:07 +00007254 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007255 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007256 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007257 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007258 OperatorNew == E->getOperatorNew() &&
7259 OperatorDelete == E->getOperatorDelete() &&
7260 !ArgumentChanged) {
7261 // Mark any declarations we need as referenced.
7262 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007263 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007264 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007265 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007266 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007267
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007268 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007269 QualType ElementType
7270 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7271 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7272 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7273 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007274 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007275 }
7276 }
7277 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007278
John McCall3fa5cae2010-10-26 07:05:15 +00007279 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007280 }
Mike Stump1eb44332009-09-09 15:08:12 +00007281
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007282 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007283 if (!ArraySize.get()) {
7284 // If no array size was specified, but the new expression was
7285 // instantiated with an array type (e.g., "new T" where T is
7286 // instantiated with "int[4]"), extract the outer bound from the
7287 // array type as our array size. We do this with constant and
7288 // dependently-sized array types.
7289 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7290 if (!ArrayT) {
7291 // Do nothing
7292 } else if (const ConstantArrayType *ConsArrayT
7293 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007294 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007295 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007296 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007297 SemaRef.Context.getSizeType(),
7298 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007299 AllocType = ConsArrayT->getElementType();
7300 } else if (const DependentSizedArrayType *DepArrayT
7301 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7302 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007303 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007304 AllocType = DepArrayT->getElementType();
7305 }
7306 }
7307 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007308
Douglas Gregorb98b1992009-08-11 05:31:07 +00007309 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7310 E->isGlobalNew(),
7311 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007312 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007313 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007314 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007315 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007316 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007317 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007318 E->getDirectInitRange(),
7319 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007320}
Mike Stump1eb44332009-09-09 15:08:12 +00007321
Douglas Gregorb98b1992009-08-11 05:31:07 +00007322template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007323ExprResult
John McCall454feb92009-12-08 09:21:05 +00007324TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007325 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007326 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007327 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007328
Douglas Gregor1af74512010-02-26 00:38:10 +00007329 // Transform the delete operator, if known.
7330 FunctionDecl *OperatorDelete = 0;
7331 if (E->getOperatorDelete()) {
7332 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007333 getDerived().TransformDecl(E->getLocStart(),
7334 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007335 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007336 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007337 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007338
Douglas Gregorb98b1992009-08-11 05:31:07 +00007339 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007340 Operand.get() == E->getArgument() &&
7341 OperatorDelete == E->getOperatorDelete()) {
7342 // Mark any declarations we need as referenced.
7343 // FIXME: instantiation-specific.
7344 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007345 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007346
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007347 if (!E->getArgument()->isTypeDependent()) {
7348 QualType Destroyed = SemaRef.Context.getBaseElementType(
7349 E->getDestroyedType());
7350 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7351 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007352 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007353 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007354 }
7355 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007356
John McCall3fa5cae2010-10-26 07:05:15 +00007357 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007358 }
Mike Stump1eb44332009-09-09 15:08:12 +00007359
Douglas Gregorb98b1992009-08-11 05:31:07 +00007360 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7361 E->isGlobalDelete(),
7362 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007363 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007364}
Mike Stump1eb44332009-09-09 15:08:12 +00007365
Douglas Gregorb98b1992009-08-11 05:31:07 +00007366template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007367ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007368TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007369 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007370 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007371 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007372 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007373
John McCallb3d87482010-08-24 05:47:05 +00007374 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007375 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007376 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007377 E->getOperatorLoc(),
7378 E->isArrow()? tok::arrow : tok::period,
7379 ObjectTypePtr,
7380 MayBePseudoDestructor);
7381 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007382 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007383
John McCallb3d87482010-08-24 05:47:05 +00007384 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007385 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7386 if (QualifierLoc) {
7387 QualifierLoc
7388 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7389 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007390 return ExprError();
7391 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007392 CXXScopeSpec SS;
7393 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007394
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007395 PseudoDestructorTypeStorage Destroyed;
7396 if (E->getDestroyedTypeInfo()) {
7397 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007398 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007399 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007400 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007401 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007402 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007403 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007404 // We aren't likely to be able to resolve the identifier down to a type
7405 // now anyway, so just retain the identifier.
7406 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7407 E->getDestroyedTypeLoc());
7408 } else {
7409 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007410 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007411 *E->getDestroyedTypeIdentifier(),
7412 E->getDestroyedTypeLoc(),
7413 /*Scope=*/0,
7414 SS, ObjectTypePtr,
7415 false);
7416 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007417 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007418
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007419 Destroyed
7420 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7421 E->getDestroyedTypeLoc());
7422 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007423
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007424 TypeSourceInfo *ScopeTypeInfo = 0;
7425 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007426 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007427 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007428 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007429 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007430
John McCall9ae2f072010-08-23 23:25:46 +00007431 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007432 E->getOperatorLoc(),
7433 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007434 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007435 ScopeTypeInfo,
7436 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007437 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007438 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007439}
Mike Stump1eb44332009-09-09 15:08:12 +00007440
Douglas Gregora71d8192009-09-04 17:36:40 +00007441template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007442ExprResult
John McCallba135432009-11-21 08:51:07 +00007443TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007444 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007445 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7446 Sema::LookupOrdinaryName);
7447
7448 // Transform all the decls.
7449 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7450 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007451 NamedDecl *InstD = static_cast<NamedDecl*>(
7452 getDerived().TransformDecl(Old->getNameLoc(),
7453 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007454 if (!InstD) {
7455 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7456 // This can happen because of dependent hiding.
7457 if (isa<UsingShadowDecl>(*I))
7458 continue;
7459 else
John McCallf312b1e2010-08-26 23:41:50 +00007460 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007461 }
John McCallf7a1a742009-11-24 19:00:30 +00007462
7463 // Expand using declarations.
7464 if (isa<UsingDecl>(InstD)) {
7465 UsingDecl *UD = cast<UsingDecl>(InstD);
7466 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7467 E = UD->shadow_end(); I != E; ++I)
7468 R.addDecl(*I);
7469 continue;
7470 }
7471
7472 R.addDecl(InstD);
7473 }
7474
7475 // Resolve a kind, but don't do any further analysis. If it's
7476 // ambiguous, the callee needs to deal with it.
7477 R.resolveKind();
7478
7479 // Rebuild the nested-name qualifier, if present.
7480 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007481 if (Old->getQualifierLoc()) {
7482 NestedNameSpecifierLoc QualifierLoc
7483 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7484 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007485 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007486
Douglas Gregor4c9be892011-02-28 20:01:57 +00007487 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007488 }
7489
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007490 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007491 CXXRecordDecl *NamingClass
7492 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7493 Old->getNameLoc(),
7494 Old->getNamingClass()));
7495 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007496 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007497
Douglas Gregor66c45152010-04-27 16:10:10 +00007498 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007499 }
7500
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007501 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7502
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007503 // If we have neither explicit template arguments, nor the template keyword,
7504 // it's a normal declaration name.
7505 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007506 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7507
7508 // If we have template arguments, rebuild them, then rebuild the
7509 // templateid expression.
7510 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007511 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7512 Old->getNumTemplateArgs(),
7513 TransArgs))
7514 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007515
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007516 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007517 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007518}
Mike Stump1eb44332009-09-09 15:08:12 +00007519
Douglas Gregorb98b1992009-08-11 05:31:07 +00007520template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007521ExprResult
John McCall454feb92009-12-08 09:21:05 +00007522TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007523 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7524 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007525 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007526
Douglas Gregorb98b1992009-08-11 05:31:07 +00007527 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007528 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007529 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007530
Mike Stump1eb44332009-09-09 15:08:12 +00007531 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007532 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007533 T,
7534 E->getLocEnd());
7535}
Mike Stump1eb44332009-09-09 15:08:12 +00007536
Douglas Gregorb98b1992009-08-11 05:31:07 +00007537template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007538ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007539TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7540 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7541 if (!LhsT)
7542 return ExprError();
7543
7544 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7545 if (!RhsT)
7546 return ExprError();
7547
7548 if (!getDerived().AlwaysRebuild() &&
7549 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7550 return SemaRef.Owned(E);
7551
7552 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7553 E->getLocStart(),
7554 LhsT, RhsT,
7555 E->getLocEnd());
7556}
7557
7558template<typename Derived>
7559ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007560TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7561 bool ArgChanged = false;
7562 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7563 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7564 TypeSourceInfo *From = E->getArg(I);
7565 TypeLoc FromTL = From->getTypeLoc();
7566 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7567 TypeLocBuilder TLB;
7568 TLB.reserve(FromTL.getFullDataSize());
7569 QualType To = getDerived().TransformType(TLB, FromTL);
7570 if (To.isNull())
7571 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007572
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007573 if (To == From->getType())
7574 Args.push_back(From);
7575 else {
7576 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7577 ArgChanged = true;
7578 }
7579 continue;
7580 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007581
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007582 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007583
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007584 // We have a pack expansion. Instantiate it.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007585 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007586 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7587 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7588 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007589
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007590 // Determine whether the set of unexpanded parameter packs can and should
7591 // be expanded.
7592 bool Expand = true;
7593 bool RetainExpansion = false;
7594 llvm::Optional<unsigned> OrigNumExpansions
7595 = ExpansionTL.getTypePtr()->getNumExpansions();
7596 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7597 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7598 PatternTL.getSourceRange(),
7599 Unexpanded,
7600 Expand, RetainExpansion,
7601 NumExpansions))
7602 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007603
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007604 if (!Expand) {
7605 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007606 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007607 // expansion.
7608 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007609
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007610 TypeLocBuilder TLB;
7611 TLB.reserve(From->getTypeLoc().getFullDataSize());
7612
7613 QualType To = getDerived().TransformType(TLB, PatternTL);
7614 if (To.isNull())
7615 return ExprError();
7616
Chad Rosier4a9d7952012-08-08 18:46:20 +00007617 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007618 PatternTL.getSourceRange(),
7619 ExpansionTL.getEllipsisLoc(),
7620 NumExpansions);
7621 if (To.isNull())
7622 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007623
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007624 PackExpansionTypeLoc ToExpansionTL
7625 = TLB.push<PackExpansionTypeLoc>(To);
7626 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7627 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7628 continue;
7629 }
7630
7631 // Expand the pack expansion by substituting for each argument in the
7632 // pack(s).
7633 for (unsigned I = 0; I != *NumExpansions; ++I) {
7634 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7635 TypeLocBuilder TLB;
7636 TLB.reserve(PatternTL.getFullDataSize());
7637 QualType To = getDerived().TransformType(TLB, PatternTL);
7638 if (To.isNull())
7639 return ExprError();
7640
7641 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7642 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007643
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007644 if (!RetainExpansion)
7645 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007646
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007647 // If we're supposed to retain a pack expansion, do so by temporarily
7648 // forgetting the partially-substituted parameter pack.
7649 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7650
7651 TypeLocBuilder TLB;
7652 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007653
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007654 QualType To = getDerived().TransformType(TLB, PatternTL);
7655 if (To.isNull())
7656 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007657
7658 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007659 PatternTL.getSourceRange(),
7660 ExpansionTL.getEllipsisLoc(),
7661 NumExpansions);
7662 if (To.isNull())
7663 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007664
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007665 PackExpansionTypeLoc ToExpansionTL
7666 = TLB.push<PackExpansionTypeLoc>(To);
7667 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7668 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7669 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007670
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007671 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7672 return SemaRef.Owned(E);
7673
7674 return getDerived().RebuildTypeTrait(E->getTrait(),
7675 E->getLocStart(),
7676 Args,
7677 E->getLocEnd());
7678}
7679
7680template<typename Derived>
7681ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007682TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7683 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7684 if (!T)
7685 return ExprError();
7686
7687 if (!getDerived().AlwaysRebuild() &&
7688 T == E->getQueriedTypeSourceInfo())
7689 return SemaRef.Owned(E);
7690
7691 ExprResult SubExpr;
7692 {
7693 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7694 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7695 if (SubExpr.isInvalid())
7696 return ExprError();
7697
7698 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7699 return SemaRef.Owned(E);
7700 }
7701
7702 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7703 E->getLocStart(),
7704 T,
7705 SubExpr.get(),
7706 E->getLocEnd());
7707}
7708
7709template<typename Derived>
7710ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007711TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7712 ExprResult SubExpr;
7713 {
7714 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7715 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7716 if (SubExpr.isInvalid())
7717 return ExprError();
7718
7719 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7720 return SemaRef.Owned(E);
7721 }
7722
7723 return getDerived().RebuildExpressionTrait(
7724 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7725}
7726
7727template<typename Derived>
7728ExprResult
John McCall865d4472009-11-19 22:55:06 +00007729TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007730 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007731 NestedNameSpecifierLoc QualifierLoc
7732 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7733 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007734 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007735 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007736
John McCall43fed0d2010-11-12 08:19:04 +00007737 // TODO: If this is a conversion-function-id, verify that the
7738 // destination type name (if present) resolves the same way after
7739 // instantiation as it did in the local scope.
7740
Abramo Bagnara25777432010-08-11 22:01:17 +00007741 DeclarationNameInfo NameInfo
7742 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7743 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007744 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007745
John McCallf7a1a742009-11-24 19:00:30 +00007746 if (!E->hasExplicitTemplateArgs()) {
7747 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007748 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007749 // Note: it is sufficient to compare the Name component of NameInfo:
7750 // if name has not changed, DNLoc has not changed either.
7751 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007752 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007753
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007754 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007755 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007756 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007757 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007758 }
John McCalld5532b62009-11-23 01:53:49 +00007759
7760 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007761 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7762 E->getNumTemplateArgs(),
7763 TransArgs))
7764 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007765
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007766 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007767 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007768 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007769 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007770}
7771
7772template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007773ExprResult
John McCall454feb92009-12-08 09:21:05 +00007774TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007775 // CXXConstructExprs are always implicit, so when we have a
7776 // 1-argument construction we just transform that argument.
7777 if (E->getNumArgs() == 1 ||
7778 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7779 return getDerived().TransformExpr(E->getArg(0));
7780
Douglas Gregorb98b1992009-08-11 05:31:07 +00007781 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7782
7783 QualType T = getDerived().TransformType(E->getType());
7784 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007785 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007786
7787 CXXConstructorDecl *Constructor
7788 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007789 getDerived().TransformDecl(E->getLocStart(),
7790 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007791 if (!Constructor)
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 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007795 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007796 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007797 &ArgumentChanged))
7798 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007799
Douglas Gregorb98b1992009-08-11 05:31:07 +00007800 if (!getDerived().AlwaysRebuild() &&
7801 T == E->getType() &&
7802 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007803 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007804 // Mark the constructor as referenced.
7805 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007806 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007807 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007808 }
Mike Stump1eb44332009-09-09 15:08:12 +00007809
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007810 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7811 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007812 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007813 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007814 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007815 E->getConstructionKind(),
7816 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007817}
Mike Stump1eb44332009-09-09 15:08:12 +00007818
Douglas Gregorb98b1992009-08-11 05:31:07 +00007819/// \brief Transform a C++ temporary-binding expression.
7820///
Douglas Gregor51326552009-12-24 18:51:59 +00007821/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7822/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007823template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007824ExprResult
John McCall454feb92009-12-08 09:21:05 +00007825TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007826 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007827}
Mike Stump1eb44332009-09-09 15:08:12 +00007828
John McCall4765fa02010-12-06 08:20:24 +00007829/// \brief Transform a C++ expression that contains cleanups that should
7830/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007831///
John McCall4765fa02010-12-06 08:20:24 +00007832/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007833/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007834template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007835ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007836TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007837 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007838}
Mike Stump1eb44332009-09-09 15:08:12 +00007839
Douglas Gregorb98b1992009-08-11 05:31:07 +00007840template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007841ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007842TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007843 CXXTemporaryObjectExpr *E) {
7844 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7845 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007846 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007847
Douglas Gregorb98b1992009-08-11 05:31:07 +00007848 CXXConstructorDecl *Constructor
7849 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007850 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007851 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007852 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007853 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007854
Douglas Gregorb98b1992009-08-11 05:31:07 +00007855 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007856 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007857 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007858 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007859 &ArgumentChanged))
7860 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007861
Douglas Gregorb98b1992009-08-11 05:31:07 +00007862 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007863 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007864 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007865 !ArgumentChanged) {
7866 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007867 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007868 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007869 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007870
Douglas Gregorab6677e2010-09-08 00:15:04 +00007871 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7872 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007873 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007874 E->getLocEnd());
7875}
Mike Stump1eb44332009-09-09 15:08:12 +00007876
Douglas Gregorb98b1992009-08-11 05:31:07 +00007877template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007878ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007879TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007880 // Create the local class that will describe the lambda.
7881 CXXRecordDecl *Class
Douglas Gregorf54486a2012-04-04 17:40:10 +00007882 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7883 /*KnownDependent=*/false);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007884 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007885
Douglas Gregordfca6f52012-02-13 22:00:16 +00007886 // Transform the type of the lambda parameters and start the definition of
7887 // the lambda itself.
7888 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00007889 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00007890 if (!MethodTy)
7891 return ExprError();
7892
Douglas Gregorc6889e72012-02-14 22:28:59 +00007893 // Transform lambda parameters.
Douglas Gregorc6889e72012-02-14 22:28:59 +00007894 llvm::SmallVector<QualType, 4> ParamTypes;
7895 llvm::SmallVector<ParmVarDecl *, 4> Params;
7896 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7897 E->getCallOperator()->param_begin(),
7898 E->getCallOperator()->param_size(),
7899 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00007900 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00007901
Douglas Gregordfca6f52012-02-13 22:00:16 +00007902 // Build the call operator.
7903 CXXMethodDecl *CallOperator
7904 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007905 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007906 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007907 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007908 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00007909
Richard Smith612409e2012-07-25 03:56:55 +00007910 return getDerived().TransformLambdaScope(E, CallOperator);
7911}
7912
7913template<typename Derived>
7914ExprResult
7915TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
7916 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00007917 // Introduce the context of the call operator.
7918 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7919
Douglas Gregordfca6f52012-02-13 22:00:16 +00007920 // Enter the scope of the lambda.
7921 sema::LambdaScopeInfo *LSI
7922 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7923 E->getCaptureDefault(),
7924 E->hasExplicitParameters(),
7925 E->hasExplicitResultType(),
7926 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007927
Douglas Gregordfca6f52012-02-13 22:00:16 +00007928 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00007929 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00007930 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007931 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007932 CEnd = E->capture_end();
7933 C != CEnd; ++C) {
7934 // When we hit the first implicit capture, tell Sema that we've finished
7935 // the list of explicit captures.
7936 if (!FinishedExplicitCaptures && C->isImplicit()) {
7937 getSema().finishLambdaExplicitCaptures(LSI);
7938 FinishedExplicitCaptures = true;
7939 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007940
Douglas Gregordfca6f52012-02-13 22:00:16 +00007941 // Capturing 'this' is trivial.
7942 if (C->capturesThis()) {
7943 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7944 continue;
7945 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007946
Douglas Gregora7365242012-02-14 19:27:52 +00007947 // Determine the capture kind for Sema.
7948 Sema::TryCaptureKind Kind
7949 = C->isImplicit()? Sema::TryCapture_Implicit
7950 : C->getCaptureKind() == LCK_ByCopy
7951 ? Sema::TryCapture_ExplicitByVal
7952 : Sema::TryCapture_ExplicitByRef;
7953 SourceLocation EllipsisLoc;
7954 if (C->isPackExpansion()) {
7955 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7956 bool ShouldExpand = false;
7957 bool RetainExpansion = false;
7958 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007959 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7960 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00007961 Unexpanded,
7962 ShouldExpand, RetainExpansion,
7963 NumExpansions))
7964 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007965
Douglas Gregora7365242012-02-14 19:27:52 +00007966 if (ShouldExpand) {
7967 // The transform has determined that we should perform an expansion;
7968 // transform and capture each of the arguments.
7969 // expansion of the pattern. Do so.
7970 VarDecl *Pack = C->getCapturedVar();
7971 for (unsigned I = 0; I != *NumExpansions; ++I) {
7972 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7973 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00007974 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00007975 Pack));
7976 if (!CapturedVar) {
7977 Invalid = true;
7978 continue;
7979 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007980
Douglas Gregora7365242012-02-14 19:27:52 +00007981 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007982 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
7983 }
Douglas Gregora7365242012-02-14 19:27:52 +00007984 continue;
7985 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007986
Douglas Gregora7365242012-02-14 19:27:52 +00007987 EllipsisLoc = C->getEllipsisLoc();
7988 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007989
Douglas Gregordfca6f52012-02-13 22:00:16 +00007990 // Transform the captured variable.
7991 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00007992 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007993 C->getCapturedVar()));
7994 if (!CapturedVar) {
7995 Invalid = true;
7996 continue;
7997 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007998
Douglas Gregordfca6f52012-02-13 22:00:16 +00007999 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008000 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008001 }
8002 if (!FinishedExplicitCaptures)
8003 getSema().finishLambdaExplicitCaptures(LSI);
8004
Douglas Gregordfca6f52012-02-13 22:00:16 +00008005
8006 // Enter a new evaluation context to insulate the lambda from any
8007 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008008 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008009
8010 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008011 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008012 /*IsInstantiation=*/true);
8013 return ExprError();
8014 }
8015
8016 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008017 StmtResult Body = getDerived().TransformStmt(E->getBody());
8018 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008019 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008020 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008021 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008022 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008023
Chad Rosier4a9d7952012-08-08 18:46:20 +00008024 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008025 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008026}
8027
8028template<typename Derived>
8029ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008030TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008031 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008032 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8033 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008034 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008035
Douglas Gregorb98b1992009-08-11 05:31:07 +00008036 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008037 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008038 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008039 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008040 &ArgumentChanged))
8041 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008042
Douglas Gregorb98b1992009-08-11 05:31:07 +00008043 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008044 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008045 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008046 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008047
Douglas Gregorb98b1992009-08-11 05:31:07 +00008048 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008049 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008050 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008051 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008052 E->getRParenLoc());
8053}
Mike Stump1eb44332009-09-09 15:08:12 +00008054
Douglas Gregorb98b1992009-08-11 05:31:07 +00008055template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008056ExprResult
John McCall865d4472009-11-19 22:55:06 +00008057TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008058 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008059 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008060 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008061 Expr *OldBase;
8062 QualType BaseType;
8063 QualType ObjectType;
8064 if (!E->isImplicitAccess()) {
8065 OldBase = E->getBase();
8066 Base = getDerived().TransformExpr(OldBase);
8067 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008068 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008069
John McCallaa81e162009-12-01 22:10:20 +00008070 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008071 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008072 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008073 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008074 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008075 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008076 ObjectTy,
8077 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008078 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008079 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008080
John McCallb3d87482010-08-24 05:47:05 +00008081 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008082 BaseType = ((Expr*) Base.get())->getType();
8083 } else {
8084 OldBase = 0;
8085 BaseType = getDerived().TransformType(E->getBaseType());
8086 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8087 }
Mike Stump1eb44332009-09-09 15:08:12 +00008088
Douglas Gregor6cd21982009-10-20 05:58:46 +00008089 // Transform the first part of the nested-name-specifier that qualifies
8090 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008091 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008092 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008093 E->getFirstQualifierFoundInScope(),
8094 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008095
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008096 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008097 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008098 QualifierLoc
8099 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8100 ObjectType,
8101 FirstQualifierInScope);
8102 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008103 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008104 }
Mike Stump1eb44332009-09-09 15:08:12 +00008105
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008106 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8107
John McCall43fed0d2010-11-12 08:19:04 +00008108 // TODO: If this is a conversion-function-id, verify that the
8109 // destination type name (if present) resolves the same way after
8110 // instantiation as it did in the local scope.
8111
Abramo Bagnara25777432010-08-11 22:01:17 +00008112 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008113 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008114 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008115 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008116
John McCallaa81e162009-12-01 22:10:20 +00008117 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008118 // This is a reference to a member without an explicitly-specified
8119 // template argument list. Optimize for this common case.
8120 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008121 Base.get() == OldBase &&
8122 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008123 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008124 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008125 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008126 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008127
John McCall9ae2f072010-08-23 23:25:46 +00008128 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008129 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008130 E->isArrow(),
8131 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008132 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008133 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008134 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008135 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008136 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008137 }
8138
John McCalld5532b62009-11-23 01:53:49 +00008139 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008140 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8141 E->getNumTemplateArgs(),
8142 TransArgs))
8143 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008144
John McCall9ae2f072010-08-23 23:25:46 +00008145 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008146 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008147 E->isArrow(),
8148 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008149 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008150 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008151 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008152 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008153 &TransArgs);
8154}
8155
8156template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008157ExprResult
John McCall454feb92009-12-08 09:21:05 +00008158TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008159 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008160 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008161 QualType BaseType;
8162 if (!Old->isImplicitAccess()) {
8163 Base = getDerived().TransformExpr(Old->getBase());
8164 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008165 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008166 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8167 Old->isArrow());
8168 if (Base.isInvalid())
8169 return ExprError();
8170 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008171 } else {
8172 BaseType = getDerived().TransformType(Old->getBaseType());
8173 }
John McCall129e2df2009-11-30 22:42:35 +00008174
Douglas Gregor4c9be892011-02-28 20:01:57 +00008175 NestedNameSpecifierLoc QualifierLoc;
8176 if (Old->getQualifierLoc()) {
8177 QualifierLoc
8178 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8179 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008180 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008181 }
8182
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008183 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8184
Abramo Bagnara25777432010-08-11 22:01:17 +00008185 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008186 Sema::LookupOrdinaryName);
8187
8188 // Transform all the decls.
8189 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8190 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008191 NamedDecl *InstD = static_cast<NamedDecl*>(
8192 getDerived().TransformDecl(Old->getMemberLoc(),
8193 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008194 if (!InstD) {
8195 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8196 // This can happen because of dependent hiding.
8197 if (isa<UsingShadowDecl>(*I))
8198 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008199 else {
8200 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008201 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008202 }
John McCall9f54ad42009-12-10 09:41:52 +00008203 }
John McCall129e2df2009-11-30 22:42:35 +00008204
8205 // Expand using declarations.
8206 if (isa<UsingDecl>(InstD)) {
8207 UsingDecl *UD = cast<UsingDecl>(InstD);
8208 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8209 E = UD->shadow_end(); I != E; ++I)
8210 R.addDecl(*I);
8211 continue;
8212 }
8213
8214 R.addDecl(InstD);
8215 }
8216
8217 R.resolveKind();
8218
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008219 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008220 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008221 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008222 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008223 Old->getMemberLoc(),
8224 Old->getNamingClass()));
8225 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008226 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008227
Douglas Gregor66c45152010-04-27 16:10:10 +00008228 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008229 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008230
John McCall129e2df2009-11-30 22:42:35 +00008231 TemplateArgumentListInfo TransArgs;
8232 if (Old->hasExplicitTemplateArgs()) {
8233 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8234 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008235 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8236 Old->getNumTemplateArgs(),
8237 TransArgs))
8238 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008239 }
John McCallc2233c52010-01-15 08:34:02 +00008240
8241 // FIXME: to do this check properly, we will need to preserve the
8242 // first-qualifier-in-scope here, just in case we had a dependent
8243 // base (and therefore couldn't do the check) and a
8244 // nested-name-qualifier (and therefore could do the lookup).
8245 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008246
John McCall9ae2f072010-08-23 23:25:46 +00008247 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008248 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008249 Old->getOperatorLoc(),
8250 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008251 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008252 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008253 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008254 R,
8255 (Old->hasExplicitTemplateArgs()
8256 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008257}
8258
8259template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008260ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008261TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008262 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008263 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8264 if (SubExpr.isInvalid())
8265 return ExprError();
8266
8267 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008268 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008269
8270 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8271}
8272
8273template<typename Derived>
8274ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008275TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008276 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8277 if (Pattern.isInvalid())
8278 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008279
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008280 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8281 return SemaRef.Owned(E);
8282
Douglas Gregor67fd1252011-01-14 21:20:45 +00008283 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8284 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008285}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008286
8287template<typename Derived>
8288ExprResult
8289TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8290 // If E is not value-dependent, then nothing will change when we transform it.
8291 // Note: This is an instantiation-centric view.
8292 if (!E->isValueDependent())
8293 return SemaRef.Owned(E);
8294
8295 // Note: None of the implementations of TryExpandParameterPacks can ever
8296 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008297 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008298 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8299 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008300 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008301 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008302 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008303 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008304 ShouldExpand, RetainExpansion,
8305 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008306 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008307
Douglas Gregor089e8932011-10-10 18:59:29 +00008308 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008309 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008310
Douglas Gregor089e8932011-10-10 18:59:29 +00008311 NamedDecl *Pack = E->getPack();
8312 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008313 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008314 Pack));
8315 if (!Pack)
8316 return ExprError();
8317 }
8318
Chad Rosier4a9d7952012-08-08 18:46:20 +00008319
Douglas Gregoree8aff02011-01-04 17:33:58 +00008320 // We now know the length of the parameter pack, so build a new expression
8321 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008322 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8323 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008324 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008325}
8326
Douglas Gregorbe230c32011-01-03 17:17:50 +00008327template<typename Derived>
8328ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008329TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8330 SubstNonTypeTemplateParmPackExpr *E) {
8331 // Default behavior is to do nothing with this transformation.
8332 return SemaRef.Owned(E);
8333}
8334
8335template<typename Derived>
8336ExprResult
John McCall91a57552011-07-15 05:09:51 +00008337TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8338 SubstNonTypeTemplateParmExpr *E) {
8339 // Default behavior is to do nothing with this transformation.
8340 return SemaRef.Owned(E);
8341}
8342
8343template<typename Derived>
8344ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008345TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8346 MaterializeTemporaryExpr *E) {
8347 return getDerived().TransformExpr(E->GetTemporaryExpr());
8348}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008349
Douglas Gregor03e80032011-06-21 17:03:29 +00008350template<typename Derived>
8351ExprResult
John McCall454feb92009-12-08 09:21:05 +00008352TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008353 return SemaRef.MaybeBindToTemporary(E);
8354}
8355
8356template<typename Derived>
8357ExprResult
8358TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008359 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008360}
8361
8362template<typename Derived>
8363ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008364TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8365 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8366 if (SubExpr.isInvalid())
8367 return ExprError();
8368
8369 if (!getDerived().AlwaysRebuild() &&
8370 SubExpr.get() == E->getSubExpr())
8371 return SemaRef.Owned(E);
8372
8373 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008374}
8375
8376template<typename Derived>
8377ExprResult
8378TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8379 // Transform each of the elements.
8380 llvm::SmallVector<Expr *, 8> Elements;
8381 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008382 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008383 /*IsCall=*/false, Elements, &ArgChanged))
8384 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008385
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008386 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8387 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008388
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008389 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8390 Elements.data(),
8391 Elements.size());
8392}
8393
8394template<typename Derived>
8395ExprResult
8396TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008397 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008398 // Transform each of the elements.
8399 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8400 bool ArgChanged = false;
8401 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8402 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008403
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008404 if (OrigElement.isPackExpansion()) {
8405 // This key/value element is a pack expansion.
8406 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8407 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8408 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8409 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8410
8411 // Determine whether the set of unexpanded parameter packs can
8412 // and should be expanded.
8413 bool Expand = true;
8414 bool RetainExpansion = false;
8415 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8416 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8417 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8418 OrigElement.Value->getLocEnd());
8419 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8420 PatternRange,
8421 Unexpanded,
8422 Expand, RetainExpansion,
8423 NumExpansions))
8424 return ExprError();
8425
8426 if (!Expand) {
8427 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008428 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008429 // expansion.
8430 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8431 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8432 if (Key.isInvalid())
8433 return ExprError();
8434
8435 if (Key.get() != OrigElement.Key)
8436 ArgChanged = true;
8437
8438 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8439 if (Value.isInvalid())
8440 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008441
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008442 if (Value.get() != OrigElement.Value)
8443 ArgChanged = true;
8444
Chad Rosier4a9d7952012-08-08 18:46:20 +00008445 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008446 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8447 };
8448 Elements.push_back(Expansion);
8449 continue;
8450 }
8451
8452 // Record right away that the argument was changed. This needs
8453 // to happen even if the array expands to nothing.
8454 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008455
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008456 // The transform has determined that we should perform an elementwise
8457 // expansion of the pattern. Do so.
8458 for (unsigned I = 0; I != *NumExpansions; ++I) {
8459 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8460 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8461 if (Key.isInvalid())
8462 return ExprError();
8463
8464 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8465 if (Value.isInvalid())
8466 return ExprError();
8467
Chad Rosier4a9d7952012-08-08 18:46:20 +00008468 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008469 Key.get(), Value.get(), SourceLocation(), NumExpansions
8470 };
8471
8472 // If any unexpanded parameter packs remain, we still have a
8473 // pack expansion.
8474 if (Key.get()->containsUnexpandedParameterPack() ||
8475 Value.get()->containsUnexpandedParameterPack())
8476 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008477
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008478 Elements.push_back(Element);
8479 }
8480
8481 // We've finished with this pack expansion.
8482 continue;
8483 }
8484
8485 // Transform and check key.
8486 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8487 if (Key.isInvalid())
8488 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008489
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008490 if (Key.get() != OrigElement.Key)
8491 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008492
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008493 // Transform and check value.
8494 ExprResult Value
8495 = getDerived().TransformExpr(OrigElement.Value);
8496 if (Value.isInvalid())
8497 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008498
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008499 if (Value.get() != OrigElement.Value)
8500 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008501
8502 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008503 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8504 };
8505 Elements.push_back(Element);
8506 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008507
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008508 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8509 return SemaRef.MaybeBindToTemporary(E);
8510
8511 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8512 Elements.data(),
8513 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008514}
8515
Mike Stump1eb44332009-09-09 15:08:12 +00008516template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008517ExprResult
John McCall454feb92009-12-08 09:21:05 +00008518TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008519 TypeSourceInfo *EncodedTypeInfo
8520 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8521 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008522 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008523
Douglas Gregorb98b1992009-08-11 05:31:07 +00008524 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008525 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008526 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008527
8528 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008529 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008530 E->getRParenLoc());
8531}
Mike Stump1eb44332009-09-09 15:08:12 +00008532
Douglas Gregorb98b1992009-08-11 05:31:07 +00008533template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008534ExprResult TreeTransform<Derived>::
8535TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8536 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8537 if (result.isInvalid()) return ExprError();
8538 Expr *subExpr = result.take();
8539
8540 if (!getDerived().AlwaysRebuild() &&
8541 subExpr == E->getSubExpr())
8542 return SemaRef.Owned(E);
8543
8544 return SemaRef.Owned(new(SemaRef.Context)
8545 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8546}
8547
8548template<typename Derived>
8549ExprResult TreeTransform<Derived>::
8550TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008551 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008552 = getDerived().TransformType(E->getTypeInfoAsWritten());
8553 if (!TSInfo)
8554 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008555
John McCallf85e1932011-06-15 23:02:42 +00008556 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008557 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008558 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008559
John McCallf85e1932011-06-15 23:02:42 +00008560 if (!getDerived().AlwaysRebuild() &&
8561 TSInfo == E->getTypeInfoAsWritten() &&
8562 Result.get() == E->getSubExpr())
8563 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008564
John McCallf85e1932011-06-15 23:02:42 +00008565 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008566 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008567 Result.get());
8568}
8569
8570template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008571ExprResult
John McCall454feb92009-12-08 09:21:05 +00008572TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008573 // Transform arguments.
8574 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008575 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008576 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008577 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008578 &ArgChanged))
8579 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008580
Douglas Gregor92e986e2010-04-22 16:44:27 +00008581 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8582 // Class message: transform the receiver type.
8583 TypeSourceInfo *ReceiverTypeInfo
8584 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8585 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008586 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008587
Douglas Gregor92e986e2010-04-22 16:44:27 +00008588 // If nothing changed, just retain the existing message send.
8589 if (!getDerived().AlwaysRebuild() &&
8590 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008591 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008592
8593 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008594 SmallVector<SourceLocation, 16> SelLocs;
8595 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008596 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8597 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008598 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008599 E->getMethodDecl(),
8600 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008601 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008602 E->getRightLoc());
8603 }
8604
8605 // Instance message: transform the receiver
8606 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8607 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008608 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008609 = getDerived().TransformExpr(E->getInstanceReceiver());
8610 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008611 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008612
8613 // If nothing changed, just retain the existing message send.
8614 if (!getDerived().AlwaysRebuild() &&
8615 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008616 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008617
Douglas Gregor92e986e2010-04-22 16:44:27 +00008618 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008619 SmallVector<SourceLocation, 16> SelLocs;
8620 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008621 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008622 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008623 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008624 E->getMethodDecl(),
8625 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008626 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008627 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008628}
8629
Mike Stump1eb44332009-09-09 15:08:12 +00008630template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008631ExprResult
John McCall454feb92009-12-08 09:21:05 +00008632TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008633 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008634}
8635
Mike Stump1eb44332009-09-09 15:08:12 +00008636template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008637ExprResult
John McCall454feb92009-12-08 09:21:05 +00008638TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008639 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008640}
8641
Mike Stump1eb44332009-09-09 15:08:12 +00008642template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008643ExprResult
John McCall454feb92009-12-08 09:21:05 +00008644TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008645 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008646 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008647 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008648 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008649
8650 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008651
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008652 // If nothing changed, just retain the existing expression.
8653 if (!getDerived().AlwaysRebuild() &&
8654 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008655 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008656
John McCall9ae2f072010-08-23 23:25:46 +00008657 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008658 E->getLocation(),
8659 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008660}
8661
Mike Stump1eb44332009-09-09 15:08:12 +00008662template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008663ExprResult
John McCall454feb92009-12-08 09:21:05 +00008664TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008665 // 'super' and types never change. Property never changes. Just
8666 // retain the existing expression.
8667 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008668 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008669
Douglas Gregore3303542010-04-26 20:47:02 +00008670 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008671 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008672 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008673 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008674
Douglas Gregore3303542010-04-26 20:47:02 +00008675 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008676
Douglas Gregore3303542010-04-26 20:47:02 +00008677 // If nothing changed, just retain the existing expression.
8678 if (!getDerived().AlwaysRebuild() &&
8679 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008680 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008681
John McCall12f78a62010-12-02 01:19:52 +00008682 if (E->isExplicitProperty())
8683 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8684 E->getExplicitProperty(),
8685 E->getLocation());
8686
8687 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008688 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008689 E->getImplicitPropertyGetter(),
8690 E->getImplicitPropertySetter(),
8691 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008692}
8693
Mike Stump1eb44332009-09-09 15:08:12 +00008694template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008695ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008696TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8697 // Transform the base expression.
8698 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8699 if (Base.isInvalid())
8700 return ExprError();
8701
8702 // Transform the key expression.
8703 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8704 if (Key.isInvalid())
8705 return ExprError();
8706
8707 // If nothing changed, just retain the existing expression.
8708 if (!getDerived().AlwaysRebuild() &&
8709 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8710 return SemaRef.Owned(E);
8711
Chad Rosier4a9d7952012-08-08 18:46:20 +00008712 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008713 Base.get(), Key.get(),
8714 E->getAtIndexMethodDecl(),
8715 E->setAtIndexMethodDecl());
8716}
8717
8718template<typename Derived>
8719ExprResult
John McCall454feb92009-12-08 09:21:05 +00008720TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008721 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008722 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008723 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008724 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008725
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008726 // If nothing changed, just retain the existing expression.
8727 if (!getDerived().AlwaysRebuild() &&
8728 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008729 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008730
John McCall9ae2f072010-08-23 23:25:46 +00008731 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008732 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008733}
8734
Mike Stump1eb44332009-09-09 15:08:12 +00008735template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008736ExprResult
John McCall454feb92009-12-08 09:21:05 +00008737TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008738 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008739 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008740 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008741 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008742 SubExprs, &ArgumentChanged))
8743 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008744
Douglas Gregorb98b1992009-08-11 05:31:07 +00008745 if (!getDerived().AlwaysRebuild() &&
8746 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008747 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008748
Douglas Gregorb98b1992009-08-11 05:31:07 +00008749 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008750 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008751 E->getRParenLoc());
8752}
8753
Mike Stump1eb44332009-09-09 15:08:12 +00008754template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008755ExprResult
John McCall454feb92009-12-08 09:21:05 +00008756TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008757 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008758
John McCallc6ac9c32011-02-04 18:33:18 +00008759 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8760 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8761
8762 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008763 blockScope->TheDecl->setBlockMissingReturnType(
8764 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008765
Chris Lattner686775d2011-07-20 06:58:45 +00008766 SmallVector<ParmVarDecl*, 4> params;
8767 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008768
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008769 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008770 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8771 oldBlock->param_begin(),
8772 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008773 0, paramTypes, &params)) {
8774 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008775 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008776 }
John McCallc6ac9c32011-02-04 18:33:18 +00008777
8778 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008779 QualType exprResultType =
8780 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008781
8782 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008783 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008784 getSema().Diag(E->getCaretLocation(),
8785 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008786 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008787 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008788 return ExprError();
8789 }
John McCall711c52b2011-01-05 12:14:39 +00008790
John McCallc6ac9c32011-02-04 18:33:18 +00008791 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008792 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008793 paramTypes.data(),
8794 paramTypes.size(),
8795 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008796 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008797 exprFunctionType->getExtInfo());
8798 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008799
8800 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008801 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008802 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008803
8804 if (!oldBlock->blockMissingReturnType()) {
8805 blockScope->HasImplicitReturnType = false;
8806 blockScope->ReturnType = exprResultType;
8807 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008808
John McCall711c52b2011-01-05 12:14:39 +00008809 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008810 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008811 if (body.isInvalid()) {
8812 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008813 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008814 }
John McCall711c52b2011-01-05 12:14:39 +00008815
John McCallc6ac9c32011-02-04 18:33:18 +00008816#ifndef NDEBUG
8817 // In builds with assertions, make sure that we captured everything we
8818 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008819 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8820 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8821 e = oldBlock->capture_end(); i != e; ++i) {
8822 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008823
Douglas Gregorfc921372011-05-20 15:32:55 +00008824 // Ignore parameter packs.
8825 if (isa<ParmVarDecl>(oldCapture) &&
8826 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8827 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008828
Douglas Gregorfc921372011-05-20 15:32:55 +00008829 VarDecl *newCapture =
8830 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8831 oldCapture));
8832 assert(blockScope->CaptureMap.count(newCapture));
8833 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008834 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008835 }
8836#endif
8837
8838 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8839 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008840}
8841
Mike Stump1eb44332009-09-09 15:08:12 +00008842template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008843ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008844TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008845 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008846}
Eli Friedman276b0612011-10-11 02:20:01 +00008847
8848template<typename Derived>
8849ExprResult
8850TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008851 QualType RetTy = getDerived().TransformType(E->getType());
8852 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008853 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008854 SubExprs.reserve(E->getNumSubExprs());
8855 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8856 SubExprs, &ArgumentChanged))
8857 return ExprError();
8858
8859 if (!getDerived().AlwaysRebuild() &&
8860 !ArgumentChanged)
8861 return SemaRef.Owned(E);
8862
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008863 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008864 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008865}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008866
Douglas Gregorb98b1992009-08-11 05:31:07 +00008867//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008868// Type reconstruction
8869//===----------------------------------------------------------------------===//
8870
Mike Stump1eb44332009-09-09 15:08:12 +00008871template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008872QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8873 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008874 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008875 getDerived().getBaseEntity());
8876}
8877
Mike Stump1eb44332009-09-09 15:08:12 +00008878template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008879QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8880 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008881 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008882 getDerived().getBaseEntity());
8883}
8884
Mike Stump1eb44332009-09-09 15:08:12 +00008885template<typename Derived>
8886QualType
John McCall85737a72009-10-30 00:06:24 +00008887TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8888 bool WrittenAsLValue,
8889 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008890 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008891 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008892}
8893
8894template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008895QualType
John McCall85737a72009-10-30 00:06:24 +00008896TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8897 QualType ClassType,
8898 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008899 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008900 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008901}
8902
8903template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008904QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008905TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8906 ArrayType::ArraySizeModifier SizeMod,
8907 const llvm::APInt *Size,
8908 Expr *SizeExpr,
8909 unsigned IndexTypeQuals,
8910 SourceRange BracketsRange) {
8911 if (SizeExpr || !Size)
8912 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8913 IndexTypeQuals, BracketsRange,
8914 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008915
8916 QualType Types[] = {
8917 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8918 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8919 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008920 };
8921 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8922 QualType SizeType;
8923 for (unsigned I = 0; I != NumTypes; ++I)
8924 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8925 SizeType = Types[I];
8926 break;
8927 }
Mike Stump1eb44332009-09-09 15:08:12 +00008928
Eli Friedman01f276d2012-01-25 23:20:27 +00008929 // Note that we can return a VariableArrayType here in the case where
8930 // the element type was a dependent VariableArrayType.
8931 IntegerLiteral *ArraySize
8932 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8933 /*FIXME*/BracketsRange.getBegin());
8934 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008935 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008936 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008937}
Mike Stump1eb44332009-09-09 15:08:12 +00008938
Douglas Gregor577f75a2009-08-04 16:50:30 +00008939template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008940QualType
8941TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008942 ArrayType::ArraySizeModifier SizeMod,
8943 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008944 unsigned IndexTypeQuals,
8945 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008946 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008947 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008948}
8949
8950template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008951QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008952TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008953 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008954 unsigned IndexTypeQuals,
8955 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008956 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008957 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008958}
Mike Stump1eb44332009-09-09 15:08:12 +00008959
Douglas Gregor577f75a2009-08-04 16:50:30 +00008960template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008961QualType
8962TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008963 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008964 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008965 unsigned IndexTypeQuals,
8966 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008967 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008968 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008969 IndexTypeQuals, BracketsRange);
8970}
8971
8972template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008973QualType
8974TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008975 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008976 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008977 unsigned IndexTypeQuals,
8978 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008979 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008980 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008981 IndexTypeQuals, BracketsRange);
8982}
8983
8984template<typename Derived>
8985QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008986 unsigned NumElements,
8987 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008988 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008989 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008990}
Mike Stump1eb44332009-09-09 15:08:12 +00008991
Douglas Gregor577f75a2009-08-04 16:50:30 +00008992template<typename Derived>
8993QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8994 unsigned NumElements,
8995 SourceLocation AttributeLoc) {
8996 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8997 NumElements, true);
8998 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008999 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9000 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009001 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009002}
Mike Stump1eb44332009-09-09 15:08:12 +00009003
Douglas Gregor577f75a2009-08-04 16:50:30 +00009004template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009005QualType
9006TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009007 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009008 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009009 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009010}
Mike Stump1eb44332009-09-09 15:08:12 +00009011
Douglas Gregor577f75a2009-08-04 16:50:30 +00009012template<typename Derived>
9013QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00009014 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009015 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00009016 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009017 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00009018 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00009019 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00009020 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00009021 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009022 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009023 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009024 getDerived().getBaseEntity(),
9025 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009026}
Mike Stump1eb44332009-09-09 15:08:12 +00009027
Douglas Gregor577f75a2009-08-04 16:50:30 +00009028template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009029QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9030 return SemaRef.Context.getFunctionNoProtoType(T);
9031}
9032
9033template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009034QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9035 assert(D && "no decl found");
9036 if (D->isInvalidDecl()) return QualType();
9037
Douglas Gregor92e986e2010-04-22 16:44:27 +00009038 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009039 TypeDecl *Ty;
9040 if (isa<UsingDecl>(D)) {
9041 UsingDecl *Using = cast<UsingDecl>(D);
9042 assert(Using->isTypeName() &&
9043 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9044
9045 // A valid resolved using typename decl points to exactly one type decl.
9046 assert(++Using->shadow_begin() == Using->shadow_end());
9047 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009048
John McCalled976492009-12-04 22:46:56 +00009049 } else {
9050 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9051 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9052 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9053 }
9054
9055 return SemaRef.Context.getTypeDeclType(Ty);
9056}
9057
9058template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009059QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9060 SourceLocation Loc) {
9061 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009062}
9063
9064template<typename Derived>
9065QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9066 return SemaRef.Context.getTypeOfType(Underlying);
9067}
9068
9069template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009070QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9071 SourceLocation Loc) {
9072 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009073}
9074
9075template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009076QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9077 UnaryTransformType::UTTKind UKind,
9078 SourceLocation Loc) {
9079 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9080}
9081
9082template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009083QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009084 TemplateName Template,
9085 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009086 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009087 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009088}
Mike Stump1eb44332009-09-09 15:08:12 +00009089
Douglas Gregordcee1a12009-08-06 05:28:30 +00009090template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009091QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9092 SourceLocation KWLoc) {
9093 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9094}
9095
9096template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009097TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009098TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009099 bool TemplateKW,
9100 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009101 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009102 Template);
9103}
9104
9105template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009106TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009107TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9108 const IdentifierInfo &Name,
9109 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009110 QualType ObjectType,
9111 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009112 UnqualifiedId TemplateName;
9113 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009114 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009115 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009116 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009117 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009118 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009119 /*EnteringContext=*/false,
9120 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009121 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009122}
Mike Stump1eb44332009-09-09 15:08:12 +00009123
Douglas Gregorb98b1992009-08-11 05:31:07 +00009124template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009125TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009126TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009127 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009128 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009129 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009130 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009131 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009132 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009133 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009134 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009135 Sema::TemplateTy Template;
9136 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009137 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009138 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009139 /*EnteringContext=*/false,
9140 Template);
9141 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009142}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009143
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009144template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009145ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009146TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9147 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009148 Expr *OrigCallee,
9149 Expr *First,
9150 Expr *Second) {
9151 Expr *Callee = OrigCallee->IgnoreParenCasts();
9152 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009153
Douglas Gregorb98b1992009-08-11 05:31:07 +00009154 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009155 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009156 if (!First->getType()->isOverloadableType() &&
9157 !Second->getType()->isOverloadableType())
9158 return getSema().CreateBuiltinArraySubscriptExpr(First,
9159 Callee->getLocStart(),
9160 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009161 } else if (Op == OO_Arrow) {
9162 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009163 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9164 } else if (Second == 0 || isPostIncDec) {
9165 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009166 // The argument is not of overloadable type, so try to create a
9167 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009168 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009169 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009170
John McCall9ae2f072010-08-23 23:25:46 +00009171 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009172 }
9173 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009174 if (!First->getType()->isOverloadableType() &&
9175 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009176 // Neither of the arguments is an overloadable type, so try to
9177 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009178 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009179 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009180 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009181 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009182 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009183
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009184 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009185 }
9186 }
Mike Stump1eb44332009-09-09 15:08:12 +00009187
9188 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009189 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009190 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009191
John McCall9ae2f072010-08-23 23:25:46 +00009192 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009193 assert(ULE->requiresADL());
9194
9195 // FIXME: Do we have to check
9196 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009197 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009198 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009199 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00009200 }
Mike Stump1eb44332009-09-09 15:08:12 +00009201
Douglas Gregorb98b1992009-08-11 05:31:07 +00009202 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009203 Expr *Args[2] = { First, Second };
9204 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009205
Douglas Gregorb98b1992009-08-11 05:31:07 +00009206 // Create the overloaded operator invocation for unary operators.
9207 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009208 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009209 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009210 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009211 }
Mike Stump1eb44332009-09-09 15:08:12 +00009212
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009213 if (Op == OO_Subscript) {
9214 SourceLocation LBrace;
9215 SourceLocation RBrace;
9216
9217 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9218 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9219 LBrace = SourceLocation::getFromRawEncoding(
9220 NameLoc.CXXOperatorName.BeginOpNameLoc);
9221 RBrace = SourceLocation::getFromRawEncoding(
9222 NameLoc.CXXOperatorName.EndOpNameLoc);
9223 } else {
9224 LBrace = Callee->getLocStart();
9225 RBrace = OpLoc;
9226 }
9227
9228 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9229 First, Second);
9230 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009231
Douglas Gregorb98b1992009-08-11 05:31:07 +00009232 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009233 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009234 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009235 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9236 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009237 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009238
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009239 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009240}
Mike Stump1eb44332009-09-09 15:08:12 +00009241
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009242template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009243ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009244TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009245 SourceLocation OperatorLoc,
9246 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009247 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009248 TypeSourceInfo *ScopeType,
9249 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009250 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009251 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009252 QualType BaseType = Base->getType();
9253 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009254 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009255 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009256 !BaseType->getAs<PointerType>()->getPointeeType()
9257 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009258 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009259 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009260 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009261 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009262 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009263 /*FIXME?*/true);
9264 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009265
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009266 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009267 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9268 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9269 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9270 NameInfo.setNamedTypeInfo(DestroyedType);
9271
Richard Smith6314db92012-05-15 06:15:11 +00009272 // The scope type is now known to be a valid nested name specifier
9273 // component. Tack it on to the end of the nested name specifier.
9274 if (ScopeType)
9275 SS.Extend(SemaRef.Context, SourceLocation(),
9276 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009277
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009278 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009279 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009280 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009281 SS, TemplateKWLoc,
9282 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009283 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009284 /*TemplateArgs*/ 0);
9285}
9286
Douglas Gregor577f75a2009-08-04 16:50:30 +00009287} // end namespace clang
9288
9289#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H